-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller.iss
290 lines (257 loc) · 13.3 KB
/
installer.iss
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
; (c) 2019 - Aris Ripandi
#define BasePath ""
#define AppName "Varlet"
#define AppSlug "varlet"
#define AppWebsite "varlet.dev"
#define AppPublisher "Aris Ripandi"
#define GetAppVersion GetFileVersion('_dst64\VarletUi.exe')
[Setup]
AppName = {#AppName}
AppVersion = {#GetAppVersion}
AppPublisher = {#AppPublisher}
AppPublisherURL = {#AppWebsite}
AppSupportURL = {#AppWebsite}
AppUpdatesURL = {#AppWebsite}
DefaultGroupName = {#AppName}
AppCopyright = Copyright (c) {#AppPublisher}
Compression = lzma2/ultra
SolidCompression = yes
DisableStartupPrompt = yes
DisableWelcomePage = no
DisableDirPage = no
DisableProgramGroupPage = yes
DisableReadyPage = no
DisableFinishedPage = no
AppendDefaultDirName = yes
AlwaysShowComponentsList = no
FlatComponentsList = yes
OutputDir = {#BasePath}_output
OutputBaseFilename = {#AppSlug}-{#GetAppVersion}-x64
SetupIconFile = "{#BasePath}include\setup-icon.ico"
LicenseFile = "{#BasePath}include\varlet-license.txt"
WizardImageFile = "{#BasePath}include\setup-img-side.bmp"
WizardSmallImageFile = "{#BasePath}include\setup-img-top.bmp"
DefaultDirName = {code:GetDefaultDir}
UninstallFilesDir = {app}\pkg
Uninstallable = yes
CreateUninstallRegKey = yes
DirExistsWarning = yes
AlwaysRestart = no
ArchitecturesAllowed = x64
[Registry]
Root: HKLM; Subkey: "Software\{#AppPublisher}"; Flags: uninsdeletekeyifempty;
Root: HKLM; Subkey: "Software\{#AppPublisher}\{#AppName}"; Flags: uninsdeletekey;
Root: HKLM; Subkey: "Software\{#AppPublisher}\{#AppName}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}";
Root: HKLM; Subkey: "Software\{#AppPublisher}\{#AppName}"; ValueType: string; ValueName: "AppVersion"; ValueData: "{#GetAppVersion}";
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "{#AppName}"; ValueData: "{app}\VarletUi.exe /minimized"
[Tasks]
Name: task_add_path_envars; Description: "Add PATH environment variables";
Name: task_autorun_service; Description: "Run services when Windows starts"; Flags: unchecked
Name: task_install_mailhog; Description: "Install Mailhog SMTP Testing"; Flags: unchecked
;Name: task_notepad_context; Description: "Add Open With Notepad Context Menu"; Flags: unchecked
[Files]
Source: "{#BasePath}_tmpdir\vcredis\*"; DestDir: {tmp}; Flags: ignoreversion deleteafterinstall
Source: "{#BasePath}_dst64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
Source: "{#BasePath}_dst64\pkg\httpd\conf\ports.conf"; DestDir: "{app}\pkg\httpd\conf"; Flags: onlyifdoesntexist
Source: "{#BasePath}stubs\config\NotepadContext.inf"; DestDir: {tmp}; Flags: ignoreversion deleteafterinstall
[Icons]
Name: "{group}\VarletUi"; Filename: "{app}\VarletUi.exe"
Name: "{commondesktop}\VarletUi"; Filename: "{app}\VarletUi.exe"
Name: "{group}\Uninstall {#AppName}"; Filename: "{uninstallexe}"
[Run]
Filename: "{tmp}\vcredis2012x64.exe"; Parameters: "/install /quiet /norestart"; Description: "Installing VCRedist 2012"; Flags: waituntilterminated; Check: VCRedist2012NotInstalled
Filename: "{tmp}\vcredis1519x64.exe"; Parameters: "/install /quiet /norestart"; Description: "Installing VCRedist 2015"; Flags: waituntilterminated; Check: VCRedist2015NotInstalled
Filename: "http://localhost/phpinfo"; Description: "Display PHP info page"; Flags: postinstall shellexec runasoriginaluser; Check: IsHttpServicesRunning
Filename: "{sys}\rundll32.exe"; Parameters: "setupapi,InstallHinfSection DefaultInstall 128 {tmp}\NotepadContext.inf"; Flags: 32bit
; Filename: "{app}\VarletUi.exe"; Description: "Run Varlet Controller"; Flags: postinstall skipifsilent; BeforeInstall: StartAppServices
[Dirs]
Name: {app}\tmp; Flags: uninsalwaysuninstall
Name: {app}\pkg\httpd\conf\certs; Flags: uninsalwaysuninstall
[UninstallDelete]
Type: filesandordirs; Name: "{app}\opt"
Type: filesandordirs; Name: "{app}\pkg"
Type: filesandordirs; Name: "{app}\tmp"
Type: filesandordirs; Name: "{app}\utils"
Type: filesandordirs; Name: "{app}\varlet.ini"
; ----------------------------------------------------------------------------------------------------
; Programmatic section -------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------------------------
#include 'include\setup-helpers.iss'
[Code]
const AppFolder = 'Varlet';
const AppRegKey = 'Software\{#AppPublisher}\{#AppName}';
function GetDefaultDir(Param: string): string;
begin
Result := GetAppRegistry('InstallPath');
if not RegKeyExists(HKLM, AppRegKey) then
Result := ExpandConstant('{sd}\') + AppFolder;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := (PageID = wpSelectDir) and DirExists(GetAppRegistry('InstallPath'));
if not RegKeyExists(HKLM, AppRegKey) then
Result := (PageID = wpSelectDir) and DirExists(ExpandConstant('{sd}\') + AppFolder);
end;
function InitializeSetup: Boolean;
begin
Result := True;
if RegKeyExists(HKLM, AppRegKey) then begin
InstallPath := GetAppRegistry('InstallPath');
Str := 'Previous installation detected at: '+InstallPath+''#13#13'This process will update current installation.'#13'Do you want to start the process?';
Result := MsgBox(Str, mbConfirmation, MB_YESNO) = idYes;
if Result = False then begin
MsgBox('Installation cancelled!', mbInformation, MB_OK);
Abort;
end else begin
if IsAppRunning('VarletUi.exe') then TaskKillByPid('VarletUi.exe');
if IsAppRunning('varlet.exe') then TaskKillByPid('varlet.exe');
if IsServiceRunning('VarletHttpd') then KillService('VarletHttpd');
if IsServiceRunning('AcrylicDNSProxySvc') then KillService('AcrylicDNSProxySvc');
if IsServiceRunning('VarletMailhog') then KillService('VarletMailhog');
end;
end;
end;
procedure InitializeWizard;
begin
CustomLicensePage;
// CreateFooterText(#169 + ' 2019 - {#AppPublisher}');
CreateFooterText('{#AppWebsite}');
end;
function IsHttpServicesRunning: Boolean;
begin
Result := IsServiceRunning('VarletHttpd');
end;
procedure ConfigureApplication;
var CertDir : String;
begin
BaseDir := ExpandConstant('{app}');
CertDir := BaseDir + '\pkg\httpd\conf\certs';
// create ssl cert for localhost
Str := '-key-file ' + CertDir + '\localhost.key -cert-file ' + CertDir + '\localhost.pem localhost';
Exec(BaseDir + '\utils\mkcert.exe', Str, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Exec(BaseDir + '\utils\mkcert.exe', '-install', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
// PHP 7.2
FileReplaceString(BaseDir + '\pkg\php\php-7.2-ts\php.ini', '<<INSTALL_DIR>>', PathWithSlashes(ExpandConstant('{app}')));
FileReplaceString(BaseDir + '\pkg\php\php-7.2-ts\php.ini', '<<PHP_BASEDIR>>', PathWithSlashes(BaseDir + '\pkg\php\php-7.2-ts'));
// PHP 7.3
FileReplaceString(BaseDir + '\pkg\php\php-7.3-ts\php.ini', '<<INSTALL_DIR>>', PathWithSlashes(ExpandConstant('{app}')));
FileReplaceString(BaseDir + '\pkg\php\php-7.3-ts\php.ini', '<<PHP_BASEDIR>>', PathWithSlashes(BaseDir + '\pkg\php\php-7.3-ts'));
// PHP 7.4
FileReplaceString(BaseDir + '\pkg\php\php-7.4-ts\php.ini', '<<INSTALL_DIR>>', PathWithSlashes(ExpandConstant('{app}')));
FileReplaceString(BaseDir + '\pkg\php\php-7.4-ts\php.ini', '<<PHP_BASEDIR>>', PathWithSlashes(BaseDir + '\pkg\php\php-7.4-ts'));
// Create composer.bat
Str := '@echo off' + #13#10#13#10 + '"'+BaseDir+'\pkg\php\php-7.4-ts\php.exe" "'+ExpandConstant('{app}\utils\composer.phar')+'" %*';
SaveStringToFile(BaseDir + '\utils\composer.bat', Str, False);
end;
procedure CreatePathEnvironment;
begin
WizardForm.StatusLabel.Caption := 'Adding PATH environment variables ...';
EnvAddPath(ExpandConstant('{app}\utils'));
EnvAddPath(ExpandConstant('{app}\pkg\winacme'));
EnvAddPath(ExpandConstant('{app}\pkg\httpd\bin'));
EnvAddPath(ExpandConstant('{app}\pkg\imagick\bin'));
EnvAddPath(ExpandConstant('{app}\pkg\php\php-7.4-ts'));
EnvAddPath(ExpandConstant('{userappdata}\Composer\vendor\bin'));
CreateEnvironmentVariable('OPENSSL_CONF', ExpandConstant('{app}\pkg\httpd\conf\openssl.cnf'));
end;
procedure RemovePathEnvironment;
begin
EnvRemovePath(ExpandConstant('{app}\utils'));
EnvRemovePath(ExpandConstant('{app}\pkg\winacme'));
EnvRemovePath(ExpandConstant('{app}\pkg\httpd\bin'));
EnvRemovePath(ExpandConstant('{app}\pkg\imagick\bin'));
EnvRemovePath(ExpandConstant('{app}\pkg\php\php-7.4-ts'));
EnvRemovePath(ExpandConstant('{userappdata}\Composer\vendor\bin'));
RemoveEnvironmentVariable('OPENSSL_CONF');
end;
procedure StartAppServices;
begin
Exec(ExpandConstant('net.exe'), 'start VarletHttpd', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Exec(ExpandConstant('net.exe'), 'start AcrylicDNSProxySvc', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Exec(ExpandConstant('net.exe'), 'start VarletMailhog', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
procedure InstallHttpdService;
var HttpdBin : String;
begin
BaseDir := ExpandConstant('{app}');
HttpdBin := BaseDir + '\pkg\httpd\bin\httpd.exe';
WizardForm.StatusLabel.Caption := 'Installing Apache Web Server ...';
FileReplaceString(BaseDir + '\pkg\httpd\conf\httpd.conf', '<<INSTALL_DIR>>', PathWithSlashes(ExpandConstant('{app}')));
Str := '-k install -n "VarletHttpd" -f '+BaseDir+'"\pkg\httpd\conf\httpd.conf"';
Exec(HttpdBin, Str, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
if WizardIsTaskSelected('task_autorun_service') then begin
Exec(ExpandConstant('sc.exe'), 'config VarletHttpd start=auto', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end else begin
Exec(ExpandConstant('sc.exe'), 'config VarletHttpd start=demand', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
Exec(ExpandConstant('net.exe'), 'stop VarletHttpd', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
procedure InstallDNSResolverService;
begin
BaseDir := ExpandConstant('{app}');
WizardForm.StatusLabel.Caption := 'Installing DNS Resolver ...';
if IsServiceInstalled('AcrylicDNSProxySvc') then KillService('AcrylicDNSProxySvc');
FileReplaceString(BaseDir + '\pkg\acrylic\AcrylicConfiguration.ini', '<<INSTALL_DIR>>', ExpandConstant('{app}'));
Exec(BaseDir + '\pkg\acrylic\AcrylicUI.exe', 'InstallAcrylicService', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
if WizardIsTaskSelected('task_autorun_service') then begin
Exec(ExpandConstant('sc.exe'), 'config AcrylicDNSProxySvc start=auto', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end else begin
Exec(ExpandConstant('sc.exe'), 'config AcrylicDNSProxySvc start=demand', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
Exec(ExpandConstant('net.exe'), 'stop AcrylicDNSProxySvc', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
procedure InstallMailhogService;
begin
BaseDir := ExpandConstant('{app}');
WizardForm.StatusLabel.Caption := 'Installing Mailhog services ...';
FileReplaceString(BaseDir + '\pkg\mailhog\mailhogservice.xml', '<<INSTALL_DIR>>', ExpandConstant('{app}'));
if WizardIsTaskSelected('task_autorun_service') then begin
FileReplaceString(BaseDir + '\pkg\mailhog\mailhogservice.xml', '<<SERVICE_MODE>>', 'Automatic');
end else begin
FileReplaceString(BaseDir + '\pkg\mailhog\mailhogservice.xml', '<<SERVICE_MODE>>', 'Manual');
end;
Exec(BaseDir + '\pkg\mailhog\mailhogservice.exe', 'install', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Exec(ExpandConstant('net.exe'), 'stop VarletMailhog', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpLicense then begin
WizardForm.NextButton.Caption := '&I agree';
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
// When installing
if CurStep = ssPostInstall then begin
WizardForm.StatusLabel.Caption := 'Setting up application configuration ...';
ConfigureApplication;
InstallHttpdService;
InstallDNSResolverService;
if WizardIsTaskSelected('task_install_mailhog') then InstallMailhogService;
if WizardIsTaskSelected('task_add_path_envars') then CreatePathEnvironment;
if WizardIsTaskSelected('task_autorun_service') then StartAppServices;
end;
// When it's done
if (CurStep=ssDone) then begin
ShellExec('open', ExpandConstant('{app}\VarletUi.exe'), '', '', SW_SHOW, ewNoWait, ResultCode);
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
case CurUninstallStep of
usUninstall:
begin
KillService('VarletHttpd');
KillService('AcrylicDNSProxySvc');
KillService('VarletMailhog');
TaskKillByPid('VarletUi.exe');
TaskKillByPid('varlet.exe');
RemovePathEnvironment;
end;
usPostUninstall:
begin
// MsgBox(ExpandConstant('{#AppName}') + ' has been uninstalled!', mbInformation, MB_OK);
// ShellExec('open', 'https://varlet.dev/goodbye', '', '', SW_SHOW, ewNoWait, ResultCode);
end;
end;
end;