-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftwareUpdateApp.cpp
More file actions
93 lines (74 loc) · 2.3 KB
/
SoftwareUpdateApp.cpp
File metadata and controls
93 lines (74 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "SoftwareUpdateApp.h"
#include <wx/cmdline.h>
#include <wx/stdpaths.h>
#include "UpdateChecker.h"
wxIMPLEMENT_APP(SoftwareUpdateApp);
SoftwareUpdateApp::SoftwareUpdateApp():
m_launchMode(LaunchStandalone)
{
}
SoftwareUpdateApp::~SoftwareUpdateApp()
{
}
bool SoftwareUpdateApp::OnInit()
{
SetAppDisplayName(_("Software Update"));
SetAppName("SoftwareUpdate");
SetVendorName("ACE");
if (!wxApp::OnInit())
return false;
return true;
}
int SoftwareUpdateApp::OnRun()
{
int result = 0;
UpdateChecker checker;
if (m_launchMode == LaunchUpdate)
{
checker.CheckForUpdate(); // workaround for wxWidgets thread issue on Win32
checker.SetUpdateInfoFileName(m_updateFileName);
checker.ApplyUpdate();
result = wxApp::OnRun();
} else {
bool updateAvailable = false;
if (m_launchMode == LaunchStandalone || checker.IsCheckRequired())
updateAvailable = checker.CheckForUpdate();
if (updateAvailable && checker.ConfirmUpdate())
{
// Relaunch new process in update mode
wxExecute(wxString::Format(wxT("\"%s\" --update=\"%s\""), wxStandardPaths::Get().GetExecutablePath(), checker.GetUpdateInfoFileName()));
// Return errorlevel 1
result = 1;
}
if (m_launchMode == LaunchStandalone && !updateAvailable)
wxMessageBox(wxString::Format(_("No update available.\n\nThe latest version of %s is installed."), checker.GetSoftwareTitle()),
_("Information"), wxICON_INFORMATION | wxOK);
}
return result;
}
void SoftwareUpdateApp::OnInitCmdLine(wxCmdLineParser &parser)
{
wxApp::OnInitCmdLine(parser);
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_SWITCH, "c", "check", _("returns errorlevel 1 if update is available")},
{ wxCMD_LINE_OPTION, "u", "update", _("start update from info file") },
{ wxCMD_LINE_NONE }
};
parser.SetDesc(cmdLineDesc);
}
bool SoftwareUpdateApp::OnCmdLineParsed(wxCmdLineParser &parser)
{
if (parser.Found(wxT("check")))
m_launchMode = LaunchCheck;
else if (parser.Found(wxT("update"), &m_updateFileName))
{
if (!wxFileExists(m_updateFileName))
{
wxLogError(wxT("Update file \"%s\" not found."), m_updateFileName);
return false;
}
m_launchMode = LaunchUpdate;
}
return wxApp::OnCmdLineParsed(parser);
}