-
Notifications
You must be signed in to change notification settings - Fork 2
/
StackBuilder.cpp
197 lines (166 loc) · 7.13 KB
/
StackBuilder.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/////////////////////////////////////////////////////////////////////////////
// Name: StackBuilder.cpp
// Purpose: PostgreSQL/EnterpriseDB Application Stack Builder
// Author: Dave Page
// Created: 2007-02-13
// RCS-ID: $Id: StackBuilder.cpp,v 1.18 2011/11/28 19:09:57 dpage Exp $
// Copyright: (c) EnterpriseDB
// Licence: BSD Licence
/////////////////////////////////////////////////////////////////////////////
#include "StackBuilder.h"
// wxWindows headers
#include <wx/wx.h>
#include <wx/app.h>
#include <wx/cmdline.h>
#include <wx/dir.h>
// Application headers
#include "Wizard.h"
#include "images/background.xpm"
IMPLEMENT_APP(StackBuilder)
BEGIN_EVENT_TABLE(StackBuilder, wxApp)
EVT_WIZARD_CANCEL(wxID_ANY, StackBuilder::OnWizardCancelled)
EVT_WIZARD_FINISHED(wxID_ANY, StackBuilder::OnWizardFinished)
END_EVENT_TABLE()
// This is declared an extern in StackBuilder.h
wxString downloadCounterUrl;
wxString g_certificateBundle;
// The Application!
bool StackBuilder::OnInit()
{
wxString mirrorListUrl;
wxString applicationListUrl;
wxString language;
SetAppName(_("Stack Builder"));
// Command line options
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
#if wxCHECK_VERSION(3, 0, 0)
{wxCMD_LINE_SWITCH, "h", "help", _("show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{wxCMD_LINE_OPTION, "m", "mirror-list", _("download the mirror list from the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, "a", "application-list", _("download the application list from the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, "d", "download-counter", _("use the download counter at the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, "l", "language", _("use the specified language in the UI"), wxCMD_LINE_VAL_STRING},
#else
{wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), _("show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{wxCMD_LINE_OPTION, wxT("m"), wxT("mirror-list"), _("download the mirror list from the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, wxT("a"), wxT("application-list"), _("download the application list from the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, wxT("d"), wxT("download-counter"), _("use the download counter at the specified URL"), wxCMD_LINE_VAL_STRING},
{wxCMD_LINE_OPTION, wxT("l"), wxT("language"), _("use the specified language in the UI"), wxCMD_LINE_VAL_STRING},
#endif
#ifndef __WIN32__
#if wxCHECK_VERSION(3, 0, 0)
{wxCMD_LINE_OPTION, "c", "ca-bundle", _("user certificate for https support from the specified URL"), wxCMD_LINE_VAL_STRING},
#else
{wxCMD_LINE_OPTION, wxT("c"), wxT("ca-bundle"), _("user certificate for https support from the specified URL"), wxCMD_LINE_VAL_STRING},
#endif
#endif
{wxCMD_LINE_NONE}
};
wxCmdLineParser cmdParser(cmdLineDesc, argc, argv);
if (cmdParser.Parse() != 0)
return false;
if (!cmdParser.Found(wxT("m"), &mirrorListUrl))
mirrorListUrl = DEFAULT_MIRROR_LIST_URL;
if (!cmdParser.Found(wxT("a"), &applicationListUrl))
applicationListUrl = DEFAULT_APPLICATION_LIST_URL;
// postgresql.org no longer uses the counter, so we default to not trying
// to use any, unless the user overrides on the command line.
if (!cmdParser.Found(wxT("d"), &downloadCounterUrl))
downloadCounterUrl = wxEmptyString;
if (!cmdParser.Found(wxT("l"), &language))
language = wxEmptyString;
#ifndef __WIN32__
if (!cmdParser.Found(wxT("c"), &g_certificateBundle))
g_certificateBundle = wxEmptyString;
#endif
// Hack for the PostgreSQL installer - it might ask for the default language
if (language == wxT("DEFAULT"))
language = wxEmptyString;
// Initialize our locale and load the language catalog...
wxString executablePath = wxPathOnly(wxStandardPaths::Get().GetExecutablePath());
initializeLocale(executablePath, language);
// We need to run as root on Unix in order to ensure that
// the instalers will run with appropriate privileges. On
// Mac and Windows, installers can elevate themselves.
#ifdef __WXGTK__
if(geteuid() != 0)
{
wxLogError(_("Stack Builder requires superuser privileges. Please execute Stack Builder using sudo, or from the root user account."));
return false;
}
#endif
#ifdef __WXMSW__
BOOL isAdmin;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
isAdmin = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(isAdmin)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &isAdmin))
{
isAdmin = FALSE;
}
FreeSid(AdministratorsGroup);
}
if(!isAdmin)
{
wxLogError(_("Stack Builder requires administrator privileges. Please execute Stack Builder by right-clicking the shortcut and using the 'Run as Administrator' option, or from an Administrator account on Windows XP or 2003."));
return false;
}
#endif
// Create and run the wizard
wxBitmap bitmap = wxBitmap(background_xpm);
wxString title = wxString::Format(wxT("%s %s"), _("Stack Builder"), STACKBUILDER_VERSION);
wizard = new Wizard(NULL, bitmap, applicationListUrl, mirrorListUrl, title);
bool retval = wizard->RunWizard(wizard->GetFirstPage());
return retval;
}
void StackBuilder::OnWizardCancelled(wxWizardEvent &evt)
{
if (wxMessageBox(_("Are you sure you want to close the Stack Builder wizard?"), _("Exit wizard?"), wxICON_QUESTION | wxYES_NO) == wxNO)
{
evt.Veto();
return;
}
wizard->Destroy();
this->Exit();
}
void StackBuilder::OnWizardFinished(wxWizardEvent &evt)
{
wizard->SetReturnCode(0);
wizard->Destroy();
this->Exit();
}
void StackBuilder::initializeLocale(const wxString &appPath, const wxString &lang)
{
wxString i18nPath;
if(wxDir::Exists(appPath + wxT("/i18n")))
i18nPath = appPath + wxT("/i18n");
else if(wxDir::Exists(appPath + wxT("/../StackBuilder/i18n")))
i18nPath = appPath + wxT("/../StackBuilder/i18n");
else if(wxDir::Exists(appPath + wxT("/../StackBuilder/share/i18n")))
i18nPath = appPath + wxT("/../StackBuilder/share/i18n");
else if(wxDir::Exists(appPath + wxT("/../i18n")))
i18nPath = appPath + wxT("/../i18n");
else if(wxDir::Exists(appPath + wxT("/../share/i18n")))
i18nPath = appPath + wxT("/../share/i18n");
else if(wxDir::Exists(appPath + wxT("/../Resources/i18n")))
i18nPath = appPath + wxT("/../Resources/i18n");
wxLocale *locale = new wxLocale();
locale->AddCatalogLookupPathPrefix(i18nPath);
const wxLanguageInfo *langInfo;
if (!lang.IsEmpty())
langInfo = wxLocale::FindLanguageInfo(lang);
else
langInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT);
if (!langInfo)
return;
if(locale->Init(langInfo->Language), wxLOCALE_LOAD_DEFAULT)
locale->AddCatalog(wxT("StackBuilder"));
}