-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSH2EE-web-installer.iss
946 lines (840 loc) · 32.9 KB
/
SH2EE-web-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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
; -- SH2EE Web Installer --
#define INSTALLER_VER "1.1.5"
#define DEBUG "true"
#define SH2EE_CSV_URL "https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/master/Resources/webcsv.url"
#define PROJECT_URL "https://enhanced.townofsilenthill.com/SH2/"
#define TROUBLESHOOT_URL "https://enhanced.townofsilenthill.com/SH2/troubleshoot.htm"
#define HELP_URL "https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues"
#define eeModuleName "SH2 Enhancements Module"
#define wine_stubName "Wine/Linux Support"
#define ee_exeName "Enhanced Executable"
#define ee_essentialsName "Enhanced Edition Essential Files"
#define img_packName "Image Enhancement Pack"
#define fmv_packName "FMV Enhancement Pack"
#define audio_pack "Audio Enhancement Pack"
;#define dsoalName "DSOAL"
#define xidiName "Xidi"
#define CreditsName "Credits"
#include "languages/English.iss"
#include "languages/BrazilianPortuguese.iss"
#include "languages/Spanish.iss"
#include "languages/Italian.iss"
#include "languages/Japanese.iss"
[Setup]
AppName=Silent Hill 2: Enhanced Edition
AppVersion={#INSTALLER_VER}
WizardStyle=modern
DefaultDirName={code:GetDefaultDirName}
OutputDir=build
OutputBaseFilename=SH2EEsetup
DirExistsWarning=no
DisableWelcomePage=no
RestartIfNeededByRun=no
AppendDefaultDirName=no
DisableProgramGroupPage=yes
UsePreviousTasks=no
UsePreviousSetupType=no
UsePreviousAppDir=no
RestartApplications=no
Uninstallable=no
DisableDirPage=no
ShowLanguageDialog=no
WizardResizable=yes
SetupIconFile=resources\icon.ico
WizardImageFile=resources\side.bmp
WizardSmallImageFile=resources\top.bmp
WizardImageAlphaFormat=premultiplied
VersionInfoVersion={#INSTALLER_VER}
VersionInfoCompany=nipkow
VersionInfoDescription=Silent Hill 2: Enhanced Edition Web Installer
VersionInfoTextVersion={#INSTALLER_VER}
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"; LicenseFile: "languages\English-license.rtf"
Name: "pt_br"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"; LicenseFile: "languages\BrazilianPortuguese-license.rtf"
Name: "es"; MessagesFile: "compiler:Languages\Spanish.isl"; LicenseFile: "languages\Spanish-license.rtf"
Name: "it"; MessagesFile: "compiler:Languages\Italian.isl"; LicenseFile: "languages\Italian-license.rtf"
Name: "jp"; MessagesFile: "compiler:Languages\Japanese.isl"; LicenseFile: "languages\Japanese-license.rtf"
[Types]
Name: full; Description: {cm:installTypeFull}
Name: custom; Description: {cm:installTypeCustom}; Flags: iscustom
[Components]
; *** component name MUST match the component "id" in _sh2ee.csv! ***
Name: sh2emodule; Description: {#eeModuleName}; Types: full custom; Flags: checkablealone
Name: sh2emodule\wine_stub; Description: {#wine_stubName}; Types: custom; Flags: dontinheritcheck
Name: ee_exe; Description: {#ee_exeName}; Types: full custom
Name: ee_essentials; Description: {#ee_essentialsName}; Types: full
Name: img_pack; Description: {#img_packName}; Types: full
Name: fmv_pack; Description: {#fmv_packName}; Types: full
Name: audio_pack; Description: {#audio_pack}; Types: full
;Name: dsoal; Description: {#dsoalName}; Types: full
Name: xidi; Description: {#xidiName}; Types: full
Name: credits; Description: {#creditsName}; Types: full custom
[Files]
; Tools below
Source: "includes\7zip\7za_x86.exe"; Flags: dontcopy
Source: "includes\7zip\7za_x64.exe"; Flags: dontcopy
Source: "includes\cmdlinerunner\cmdlinerunner.dll"; Flags: dontcopy
Source: "includes\BytesToString\BytesToString.dll"; Flags: dontcopy
Source: "includes\deletefile_util\deletefile_util.exe"; Flags: dontcopy
Source: "includes\renamefile_util\renamefile_util.exe"; Flags: dontcopy
Source: "{srcexe}"; DestDir: "{tmp}"; DestName: "SH2EEsetup.exe"; Flags: external
Source: "resources\top.bmp"; Flags: dontcopy
Source: "resources\maintenance\icon_install.bmp"; Flags: dontcopy
Source: "resources\maintenance\icon_update.bmp"; Flags: dontcopy
Source: "resources\maintenance\icon_adjust.bmp"; Flags: dontcopy
Source: "resources\maintenance\icon_uninstall.bmp"; Flags: dontcopy
Source: "resources\maintenance\icon_nointernet.bmp"; Flags: dontcopy
[Run]
Filename: "{app}\sh2pc.exe"; Description: {cm:StartGameAfterExiting}; Flags: nowait postinstall skipifsilent unchecked
Filename: "{app}\SH2EEconfig.exe"; Description: {cm:OpenCfgToolAfterExiting}; Flags: nowait postinstall skipifsilent unchecked
[Messages]
SetupAppTitle =Silent Hill 2: Enhanced Edition Setup Tool
SetupWindowTitle =Silent Hill 2: Enhanced Edition Setup Tool
WelcomeLabel1 =Silent Hill 2: Enhanced Edition Setup Tool
// Seems IDP must be included before [Code]
#include "includes/innosetup-download-plugin/idp.iss"
// IDP langs must be included after idp.iss
#include "includes/innosetup-download-plugin/source/unicode/idplang/BrazilianPortuguese.iss"
#include "includes/innosetup-download-plugin/source/unicode/idplang/Spanish.iss"
#include "includes/innosetup-download-plugin/source/unicode/idplang/Italian.iss"
[Code]
type
TIniArray = record
Section : String;
Key : String;
Value : String;
end;
TSizeArray = record
Bytes : Int64;
String : String;
end;
TLocalComponentsInfo = record
ID : String;
Name : String;
fileName : String;
Version : String;
end;
TWebComponentsInfo = record
ID : String;
Name : String;
Version : String;
URL : String;
SHA256 : String;
end;
TMaintenanceComponentsInfo = record
ID : String;
isInstalled : Boolean;
Version : String;
end;
var
webcsv_url : String;
LanguageButton : TButton;
userPackageDataDir : String;
maintenanceMode : Boolean;
updateMode : Boolean;
selfUpdateMode : Boolean;
uninstallOnly : Boolean;
localInstallMode : Boolean;
Uninstalling : Boolean;
CurIniArray : array of TIniArray;
FileSizeArray : array of TSizeArray;
sh2pcFilesWerePresent : Boolean;
LocalCompsArray : array of TLocalComponentsInfo;
WebCompsArray : array of TWebComponentsInfo;
MaintenanceCompsArray : array of TMaintenanceComponentsInfo;
#include "includes/Util.iss"
#include "CustomUninstall.iss"
#include "includes/Extractore.iss"
#include "wpMaintenance.iss"
#include "CSVparser.iss"
#include "wpSelectComponents.iss"
#include "wpExtract.iss"
#include "SelfUpdate.iss"
#include "CustomLabels.iss"
#include "LanguageDialog.iss"
#include "wpInstallMode.iss"
// Runs before anything else
function InitializeSetup(): Boolean;
var
i: integer;
CSVFilePath : String;
Language: string;
csvDownloadSuccess: Boolean;
urlDownloadSuccess: Boolean;
localFilesMissing :Boolean;
Lines: TStringList;
begin
Result := True;
// Determine whether or not we should be in "maintenance mode"
if DirExists(ExpandConstant('{src}\') + 'data') and FileExists(ExpandConstant('{src}\') + 'SH2EEsetup.dat') then
maintenanceMode := True;
// Set language
Language := ExpandConstant('{param:LANG}');
if Language = '' then
begin
Log('No language specified, calling language func');
SelectLanguage(false);
Result := False;
Exit;
end else
Log('Language specified, proceeding with installation');
// Determine weather or not we should be in local installation mode
if FileExists(ExpandConstant('{src}\') + 'local_sh2ee.dat') then
begin
// Create an array of TWebComponentsInfo records from sh2ee.csv and store them in a global variable
LocalCompsArray := LocalCSVToInfoArray(ExpandConstant('{src}\') + 'local_sh2ee.dat');
// Check if above didn't work
if GetArrayLength(LocalCompsArray) = 0 then
begin
if MsgBox(CustomMessage('LocalCSVParseFailed'), mbConfirmation, MB_YESNO) = IDYES then
begin
// Remove local files
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
DeleteFile(ExpandConstant('{src}\') + LocalCompsArray[i].fileName);
DeleteFile(ExpandConstant('{src}\') + 'local_sh2ee.dat')
SetArrayLength(LocalCompsArray, 0);
end else
begin
// User pressed No, so we exit
Result := False;
exit;
end;
end;
// Check if the local files from the local .csv actually exist
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do begin
if not (LocalCompsArray[i].fileName = 'notDownloaded') and not FileExists(ExpandConstant('{src}\') + LocalCompsArray[i].fileName) then
localFilesMissing := true;
end;
// Decide what to do if files are missing
if localFilesMissing then
begin
if MsgBox(CustomMessage('LocalCSVMissingFiles'), mbConfirmation, MB_YESNO) = IDYES then
begin
// Remove local files
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
DeleteFile(ExpandConstant('{src}\') + LocalCompsArray[i].fileName);
DeleteFile(ExpandConstant('{src}\') + 'local_sh2ee.dat')
SetArrayLength(LocalCompsArray, 0);
maintenanceMode := false; // Make sure this is false
end else
begin
// User pressed No, so we exit
Result := False;
exit;
end;
end else
begin
// Check if this version of the installer should work with the local .csv
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do begin
if LocalCompsArray[i].id = 'setup_tool' then
begin
if not SameText(LocalCompsArray[i].version, ExpandConstant('{#INSTALLER_VER}')) then
begin
MsgBox(FmtMessage(CustomMessage('LocalCSVIncompatibleVersion'), [ExpandConstant('{#INSTALLER_VER}'), LocalCompsArray[i].version]), mbCriticalError, MB_OK);
Result := False;
exit;
end;
end;
end;
// Guess everything should be fine then
localInstallMode := true;
end;
end;
// localInstallMode doesn't need any of this
if not localInstallMode then
begin
// Use local/debug .csv if it exist and "-sandbox" was used as a launch parameter
if FileExists(ExpandConstant('{src}\') + '_sh2ee.csv') and CmdLineParamExists('-sandbox') then
begin
Log('Using _sh2ee.csv from .exe dir!');
CSVFilePath := ExpandConstant('{src}\') + '_sh2ee.csv';
end else // Criteria not met, download .csv from web
begin
// Get web .csv URL from git repo's .url file
repeat
urlDownloadSuccess := idpDownloadFile('{#SH2EE_CSV_URL}', ExpandConstant('{tmp}\webcsv.url'));
// We'll allow the installer to "work" without the .csv in maintenance mode, so the
// user can uninstall the project without an internet connection.
if maintenanceMode and not urlDownloadSuccess then
begin
uninstallOnly := True;
Continue;
end;
if not urlDownloadSuccess then
begin
if MsgBox(CustomMessage('WebURLDownloadError'), mbConfirmation, MB_YESNO) = IDNO then
begin
Result := False;
exit;
end;
end;
until urlDownloadSuccess or uninstallOnly;
if not uninstallOnly then
begin
Lines := TStringList.Create;
Lines.LoadFromFile(ExpandConstant('{tmp}\webcsv.url'));
webcsv_url := Lines[0];
// Store the temp path to web sh2ee.csv
CSVFilePath := tmp(GetURLFilePart(webcsv_url));
// Download sh2ee.csv; show an error message and exit the installer if downloading fails
begin
repeat
csvDownloadSuccess := idpDownloadFile(webcsv_url, CSVFilePath);
// We'll allow the installer to "work" without the .csv in maintenance mode, so the
// user can uninstall the project without an internet connection.
if maintenanceMode and not urlDownloadSuccess then
begin
uninstallOnly := True;
Continue;
end;
if not csvDownloadSuccess then
begin
if MsgBox(CustomMessage('WebCSVDownloadError'), mbConfirmation, MB_YESNO) = IDNO then
begin
Result := False;
exit;
end;
end;
until csvDownloadSuccess or uninstallOnly;
end;
end;
end;
if not uninstallOnly then
begin
// Create an array of TWebComponentsInfo records from sh2ee.csv and store them in a global variable
WebCompsArray := WebCSVToInfoArray(CSVFilePath);
// Check if above didn't work
if GetArrayLength(WebCompsArray) = 0 then
begin
MsgBox(CustomMessage('WebCSVParseFailed'), mbCriticalError, MB_OK);
Result := False;
exit;
end;
// If we are in "maintenance mode"
if maintenanceMode then
begin
// Create an array of TMaintenanceComponentsInfo records from the existing SH2EEsetup.dat and store it in a global variable
MaintenanceCompsArray := MaintenanceCSVToInfoArray(ExpandConstant('{src}\SH2EEsetup.dat'));
// Check if above didn't work
if GetArrayLength(WebCompsArray) = 0 then
begin
MsgBox(CustomMessage('MaintenanceCSVParseFailed'), mbCriticalError, MB_OK);
Result := False;
exit;
end;
// Update and reload local CSV if array sizes are different
if not SamePackedVersion(GetArrayLength(MaintenanceCompsArray), GetArrayLength(WebCompsArray)) then // [2] Using SamePackedVersion() to compare lengths isn't the fanciest approach, but it works
begin
UpdateMaintenanceCSV(true);
MaintenanceCompsArray := MaintenanceCSVToInfoArray(ExpandConstant('{src}\SH2EEsetup.dat'));
end;
// Update and reload local CSV if the order of ids don't match
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if not SameText(MaintenanceCompsArray[i].id, WebCompsArray[i].id) then
UpdateMaintenanceCSV(true);
MaintenanceCompsArray := MaintenanceCSVToInfoArray(ExpandConstant('{src}\SH2EEsetup.dat'));
end;
end;
// Enable Update if started with argument
if CmdLineParamExists('-update') and maintenanceMode and not uninstallOnly then
begin
GetComponentSizes();
updateMode := True;
end;
// Enable selfUpdate if started with argument
if CmdLineParamExists('-selfUpdate') and not uninstallOnly then
begin
selfUpdateMode := True;
maintenanceMode := True;
end;
// Check if the installer should work correctly with with the current server-side files
if not selfUpdateMode then
begin
for i := 0 to GetArrayLength(WebCompsArray) - 1 do begin
if WebCompsArray[i].id = 'setup_tool' then
begin
if not SameText(WebCompsArray[i].version, ExpandConstant('{#INSTALLER_VER}')) then
begin
if MsgBox(CustomMessage('OutdatedSetupTool'), mbConfirmation, MB_YESNO) = IDYES then
begin
selfUpdateMode := True;
maintenanceMode := True;
end else
begin
Result := False;
exit;
end;
end else
begin
// Make sure the local .csv has the current Setup Tool's version, as there is
// a chance the user might have manually updated the setup tool.
UpdateMaintenanceCSV_SetupToolOnly();
end;
end;
end;
end;
end;
end;
end;
// What to do if the user presses the help button
procedure HelpButtonClick(Sender: TObject);
var
ErrorCode: Integer;
begin
ShellExec('open', '{#HELP_URL}', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
// What to do if the user presses the language button
procedure LanguageButtonClick(Sender: TObject);
begin
// Show language dialog
if SelectLanguage(true) then
ExitProcess(1);
end;
procedure InitializeWizard();
var
HelpButton : TButton;
DebugLabel : TNewStaticText;
labelOffset : integer;
i: integer;
begin
if not localInstallMode then
begin
// Compare the lenght of the web CSV array with the installer's component list
if not uninstallOnly and not selfUpdateMode and not SamePackedVersion(WizardForm.ComponentsList.Items.Count, GetArrayLength(WebCompsArray) - 1) then // Using SamePackedVersion() to compare lengths isn't the fanciest approach, but it works
begin
MsgBox(CustomMessage('InvalidWebComponentsListSize'), mbCriticalError, MB_OK);
Abort;
end;
end else
begin
// Compare the lenght of the local CSV array with the installer's component list
if not SamePackedVersion(WizardForm.ComponentsList.Items.Count, GetArrayLength(LocalCompsArray) -1) then
begin
if MsgBox(CustomMessage('InvalidLocalComponentsListSize'), mbConfirmation, MB_YESNO) = IDYES then
begin
// Remove local files
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
DeleteFile(ExpandConstant('{src}\') + LocalCompsArray[i].fileName);
DeleteFile(ExpandConstant('{src}\') + 'local_sh2ee.dat')
// Run new instance
ShellExecute(0, '', ExpandConstant('{srcexe}'), '', '', SW_SHOW);
// Close this instance
Abort;
end else
begin
// User pressed No, so we just exit
Abort;
end;
end;
end;
// Replace some default labels with customized ones if not in maintenance mode
if not maintenanceMode then
Replace_Labels();
if not maintenanceMode and not localInstallMode then
PrepareInstallModePage();
// IDP settings
if not localInstallMode then
begin
idpSetOption('AllowContinue', '1');
idpSetOption('DetailsVisible', '1');
idpSetOption('DetailsButton', '1');
idpSetOption('RetryButton', '1');
idpSetOption('UserAgent', 'SH2EE web installer');
idpSetOption('InvalidCert', 'ignore');
end;
// Register new RunList OnClick event
WizardForm.RunList.OnClickCheck := @RunListClickCheck;
RunListLastChecked := -1;
// Customize the default SelectComponents
customize_wpSelectComponents();
// Start the download after wpReady
if not localInstallMode then
idpDownloadAfter(wpReady);
// "Install/Update/Uninstall", etc
if maintenanceMode and (not selfUpdateMode) then
PrepareMaintenance();
// Updates the setup tool itself
if selfUpdateMode then
PrepareSelfUpdate();
// Create the file extraction page
if not selfUpdateMode then
create_wpExtract();
// Force installation of the SH2E module, EE exe and credits if not in maintenance mode
if not maintenanceMode then
begin
WizardForm.ComponentsList.Checked[GetCompIndexByID('sh2emodule') - 1] := true;
WizardForm.ComponentsList.Checked[GetCompIndexByID('ee_exe') - 1] := true;
WizardForm.ComponentsList.Checked[GetCompIndexByID('credits') - 1] := true;
WizardForm.ComponentsList.ItemEnabled[GetCompIndexByID('sh2emodule') - 1] := false;
WizardForm.ComponentsList.ItemEnabled[GetCompIndexByID('ee_exe') - 1] := false;
WizardForm.ComponentsList.ItemEnabled[GetCompIndexByID('credits') - 1] := false;
end;
// Automatically check the wine_stub component if wine is detected
if not maintenanceMode then
WizardForm.ComponentsList.Checked[GetCompIndexByID('sh2emodule\wine_stub') - 1] := IsWine();
// Items names and descriptions on wpSelectComponents
create_CompNameDesc();
SetTimer(0, 0, 50, CreateCallback(@HoverTimerProc)); // Create onhover process
// Show help button on bottom left
HelpButton := TButton.Create(WizardForm);
with HelpButton do
begin
Top := WizardForm.CancelButton.Top;
Left := WizardForm.ClientWidth - WizardForm.CancelButton.Left - WizardForm.CancelButton.Width;
Height := WizardForm.CancelButton.Height;
Anchors := [akLeft, akBottom];
Caption := CustomMessage('HelpButton');
Cursor := crHelp;
Font.Color := clHighlight;
OnClick := @HelpButtonClick;
Parent := WizardForm;
end;
// Show language button in maintenanceMode
if maintenanceMode then
begin
LanguageButton := TButton.Create(WizardForm);
with LanguageButton do
begin
Top := WizardForm.CancelButton.Top;
Left := HelpButton.Left + HelpButton.Width + ScaleX(10);
Height := WizardForm.CancelButton.Height;
Width := WizardForm.CancelButton.Width + ScaleX(25);
Anchors := [akLeft, akBottom];
Caption := CustomMessage('LanguageButton');
Font.Color := clHighlight;
OnClick := @LanguageButtonClick;
Parent := WizardForm;
end;
end;
// Show "DEBUG ON" text
if {#DEBUG} then
begin
DebugLabel := TNewStaticText.Create(WizardForm);
with DebugLabel do
begin
Top := HelpButton.Top + 4;
Anchors := [akRight, akBottom];
Left := WizardForm.BackButton.Left - WizardForm.BackButton.Width;
Caption := ExpandConstant('DEBUG ON');
Font.Style := [fsBold];
Parent := WizardForm;
end;
end;
// Show "OFFLINE INSTALLATION" text
if localInstallMode then
begin
DebugLabel := TNewStaticText.Create(WizardForm);
with DebugLabel do
begin
Top := HelpButton.Top + 4;
Anchors := [akLeft, akBottom];
Left := HelpButton.Left + HelpButton.Width + 10;
Caption := ExpandConstant('OFFLINE INSTALLATION');
Font.Style := [fsBold];
Parent := WizardForm;
end;
end;
// Show "SANDBOX MODE" text
if FileExists(ExpandConstant('{src}\') + '_sh2ee.csv') and CmdLineParamExists('-sandbox') then
begin
if maintenanceMode then
labelOffset := ScaleX(120)
else
labelOffset := ScaleX(10);
DebugLabel := TNewStaticText.Create(WizardForm);
with DebugLabel do
begin
Top := HelpButton.Top + 4;
Anchors := [akLeft, akBottom];
Left := HelpButton.Left + HelpButton.Width + labelOffset;
Caption := ExpandConstant('SANDBOX MODE');
Font.Style := [fsBold];
Parent := WizardForm;
end;
end;
end;
function ShouldSkipPage(CurPage: Integer): Boolean;
begin
Result := False;
// Skip pages if in selfUpdateMode
if selfUpdateMode then
begin
if (CurPage = wpSelectComponents) or
(CurPage = wpFinished) then
begin
Result := True;
end;
end;
// Skip wpSelectComponents and wpExtract if uninstalling
if maintenanceMode and not selfUpdateMode then
begin
if (CurPage = wpSelectComponents) or
(CurPage = wpExtract.ID) then
if uninstallRadioBtn.Checked then
Result := True;
end;
// Skip pages if running launcher
if maintenanceMode and not selfUpdateMode and not updateMode then
begin
if (CurPage = wpSelectComponents) or
(CurPage = wpExtract.ID) or
(CurPage = wpPreparing) or
(CurPage = wpInstalling) or
(CurPage = wpFinished) then
if adjustRadioBtn.Checked then
Result := True;
end;
// Skip to updater page if started with argument
if CmdLineParamExists('-update') and maintenanceMode and not uninstallOnly then
begin
if (CurPage = wpMaintenance.ID) then
begin
Result := True;
end;
end;
// Skip normal setup pages if in maintenanceMode
if maintenanceMode then
begin
if (CurPage = wpWelcome) or
(CurPage = wpLicense) or
(CurPage = wpSelectDir) or
(CurPage = wpReady) then
begin
Result := True;
end;
end;
end;
function NextButtonClick(CurPage: Integer): Boolean;
var
i : Integer;
iRequiredSize : Int64;
begin
Result := True;
if (CurPage = wpWelcome) and not maintenanceMode then
begin
GetComponentSizes();
end;
if CurPage = wpSelectComponents then
begin
// Check if componentes are selected
if iTotalCompCount = 0 then
begin
MsgBox(CustomMessage('NoComponentsSelected'), mbInformation, MB_OK);
Result := False;
exit;
end;
// Check if we have enough free space
iRequiredSize := iTotalCompSize * 2;
Log(WizardDirValue);
if not IsEnoughFreeSpace(WizardDirValue, iRequiredSize) then
begin
MsgBox(FmtMessage(CustomMessage('NoFreeSpace'), [BytesToString(iRequiredSize)]), mbCriticalError, MB_OK);
ExitProcess(666);
end;
// Add files to IDP
if not localInstallMode then
begin
iTotalCompCount := 0; // Clear list
idpClearFiles(); // Make sure idp file list is clean
for i := 0 to WizardForm.ComponentsList.Items.Count - 1 do
begin
if WizardForm.ComponentsList.Checked[i] then
begin
iTotalCompCount := iTotalCompCount + 1;
idpAddFile(WebCompsArray[i + 1].URL, localDataDir(GetURLFilePart(WebCompsArray[i + 1].URL)));
end;
end;
end;
selectedComponents := WizardSelectedComponents(false);
Log('# The following [' + IntToStr(iTotalCompCount) + '] components are selected: ' + selectedComponents);
end;
// Check for file presence in WizardDirValue
if CurPage = wpSelectDir then
begin
if not FileExists(AddBackslash(WizardDirValue) + 'data\pic\etc\konami.tex') then
begin
if MsgBox(CustomMessage('GameFilesNotFound'), mbConfirmation, MB_YESNO) = IDYES then
begin
Result := True;
sh2pcFilesWerePresent := False;
end else
Result := False;
end else
sh2pcFilesWerePresent := True;
// Check for the presence of a semicolon in the installation path
if Pos(';', WizardDirValue) > 0 then
begin
MsgBox(CustomMessage('SemicolonInPath'), mbInformation, MB_OK);
Result := False;
end;
end;
end;
procedure postInstall();
begin
if selfUpdateMode then
SelfUpdate_postInstall();
// User chose to back up installation files
if (Length(userPackageDataDir) > 0) then
begin
CreateLocalCSV();
FileCopy(ExpandConstant('{tmp}\SH2EEsetup.exe'), localDataDir('SH2EEsetup.exe'), false);
end;
// Copy SH2EEsetup.exe to the game's directory if we're not currently running from it
if not (DirExists(ExpandConstant('{src}\') + 'data') and FileExists(ExpandConstant('{src}\') + 'SH2EEsetup.dat')) then
FileCopy(ExpandConstant('{tmp}\SH2EEsetup.exe'), ExpandConstant('{app}\SH2EEsetup.exe'), false);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
//if CurStep = ssInstall then preInstall();
if CurStep = ssPostInstall then postInstall();
end;
procedure CurPageChanged(CurPage: Integer);
var
sh2pcFilesExist : Boolean;
i : Integer;
compIndex : Integer;
begin
// Only enable the lang button if we're in the main maintenance page
if maintenanceMode and not selfUpdateMode then
begin
if (CurPage = wpMaintenance.ID) then
LanguageButton.Enabled := true
else
LanguageButton.Enabled := false;
end;
// Update ComponentsList changes
if (CurPage = wpSelectComponents) then
begin
// Text adjustments for maintenanceMode
if maintenanceMode then
begin
// Hide TypesCombo
WizardForm.TypesCombo.Visible := False;
WizardForm.IncTopDecHeight(WizardForm.ComponentsList, - (WizardForm.ComponentsList.Top - WizardForm.TypesCombo.Top));
// "Install/Repair" page
if installRadioBtn.Checked then
begin
// Text adjustments
WizardForm.PageDescriptionLabel.Caption := CustomMessage('installPageDescriptionLabel');
WizardForm.SelectComponentsLabel.Caption := CustomMessage('installSelectComponentsLabel');
WizardForm.SelectComponentsLabel.Height := 40; // Default value
WizardForm.ComponentsList.Top := 50; // Default value
WizardForm.ComponentsList.Height := ScaleY(150);
// Update the components title/desc Top pos
CompTitle.Top := WizardForm.ComponentsList.Top + WizardForm.ComponentsList.Height - CompTitle.Height - ScaleY(-40);
CompDescription.Top := CompTitle.Top + CompTitle.Height - ScaleY(20);
end else if updateRadioBtn.Checked or updateMode then // "Update" page
begin
// Text adjustments
WizardForm.PageDescriptionLabel.Caption := CustomMessage('updatePageDescriptionLabel');
WizardForm.SelectComponentsLabel.Caption := CustomMessage('updateSelectComponentsLabel');
WizardForm.SelectComponentsLabel.Height := 20;
WizardForm.ComponentsList.Top := 30;
WizardForm.ComponentsList.Height := ScaleY(170);
// Gotta update the components title/desc Top pos as well
CompTitle.Top := WizardForm.ComponentsList.Top + WizardForm.ComponentsList.Height - CompTitle.Height - ScaleY(-40);
CompDescription.Top := CompTitle.Top + CompTitle.Height - ScaleY(20);
end;
// ComponentsList adjustments
for i := 0 to GetArrayLength(WebCompsArray) - 1 do begin
if not (WebCompsArray[i].id = 'setup_tool') then
begin
compIndex := GetCompIndexByID(WebCompsArray[i].id);
if compIndex > -1 then
begin
with Wizardform.ComponentsList do
begin
// Unchecked and enabled by default
Checked[i - 1] := false;
ItemEnabled[i - 1] := true;
if updateRadioBtn.Checked or updateMode then // "Update" page
begin
Checked[i - 1] := isUpdateAvailable(WebCompsArray[i].Version, MaintenanceCompsArray[compIndex].Version, MaintenanceCompsArray[compIndex].isInstalled);
ItemEnabled[i - 1] := isUpdateAvailable(WebCompsArray[i].Version, MaintenanceCompsArray[compIndex].Version, MaintenanceCompsArray[compIndex].isInstalled);
end;
end;
end;
end;
end;
end;
update_ComponentsList();
end;
// Disable the run checkbox if the sh2pc files were not present when the installation directory was selected, and we're not in maintenance mode
if (CurPage = wpFinished) and not maintenanceMode and not sh2pcFilesWerePresent then
begin
WizardForm.RunList.ItemEnabled[0] := False;
WizardForm.RunList.Checked[0] := False;
WizardForm.RunList.ItemCaption[0] := CustomMessage('StartGameAfterExiting') + ' (' + CustomMessage('UnavailableOption') + ')';
end;
// Check the run checkbox if the sh2pc files were present when the installation directory was selected, and we're not in maintenance mode
if (CurPage = wpFinished) and not maintenanceMode and sh2pcFilesWerePresent then
begin
WizardForm.RunList.Checked[0] := true;
RunListLastChecked := 0;
end;
// maintenanceMode's wpFinished tweaks
if (CurPage = wpFinished) and maintenanceMode then
begin
sh2pcFilesExist := FileExists(AddBackslash(WizardDirValue) + 'data\pic\etc\konami.tex');
// Check run box for updateMode
if updateMode then
begin
WizardForm.RunList.Visible := true;
WizardForm.RunList.Checked[0] := true;
RunListLastChecked := 0;
end else
if installRadioBtn.Checked then
begin
// Change default labels to fit the install action
WizardForm.FinishedLabel.Caption := CustomMessage('InstallSuccess');
WizardForm.RunList.Visible := true;
WizardForm.RunList.Checked[0] := true;
RunListLastChecked := 0;
end else
if updateRadioBtn.Checked then
begin
// Change default labels to fit the update action
WizardForm.FinishedHeadingLabel.Caption := CustomMessage('updateFinishedHeadingLabel');
WizardForm.FinishedLabel.Caption := CustomMessage('UpdateSuccess');
WizardForm.RunList.Visible := true;
WizardForm.RunList.Checked[0] := true;
RunListLastChecked := 0;
end else
if uninstallRadioBtn.Checked then
begin
// Change default labels to fit the uninstaller action
WizardForm.FinishedHeadingLabel.Caption := CustomMessage('uninstallFinishedHeadingLabel');
WizardForm.FinishedLabel.Caption := CustomMessage('UninstallSuccess');
// Hide and uncheck the run checkbox when uninstalling
WizardForm.RunList.Visible := false;
WizardForm.RunList.Checked[0] := false;
WizardForm.RunList.Checked[1] := false;
end;
// Hide and uncheck the run checkbox if the data folder doesn't exist
if not sh2pcFilesExist then
begin
WizardForm.RunList.Visible := false;
WizardForm.RunList.Checked[0] := false;
WizardForm.RunList.Checked[1] := false;
end;
// Disable the run checkbox if the sh2pc.exe doesn't exist
if not FileExists(ExpandConstant('{src}\') + 'sh2pc.exe') then
begin
WizardForm.RunList.ItemEnabled[0] := False;
WizardForm.RunList.Checked[0] := False;
WizardForm.RunList.ItemCaption[0] := CustomMessage('StartGameAfterExiting') + ' (' + CustomMessage('UnavailableOption') + ')';
end;
end;
end;
procedure DeinitializeSetup();
var
logfilepathname, logfilename, newfilepathname: string;
begin
if not CmdLineParamExists('/LOG') then Exit;
logfilepathname := ExpandConstant('{log}');
logfilename := ExtractFileName(logfilepathname);
// Set the new target path as the directory where the installer is being run from
newfilepathname := ExpandConstant('{src}\') + logfilename;
FileCopy(logfilepathname, newfilepathname, false);
end;