-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMainCode.iss
284 lines (216 loc) · 7.9 KB
/
MainCode.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
[Code]
//GlobalVariables
var
PresetFile: String;
OriginalTypeComboChangedEvent: TNotifyEvent;
OriginalResizeEvent: TNotifyEvent;
ChangeBannerButton: TNewButton;
EngDisable: Boolean;
[/Code]
//The following script contains a bunch of helper functions and methods. They were moved out so better track could be kept.
#include "Helpers.iss"
//Functions to help work with the game's differences.
#include "COM3D2Helpers.iss"
//More helper functions for handling the backing up of previous installs.
#include "OldInstallHandler.iss"
//This version and path verification are such a lengthy and careful process, I've overhauled it and moved it to a seperate "class".
#include "VersionVerification.iss"
//Collection of code blocks that are delegated an event and deal with it.
#include "DelegateCode.iss"
[Code]
procedure InitializeWizard();
var
PathValue: String;
ErrorCode: Integer;
Readme: String;
begin
Log('Initial setup is beginning...')
OriginalTypeComboChangedEvent := WizardForm.TypesCombo.OnChange
WizardForm.TypesCombo.OnChange := @TypesComboChange
OriginalResizeEvent := WizardForm.OnResize
WizardForm.OnResize := @OnResize
PresetFile := 'Custom.{#ShortName}Type'
SetBanner(nil)
Log('Done setting up some events and a variable...')
if (MsgBox(CustomMessage('ScamWarning') + #13#10#13#10 + CustomMessage('ReadmeRead'), mbConfirmation, MB_YESNO) = IDNO) then
begin
MsgBox(CustomMessage('ReadmeExit'), mbCriticalError, MB_OK)
if (ActiveLanguage = 'chinesesimplified') then readme := '{#ShortName}_Readme_Chinese.pdf' else readme := '{#ShortName}_Readme.pdf';
ExtractTemporaryFile(readme)
ShellExecAsOriginalUser('open', AddQuotes(ExpandConstant('{tmp}\' + readme)), '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode)
abort
end;
ChangeBannerButton := TNewButton.Create(WizardForm)
ChangeBannerButton.Parent := WizardForm.WizardBitmapImage2.Parent
ChangeBannerButton.Caption := '→'
ChangeBannerbutton.Left := 0
ChangeBannerbutton.Top := 0
ChangeBannerButton.Anchors := [akRight]
ChangeBannerButton.Width := 20
ChangeBannerButton.Height := 20
ChangeBannerButton.OnClick := @SetBanner
//Tries to find the path of the game via the registry and if it suceeds, pushes it to the value var.
if RegQueryStringValue(HKEY_CURRENT_USER, '{#JapRegistry}','InstallPath', PathValue) then
//Sets the wizard dir field to default to what is found in the registry
begin
WizardForm.DirEdit.Text := (PathValue)
end
else if RegQueryStringValue(HKEY_CURRENT_USER, '{#JapRegistryCR}','InstallPath', PathValue) then
begin
WizardForm.DirEdit.Text := (PathValue)
end
else if RegQueryStringValue(HKEY_CURRENT_USER, '{#EnglishRegistry}','InstallPath', PathValue) then
//Sets the wizard dir field to default to what is found in the registry if the JP path isn't found but the ENG path is.
begin
WizardForm.DirEdit.Text := (PathValue)
end
//Maybe CR is the key so just check it.
else if RegQueryStringValue(HKEY_CURRENT_USER, '{#EnglishRegistryCR}','InstallPath', PathValue) then
begin
WizardForm.DirEdit.Text := (PathValue)
end
//If no registry key is found, it will blank the field to force users to select their path.
else
begin
WizardForm.DirEdit.Text := ''
end;
end;
procedure CurPageChanged(const CurPageID: Integer);
var
Path: string;
begin
//Only run the code if wizard is on the components page
if (CurPageID <> wpSelectComponents) then
exit;
Path := ExpandConstant('{app}')
if IsCR then
MsgBox(CustomMessage('CRVersionAlert'), mbInformation, MB_OK);
if (GetIsEng(path) > 0) AND NOT EngDisable then
if (MsgBox(CustomMessage('EnglishVersionAlert') + #13#10#13#10 + CustomMessage('EnglishVersionCompatibility'), mbInformation, MB_YESNO) = IDYES) then
EngDisable := true;
FixComponents();
end;
function BackButtonClick(const CurPageID: Integer): Boolean;
begin
if (CurPageID <> wpSelectComponents) then
begin
result := true;
exit;
end;
if (MsgBox(CustomMessage('GameTypeChangedExit'), mbConfirmation, MB_YESNO) = IDYES) then
begin
Abort;
end;
end;
procedure InstallOps();
var
Path, OldInstallPath: String;
begin
Log('Beginning Install Ops!');
Path := ExpandConstant('{app}')
//Saves any custom selections to components on install.
if (CompareText(WizardSetupType(false),'custom') = 0) then
begin
while NOT SaveCustomPreset(path) do
begin
case SuppressibleMsgBox('We encountered an error while trying to save the custom preset...', mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
//Starts by removing the Read-Only flag if applicable.
if WizardIsTaskSelected('readonly') then
begin
WizardForm.StatusLabel.Caption := 'Removing read-only flags in the game directory! This can take a while...';
while NOT RemoveReadonlyRecursive(path) do
begin
case SuppressibleMsgBox('We encountered an error while trying to remove readonly from your application directory...', mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
//Will now begin the move old install to backup folder if task was selected.
if WizardIsTaskSelected('clean/moveold') then
begin
WizardForm.StatusLabel.Caption := 'Backing up old installations...';
OldInstallPath := AddBackSlash(path) + 'OldInstall'
while DirExists(OldInstallPath) AND NOT AppendToName(OldInstallPath, GetDateTimeString('ddddd.h.nn.ss', '.', '.')) do
begin
case SuppressibleMsgBox('Encountered an issue while attempting to rename OldInstall folder.', mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
while NOT MoveOld(path, ['']) do
begin
case SuppressibleMsgBox(CustomMessage('MoveOldExcep'), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
Log('Moving old mods...')
if WizardIsTaskSelected('clean/moveold/mods') then
begin
WizardForm.StatusLabel.Caption := 'Backing up old mods...';
while NOT MoveOldMod(path, ['{#ModDir}']) do
begin
case SuppressibleMsgBox(CustomMessage('MoveOldModExcep'), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
Log('Install ops done!')
end;
procedure PostInstallOps();
var
OldInstallPath, Path: String;
begin
Path := expandConstant('{app}');
HandleNutakuSerialization(path);
if WizardIsTaskSelected('clean/moveold/config') then
begin
WizardForm.StatusLabel.Caption := 'Copying configuration files back...';
while NOT MoveOldConfigBack(path) do
begin
case SuppressibleMsgBox('Encountered an issue while attempting to copy your old configs back...', mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
OldInstallPath := AddBackSlash(path) + 'OldInstall'
while DirExists(OldInstallPath) AND NOT AppendToName(OldInstallPath, GetDateTimeString('ddddd.h.nn.ss', '.', '.')) do
begin
case SuppressibleMsgBox(CustomMessage('CannotRenameOld'), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
if WizardIsTaskSelected('readonly') then
begin
WizardForm.StatusLabel.Caption := 'Removing readonly (again). This can take a while...';
while NOT RemoveReadonlyRecursive(path) do
begin
// Display a message box
case SuppressibleMsgBox('We encountered an error while trying to remove readonly from your application directory...', mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of
IDIGNORE: break;
IDABORT: abort;
end;
end;
end;
//Creates a little file to help ID versions only when some component is installed.
if (Length(WizardSelectedComponents(false)) <> 0) then
SaveStringToFile(AddBackSlash(path) + '{#ShortName}.ver','{#MyAppVersion}', False);
end;
procedure CurStepChanged(const CurStep: TSetupStep);
begin
case CurStep of
ssinstall: InstallOps();
ssPostInstall: PostInstallOps();
end;
end;
[/Code]