-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathWindowsInstaller.ps1
308 lines (284 loc) · 12.8 KB
/
WindowsInstaller.ps1
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
$InstallerOut = @"
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "openBVE"
#define MyAppVersion "$args"
#define MyAppPublisher "The OpenBVE Project"
#define MyAppURL "http://www.openbve-project.net"
#define OpenBVEExecutable "OpenBve.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D617A45D-C2F6-44D1-A85C-CA7FFA91F7FC}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
DisableDirPage=auto
DisableProgramGroupPage=auto
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-setup
Compression=lzma2
SolidCompression=yes
WizardSmallImageFile=installer_logo.bmp
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl"
Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl"
Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
Name: "desktopicon2"; Description: "Create a desktop shortcut to the openBVE Addons folder"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
[Files]
;Open BVE Main Folder.
Source: "..\..\bin_release\*"; DestDir: "{app}"; Flags: recursesubdirs ignoreversion
;Custom Config File
Source: "InstallerData\filesystem_appdata.cfg"; DestDir: "{app}\";
Source: "InstallerData\filesystem_programfolder.cfg"; DestDir: "{app}\";
;MS .NET 4.6.1 Web Installer.
Source: "InstallerData\NDP461-KB3102438-Web.exe"; DestDir: "{app}"; Flags: deleteafterinstall; AfterInstall: AfterMyProgInstall('AllFilesCopy')
[Icons]
Name: "{userdesktop}\{#MyAppName}"; Filename: "{app}\{#OpenBVEExecutable}"; Tasks: desktopicon
Name: "{group}\{#MyAppName} (32-bit)"; Filename: "{app}\OpenBVE-32.exe"
Name: "{userdesktop}\openBVE Addons"; Filename:"{code:GetDataDir}"; Tasks: desktopicon2
Name: "{group}\{#MyAppName}"; Filename: "{app}\OpenBVE.exe"
Name: "{group}\Developer Tools\Route Viewer"; Filename: "{app}\RouteViewer.exe"
Name: "{group}\Developer Tools\Object Viewer"; Filename: "{app}\ObjectViewer.exe"
Name: "{group}\Developer Tools\Train Editor"; Filename: "{app}\TrainEditor2.exe"
Name: "{group}\openBVE Addons"; Filename: "{code:GetDataDir}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{app}\openBVE Addons"; Filename: "{code:GetDataDir}"; Flags: uninsneveruninstall
[Dirs]
Name: {code:GetDataDir}; Flags: uninsneveruninstall
[Run]
Filename: "{app}\{#OpenBVEExecutable}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: postinstall shellexec skipifsilent runascurrentuser
Filename: "{code:GetDataDir}"; Description: "Open the openBVE Addons Folder" ; Flags: postinstall shellexec waituntilterminated skipifsilent unchecked
[Code]
var
UsagePage: TInputOptionWizardPage;
DataDirPage: TInputDirWizardPage;
use_Net4: Cardinal;
ResultCode_Net4: Integer;
procedure InitializeWizard;
begin
{ Create the pages }
UsagePage := CreateInputOptionPage(wpSelectTasks,
'Select Destination Location', 'Where should openBVE Addons be installed?',
'Please specify the installation location for openBVE Addons.'#13#10 +
'NOTE: This may be changed at a later date using the Options dialog.',
True, False);
UsagePage.Add('Default - Use AppData\Roaming\openBVE\UserData');
UsagePage.Add('Program - Use the UserData folder in the openBVE installation directory');
UsagePage.Add('Custom - Select a custom folder');
DataDirPage := CreateInputDirPage(UsagePage.ID,
'Select openBVE Addons Directory', 'Where should openBVE Addons be installed?',
'Please select the folders in which you wish to install openBVE Addons, and then click Next.',
False, '');
DataDirPage.Add('Routes:');
//'Select Destination Location', 'Where should openBVE Addons be installed?'
DataDirPage.Add('Trains:');
DataDirPage.Add('Other:');
{ Set default values, using settings that were stored last time if possible }
case GetPreviousData('UsageMode', '') of
'Default': UsagePage.SelectedValueIndex := 0;
'Assembly': UsagePage.SelectedValueIndex := 1;
'Custom': UsagePage.SelectedValueIndex := 2;
else
UsagePage.SelectedValueIndex := 0;
end;
DataDirPage.Values[0] := GetPreviousData('DataDir0', ExpandConstant('{userappdata}\{#MyAppName}\LegacyContent\Railway'));
DataDirPage.Values[1] := GetPreviousData('DataDir1', ExpandConstant('{userappdata}\{#MyAppName}\LegacyContent\Train'));
DataDirPage.Values[2] := GetPreviousData('DataDir2', ExpandConstant('{userappdata}\{#MyAppName}\LegacyContent\Other'));
ResultCode_Net4 := 0;
end;
procedure RegisterPreviousData(PreviousDataKey: Integer);
var
UsageMode: String;
begin
{ Store the settings so we can restore them next time }
case UsagePage.SelectedValueIndex of
0: UsageMode := 'Default';
1: UsageMode := 'Assembly';
2: UsageMode := 'Custom';
end;
SetPreviousData(PreviousDataKey, 'UsageMode', UsageMode);
SetPreviousData(PreviousDataKey, 'DataDir0', DataDirPage.Values[0]);
SetPreviousData(PreviousDataKey, 'DataDir1', DataDirPage.Values[1]);
SetPreviousData(PreviousDataKey, 'DataDir2', DataDirPage.Values[2]);
end;
function GetDataDir(Param: String): String;
begin
{ Return the selected DataDir }
Result := DataDirPage.Values[0];
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
{ Skip pages that shouldn't be shown }
if (PageID = DataDirPage.ID) and (UsagePage.SelectedValueIndex <> 2) then
begin
//If this is a NEW install, and we've selected one of the default route/ train install locations
//Skip the folder selection page
Result := True;
end
else if (PageID = UsagePage.ID) then
begin
//Detect whether we've got an existing filsystem.cfg file present
if (FileExists(ExpandConstant('{userappdata}\{#MyAppName}\Settings\FileSystem.cfg')) or FileExists(ExpandConstant('{app}\UserData\Settings\filesystem.cfg'))) then
begin
//Existing install with cfg present, don't show the configuration dialog
Result := True;
end
else
//No existing filesystem.cfg , so ask the user for the directories
Result := False;
end
else
//Catch-all final false
Result := False;
end;
function GetHKLM: Integer;
begin
{ Determine whether it is 64bit OS. }
if IsWin64 then
Result := HKLM64
else
Result := HKLM32;
end;
//Executed after file installation
procedure AfterMyProgInstall(S: String);
var
Installed: Cardinal;
FileLines: TArrayOfString;
begin
//Determine whether the component is installed.
if RegQueryDWordValue(GetHKLM(),'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release',Installed) then begin
if Installed >= 394254 then begin
Log('.Net Framework 4 not detected- Launching web installer.');
use_Net4:=1;
end else begin
use_Net4:=0;
Log('.Net Framework 4 is already installed, skipping.');
end;
end;
begin
if use_Net4 = 1 then begin
end else begin
WizardForm.FilenameLabel.Caption := 'Installing Microsoft .NET Framework 4.6.1';
if Exec(ExpandConstant('{app}\NDP461-KB3102438-Web.exe'), '/norestart /passive /showrmui', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode_Net4) then
begin
IntToStr(ResultCode_Net4)
// handle success if necessary; ResultCode contains the exit code
Log('.Net Install completed sucessfully');
end
else begin
// handle failure if necessary; ResultCode contains the error code;
Log('.Net Install failed with error code ' + IntToStr(ResultCode_Net4));
end;
end;
if (UsagePage = nil) or (DataDirPage = nil) then
// Speculative, issue with something on re-install?: https://github.com/leezer3/OpenBVE/issues/806
begin
Log('Either DataDirPage or UsagePage was null. This should not happen....');
end
else begin
//OpenBVE filesystem.cfg
if (UsagePage.SelectedValueIndex = 0) then
begin
Log('Using the AppData folder to store all settings, routes and trains');
try
CreateDir(ExpandConstant('{userappdata}\{#MyAppName}'));
ForceDirectories(ExpandConstant('{{userappdata}\{#MyAppName}\Settings'));
FileCopy(ExpandConstant('{app}\filesystem_appdata.cfg'), ExpandConstant('{userappdata}\{#MyAppName}\Settings\filesystem.cfg'), True);
DeleteFile(ExpandConstant('{app}\filesystem_programfolder.cfg'));
DataDirPage.Values[0] := ExpandConstant('{userappdata}\{#MyAppName}\LegacyContent\Railway');
DataDirPage.Values[1] := ExpandConstant('{userappdata}\{#MyAppName}\LegacyContent\Train');
except
Log('Unexpected error occured whilst creating initial settings');
end;
end;
if (UsagePage.SelectedValueIndex = 1) then
begin
Log('Using the UserData folder to store all settings, routes and trains');
try
ForceDirectories(ExpandConstant('{app}\UserData\Settings'));
FileCopy(ExpandConstant('{app}\filesystem_programfolder.cfg'), ExpandConstant('{app}\UserData\Settings\filesystem.cfg'), True);
DeleteFile(ExpandConstant('{app}\filesystem_appdata.cfg'));
DataDirPage.Values[0] := ExpandConstant('{app}\UserData');
except
Log('Unexpected error occured whilst creating initial settings');
end;
end;
if (UsagePage.SelectedValueIndex = 2) then
begin
Log('Using Custom Folders to store all settings, routes and trains');
try
ForceDirectories(ExpandConstant('{app}\UserData\Settings'));
//Load filesystem.cfg
LoadStringsFromFile(ExpandConstant('{app}\UserData\Settings\filesystem.cfg'), FileLines);
FileLines[2]:='InitialRoute = '+DataDirPage.Values[0];
FileLines[3]:='InitialTrain = '+DataDirPage.Values[1];
FileLines[4]:='RoutePackageInstall = '+DataDirPage.Values[0];
FileLines[5]:='TrainPackageInstall = '+DataDirPage.Values[1];
//Save filesystem.cfg
SaveStringsToUTF8File(ExpandConstant('{app}\UserData\Settings\filesystem.cfg'),FileLines,false);
except
Log('Unexpected error occured whilst creating initial settings');
end;
end;
Log('Creating RouteInstall directory ' + DataDirPage.Values[0]);
ForceDirectories(DataDirPage.Values[0]);
Log('Creating TrainInstall directory ' + DataDirPage.Values[1]);
ForceDirectories(DataDirPage.Values[1])
end;
end;
end;
function NeedRestart(): Boolean;
begin
if ResultCode_Net4 = 3010 then
begin
Result := True;
end;
end;
//==========Uninstall Section==========
function InitializeUninstall(): Boolean;
begin
MsgBox('Add-on data will not be deleted during uninstallation.', mbError, MB_OK);
Result := True
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
ResultCode: Integer;
begin
case CurUninstallStep of usDone:
begin
Exec('explorer.exe',ExpandConstant('{app}') , '', SW_SHOW, ewNoWait,ResultCode);
end;
end;
end;
"@
$InstallerOut | Out-File -FilePath $PSScriptRoot\installers\windows\openbve.iss -Encoding UTF8
& "C:\Program Files (x86)\Inno Setup 6\iscc.exe" /q $PSScriptRoot\installers\windows\openbve.iss