-
Notifications
You must be signed in to change notification settings - Fork 4
/
VersionVerification.iss
/
VersionVerification.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
[Code]
//Calls for function that facilitate version checking from C# DLL
function VersionCheck(const path: WideString; const gver: Integer): Integer;
external 'CMIHelper@files:CMIHelper.dll stdcall delayload';
Function VerifyPath(const DirName: String): Boolean;
begin
//the result is intially true. If none of the checks are met, it passes true back. However, if any checks are met, it flips the switch to false but still does every other check. This is meant to point out all issues in a setup first run instead of forcing users to run multiple times a new issue crops up.
result := true;
EmptyFolder:= false;
//Due to INNOs cancer code. I've been splitting checks into code blocks to improve readability.
if FileExists(DirName + '{#WrongTarget}') then
begin
MsgBox(CustomMessage('CMDetected'), mbCriticalError, MB_OK)
result := false
exit;
end;
if (FileExists(DirName + '{#TargetApp}') = false) then
begin
if MsgBox(CustomMessage('NotaGameDir'), mbConfirmation, MB_YESNO) = IDYES then
begin
EmptyFolder := true;
result := true;
exit;
end;
result := false;
exit;
end;
//Quits if the users are found to have updated their game incorrectly. This should help bring more awareness to incorrect updating and stop people from blaming CMI if they update incorrectly and then install CMI.
if (FileExists(DirName + '\update.exe')) OR (FileExists(DirName + '\selector.exe')) OR (DirExists(DirName + '\data')) then
begin
MsgBox(CustomMessage('ImproperUpdate'), mbCriticalError, MB_OK)
result := false;
end;
if StringContains(DirName, 'Downloads') then
begin
MsgBox(CustomMessage('IsInDownloads'), mbCriticalError, MB_OK)
result := false
end;
if (StringContains(DirName, 'Program Files') = True) AND (StringContains(DirName, 'Steam') = False) then
begin
MsgBox(CustomMessage('IsInProgramFiles'), mbCriticalError, MB_OK)
result := false
end;
#if LMMT == false
//Checks if the game is not INM version. If it's not, installation continues.
if IsEng(DirName) = 2 then
begin
MsgBox(CustomMessage('IsINM'), mbCriticalError, MB_OK);
result := false;
end;
#endif
if FileExists(DirName + '\update.lst') = false AND FileExists(DirName + '{#TargetApp}') then
begin
MsgBox(CustomMessage('MissingUpdateLst'), mbCriticalError, MB_OK);
result := false;
end;
end;
function VersionFetch(const File: string; out version: Integer; const LineToFetch: String): Boolean;
var
i: Integer;
s: array of string;
line: string;
begin
i := 0;
if (FileExists(File) = false) then
begin
result := false;
exit;
end;
if LoadStringsFromFile(File, s) = false then
begin
MsgBox(FmtMessage(CustomMessage('VersionFetchLoadFail'), File), mbCriticalError, MB_OK);
result := false;
exit;
end;
while (GetArrayLength(s) > i) AND (StringContains(s[i], LineToFetch) = false) do
begin
i := i+1
end;
if (i = GetArrayLength(s)) OR (StringContains(s[i], LineToFetch) = false) then
begin
MsgBox(FmtMessage(CustomMessage('VersionFetchNoVersion'), [LineToFetch]), mbCriticalError, MB_OK);
result := false;
exit;
end;
line := s[i];
if StringChangeEx(line, LineToFetch + ',', '', true) <= 0 then
begin
MsgBox(CustomMessage('VersionFetchLineCleanFail'), mbCriticalError, MB_OK);
result := false
exit;
end;
version := StrToIntDef(line, 0);
if (version = 0) then
begin
MsgBox(CustomMessage('VersionFetchParseFail'), mbCriticalError, MB_OK);
result := false
exit;
end;
result := true;
end;
procedure DownloadUpdate(const MinVer: Integer; const MaxVer: Integer; const Dir: String);
var
i : Integer;
pointversion : Integer;
SiteSt: String;
site : String;
ErrorCode: Integer;
VersionString: String;
begin
if MsgBox(CustomMessage('UpdatePrompt'), mbInformation, MB_YESNO) = MrNO then
begin
#if LMMT == false
if (IsEng(Dir)) = 0 then
begin
ShellExec('open', '{#UpdateSite1}', '', '', SW_SHOW, ewNoWait, ErrorCode);
end
else
begin
ShellExec('open', '{#UpdateSite2}', '', '', SW_SHOW, ewNoWait, ErrorCode);
end;
#else
ShellExec('open', '{#UpdateSite1}', '', '', SW_SHOW, ewNoWait, ErrorCode);
#endif
exit;
end;
#if LMMT == false
if (IsEng(Dir)) = 1 then
begin
i := MinVer/10+100;
SiteSt := ExpandConstant('{#UpdateFetch2}{#UpdateFile}')
end else
begin
i := MinVer/10+100;
SiteST := ExpandConstant('{#UpdateFetch1}{#UpdateFile}')
end;
#else
i := MinVer/10+10;
SiteSt := ExpandConstant('{#UpdateFetch1}{#UpdateFile}')
#endif
while (i >= MinVer/10) AND (Length(site) <= 0) do
begin
#if LMMT == false
if (i >= MaxVer/10) then
begin
i := i-1;
continue;
end;
#endif
Log('Testing: ' + Format(SiteSt, [IntToStr(i), BitString, '.zip']));
if (SiteValid(Format(SiteSt, [IntToStr(i), BitString, '.zip'])) = true) then
begin
pointversion:= 10;
while pointversion > 0 do
begin
Log('Testing point: ' + Format(SiteSt, [IntToStr(i)+ '.' + IntToStr(pointversion), BitString, '.zip']));
if (SiteValid(Format(SiteSt, [IntToStr(i)+ '.' + IntToStr(pointversion), BitString, '.zip'])) = true) AND (i*10 + pointversion > MinVer) then
begin
site := Format(SiteSt, [IntToStr(i)+ '.' + IntToStr(pointversion), BitString, '.zip'])
VersionString := IntToStr(i) + '.' + IntToStr(pointversion);
break;
end
else if (i*10 > MinVer) then
begin
site := Format(SiteSt, [IntToStr(i), BitString, '.zip']);
VersionString := IntToStr(i);
end;
pointversion := pointversion-1;
end;
Log(site + ' as latest');
end;
i := i-1;
end;
if (CompareText(site,'') = 0) AND (Length(site) <= 0) then
begin
MsgBox(CustomMessage('UpdateFetchFail'), mbCriticalError, MB_OK)
exit;
end;
DownloadPage.Clear;
DownloadPage.Show;
if (FileExists(ExpandConstant('{tmp}\COMUpdate.zip')) = false) AND (DirExists(ExpandConstant('{tmp}\COMUpdate')) = false) then
DownloadPage.Add(site, 'COMUpdate.zip', '');
try
try
DownloadPage.Download;
except
//SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
end;
finally
end;
if (DirExists(ExpandConstant('{tmp}\COMUpdate')) = false) then
begin
DoUnZip(ExpandConstant('{tmp}\COMUpdate.zip'),ExpandConstant('{tmp}\COMUpdate'));
end;
shellExec('', ExpandConstant('{tmp}\COMUpdate\' + Format('{#UpdateFile}', [VersionString, BitString, '']) +'\update.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
DownloadPage.Hide;
end;
function VerifyVersion(const Dir: String; const MinimumVersion: Integer; const UnsupportedVersion: Integer): Boolean;
var
Version: Integer;
LineTarget: String;
begin
if (EmptyFolder = false) then
begin
if(VersionFetch(WizardForm.DirEdit.Text + '\update.lst', Version, Format('{#Assembly}', [BitString]))) then
begin
if (Version < MinimumVersion) then
begin
#if LMMT == false
if (IsCR) AND (Version < UnsupportedVersion)then
begin
MsgBox(FmtMessage(CustomMessage('GameUnsupported1'),[IntToStr(UnsupportedVersion), IntToStr(Version) + ' ' + bitString]), mbCriticalError, MB_OK);
Result := false;
exit;
end;
#endif
MsgBox(FmtMessage(CustomMessage('GameOutdated'),[IntToStr(MinimumVersion), IntToStr(Version) + ' ' + bitString]), mbCriticalError, MB_OK);
#if LMMT == false
if (IsEng(Dir) = 1)then
begin
VersionFetch(Dir + '\update.lst', Version, '{#TargetApp}')
end;
#endif
DownloadUpdate(Version, UnsupportedVersion, Dir);
Result := false;
exit;
end;
#if LMMT == false
if NOT (IsCR) AND (Version >= UnsupportedVersion) then
begin
MsgBox(FmtMessage(CustomMessage('GameUnsupported'),[IntToStr(UnsupportedVersion),IntToStr(Version)]), mbCriticalError, MB_OK);
Result := false;
exit;
end;
#endif
result := true;
end
else begin
Result := false;
exit;
end
end;
end;
function NextButtonClick(const CurPageID: Integer): Boolean;
var
FreeSpace1, TotalSpace1: Cardinal;
begin
//Prevents code from running if not on the directory selection page
if CurPageID <> wpSelectDir then
begin
result := true
exit;
end;
//MsgBox('Found Space: ' + IntToStr(FreeSpace1), mbCriticalError, MB_OK)
if (GetSpaceOnDisk(WizardForm.DirEdit.Text, True, FreeSpace1, TotalSpace1)) and (FreeSpace1 < 5000) then
begin
MsgBox(FmtMessage(CustomMessage('StorageSpaceLow2'),IntToStr(FreeSpace1)), mbCriticalError, MB_OK)
Result := false;
exit;
end;
if VerifyPath(WizardForm.DirEdit.Text) = false then
begin
Result := false;
exit;
end;
#if LMMT == true
log('Now noting the bits down...')
NoteBits(WizardForm.DirEdit.Text);
#endif
if (EmptyFolder = false) AND (VerifyVersion(WizardForm.DirEdit.Text, MinimumVersion, {#UnsupportedVersion}) = false) then
begin
Result := false;
exit;
end;
//MsgBox('We should be returning true', mbInformation, MB_OK);
//Small advisory, hope users follow it.
MsgBox(CustomMessage('EnsureGameClosed'), mbInformation, MB_OK);
Result := true
end;
[/Code]