-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCSVparser.iss
319 lines (302 loc) · 10.1 KB
/
CSVparser.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
[Code]
function GetCompIndexByID(const ID: String): Integer;
var
i: Integer;
begin
Result := -1; // Default result if not found
if localInstallMode and not maintenanceMode then
begin
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
begin
if LocalCompsArray[i].ID = ID then
begin
Result := i;
Exit;
end;
end;
end
else if not localInstallMode and maintenanceMode then
begin
for i := 0 to GetArrayLength(MaintenanceCompsArray) - 1 do
begin
if MaintenanceCompsArray[i].ID = ID then
begin
Result := i;
Exit;
end;
end;
end else
begin
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if WebCompsArray[i].ID = ID then
begin
Result := i;
Exit;
end;
end;
end;
end;
// Given a .csv file, return an array of information corresponding to
// the data in the csv file.
function WebCSVToInfoArray(Filename: String): array of TWebComponentsInfo;
var
Rows: TArrayOfString;
RowValues: TStrings;
i: Integer;
begin
// Read the file at Filename and store the lines in Rows
if LoadStringsFromFile(Filename, Rows) then begin
// Match length of return array to number of rows
SetArrayLength(Result, GetArrayLength(Rows) - 2);
for i := 1 to GetArrayLength(Rows) - 2 do begin
// Separate values at commas
RowValues := SplitString(Rows[i + 1], ',');
with Result[i - 1] do begin
ID := RowValues[0];
Name := RowValues[1];
Version := RowValues[2];
URL := RowValues[3];
SHA256 := RowValues[4];
end;
end;
end else begin
SetArrayLength(Result, 0);
end;
end;
// Same as above, but tailored to use a different format
function MaintenanceCSVToInfoArray(Filename: String): array of TMaintenanceComponentsInfo;
var
Rows: TArrayOfString;
RowValues: TStrings;
i: Integer;
begin
// Read the file at Filename and store the lines in Rows
if LoadStringsFromFile(Filename, Rows) then begin
// Match length of return array to number of rows
SetArrayLength(Result, GetArrayLength(Rows) - 2);
for i := 1 to GetArrayLength(Rows) - 2 do begin
// Separate values at commas
RowValues := SplitString(Rows[i + 1], ',');
with Result[i - 1] do begin
try
ID := RowValues[0];
isInstalled := StrToBool(RowValues[1]);
Version := RowValues[2];
except
Log('user might have edited the maintenance .csv');
end;
end;
end;
end else begin
SetArrayLength(Result, 0);
end;
end;
// Same as above, but tailored to use a different format(2)
function LocalCSVToInfoArray(Filename: String): array of TLocalComponentsInfo;
var
Rows: TArrayOfString;
RowValues: TStrings;
i: Integer;
begin
// Read the file at Filename and store the lines in Rows
if LoadStringsFromFile(Filename, Rows) then begin
// Match length of return array to number of rows
SetArrayLength(Result, GetArrayLength(Rows) - 2);
for i := 1 to GetArrayLength(Rows) - 2 do begin
// Separate values at commas
RowValues := SplitString(Rows[i + 1], ',');
with Result[i - 1] do begin
ID := RowValues[0];
Name := RowValues[1];
fileName := RowValues[2];
Version := RowValues[3];
end;
end;
end else begin
SetArrayLength(Result, 0);
end;
end;
procedure CreateLocalCSV();
var
i: Integer;
begin
Log('# updating local csv');
SaveStringToFile(localDataDir('local_sh2ee.dat')
,'# SH2EE local csv' + #13#10 +
'id,name,fileName,version' + #13#10 +
'setup_tool,SH2:EE Setup Tool,SH2EEsetup.exe,' + ExpandConstant('{#INSTALLER_VER}') + #13#10,
False);
// Populate entries based on the local csv
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if not (WebCompsArray[i].id = 'setup_tool') then
begin
SaveStringToFile(localDataDir('local_sh2ee.dat')
,WebCompsArray[i].ID + ',' + WebCompsArray[i].Name + ',notDownloaded,' + '0.0' + #13#10,
True);
end;
end;
// Update entries
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if not (WebCompsArray[i].id = 'setup_tool') then
begin
if WizardForm.ComponentsList.Checked[i - 1] then
FileReplaceString(localDataDir('local_sh2ee.dat'), WebCompsArray[i].ID + ',' + WebCompsArray[i].Name + ',notDownloaded,' + '0.0'
,WebCompsArray[i].ID + ',' + WebCompsArray[i].Name + ',' + GetURLFilePart(WebCompsArray[i].URL) + ',' + WebCompsArray[i].Version);
end;
end;
end;
procedure UpdateMaintenanceCSV(recoverOnly: Boolean);
var
i: Integer;
compIndex: Integer;
begin
Log('# updating maintenance csv');
// Create fresh local .csv in the game's directory
if localInstallMode then
begin
SaveStringToFile(ExpandConstant('{app}\SH2EEsetup.dat')
,'# **DO NOT MODIFY THIS FILE!**' + #13#10 +
'id,isInstalled,version' + #13#10 +
'setup_tool,true,' + ExpandConstant('{#INSTALLER_VER}') + #13#10,
False);
end else
if maintenanceMode then
begin
SaveStringToFile(ExpandConstant('{src}\SH2EEsetup.dat')
,'# **DO NOT MODIFY THIS FILE!**' + #13#10 +
'id,isInstalled,version' + #13#10 +
'setup_tool,true,' + WebCompsArray[0].Version + #13#10,
False);
end else
begin
SaveStringToFile(ExpandConstant('{app}\SH2EEsetup.dat')
,'# **DO NOT MODIFY THIS FILE!**' + #13#10 +
'id,isInstalled,version' + #13#10 +
'setup_tool,true,' + WebCompsArray[0].Version + #13#10,
False);
end;
// Populate entries based on the local csv
if localInstallMode then
begin
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
begin
if not (LocalCompsArray[i].id = 'setup_tool') then
begin
SaveStringToFile(ExpandConstant('{app}\SH2EEsetup.dat')
,LocalCompsArray[i].ID + ',false,' + '0.0' + #13#10,
True);
end;
end;
end else
// Populate entries based on the web csv
begin
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if not (WebCompsArray[i].id = 'setup_tool') then
begin
if not maintenanceMode then
begin
SaveStringToFile(ExpandConstant('{app}\SH2EEsetup.dat')
,WebCompsArray[i].ID + ',false,' + '0.0' + #13#10,
True);
end else
begin
SaveStringToFile(ExpandConstant('{src}\SH2EEsetup.dat')
,WebCompsArray[i].ID + ',false,' + '0.0' + #13#10,
True);
// Re-save DSOAL's info if it exists, and we just wrote audio_pack
if (WebCompsArray[i].id = 'audio_pack') then
begin
compIndex := GetCompIndexByID('dsoal');
if compIndex > -1 then
begin
if MaintenanceCompsArray[compIndex].isInstalled then
begin
Log('# User has installed DSOAL in the past, keeping .csv entry');
SaveStringToFile(ExpandConstant('{src}\SH2EEsetup.dat')
,MaintenanceCompsArray[compIndex].ID + ',true,' + MaintenanceCompsArray[compIndex].Version + #13#10,
True);
end;
end;
end;
end;
end;
end;
end;
// Write version info and installation status using local csv
if localInstallMode then
begin
for i := 0 to GetArrayLength(LocalCompsArray) - 1 do
begin
if not (LocalCompsArray[i].id = 'setup_tool') then
begin
if WizardForm.ComponentsList.Checked[i - 1] then
FileReplaceString(ExpandConstant('{app}\SH2EEsetup.dat'), LocalCompsArray[i].ID + ',false,0.0', LocalCompsArray[i].ID + ',true,' + LocalCompsArray[i].Version);
end;
end;
end else
begin
// Write version info and installation status using web csv
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
// Rewrite existing local csv info
if maintenanceMode then
begin
try
begin
if MaintenanceCompsArray[compIndex].isInstalled then
FileReplaceString(ExpandConstant('{src}\SH2EEsetup.dat'), MaintenanceCompsArray[compIndex].ID + ',false,' + '0.0', MaintenanceCompsArray[compIndex].ID + ',true,' + MaintenanceCompsArray[compIndex].Version);
end;
except
Log('# Entry is missing from CSV.');
end;
end;
// If in maintenance mode, check for maintenance page's radio buttons
if maintenanceMode and not selfUpdateMode and not recoverOnly then
begin
// Write info from new selected components using wpSelectComponents' list box
if installRadioBtn.Checked or updateRadioBtn.Checked or updateMode then
begin
if WizardForm.ComponentsList.Checked[i - 1] then
FileReplaceString(ExpandConstant('{src}\SH2EEsetup.dat'), MaintenanceCompsArray[compIndex].ID + ',' + BoolToStr(MaintenanceCompsArray[compIndex].isInstalled) + ',' + MaintenanceCompsArray[compIndex].Version, WebCompsArray[i].ID + ',true,' + WebCompsArray[i].Version);
end;
end;
// If not in maintenance mode, use the default method
if not maintenanceMode then
begin
if WizardForm.ComponentsList.Checked[i - 1] then
FileReplaceString(ExpandConstant('{app}\SH2EEsetup.dat'), WebCompsArray[i].ID + ',false,0.0', WebCompsArray[i].ID + ',true,' + WebCompsArray[i].Version);
end;
end;
end;
end;
end;
end;
procedure UpdateMaintenanceCSV_SetupToolOnly();
var
i: Integer;
begin
for i := 0 to GetArrayLength(WebCompsArray) - 1 do
begin
if (WebCompsArray[i].id = 'setup_tool') then
begin
if maintenanceMode then
begin
try
Log('Updating Setup Tool''s version');
FileReplaceString(ExpandConstant('{src}\SH2EEsetup.dat'), MaintenanceCompsArray[i].ID + ',true,' + MaintenanceCompsArray[i].Version, MaintenanceCompsArray[i].ID + ',true,' + ExpandConstant('{#INSTALLER_VER}'));
except
Log('# Entry is missing from local CSV.');
end;
end;
end;
end;
end;