/
SoD_SP Inno.iss
307 lines (291 loc) · 12 KB
/
SoD_SP Inno.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
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "SoD_SP"
#define MyAppVersion "1.16.0"
#define MyAppPublisher "RoseKavalier"
[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={{1C590ED1-97FC-41C9-ADB4-9FED1C543099}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
UsePreviousAppDir=no
DefaultDirName={code:GetPathInstalled}
DisableDirPage=no
DisableWelcomePage=yes
OutputBaseFilename=SoD_SP 1.16.0
SetupIconFile=Images\SoD_SP+.ico
Compression=lzma
SolidCompression=yes
DisableStartupPrompt=yes
AppendDefaultDirName=no
InfoAfterFile=Changelog.txt
UsePreviousGroup=yes
AllowNoIcons=True
AppendDefaultGroupName=False
VersionInfoVersion=1.16.0
CreateUninstallRegKey=no
UninstallFilesDir={app}\_HD3_Data\Packs\SoD_SP\Uninstall
VersionInfoProductName=SoD_SP
WizardStyle=classic
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
[Files]
Source: "{app}\_HD3_Data\Packs\SoD_SP\SoD_SP.ini"; DestDir: "{app}\_HD3_Data\Packs\SoD_SP\"; DestName: "[BACKUP]SoD_SP.ini"; Flags: external skipifsourcedoesntexist
Source: "_HD3_Data\*"; DestDir: "{app}\_HD3_Data\"; Flags: ignoreversion recursesubdirs createallsubdirsSource: "Images\SODSP.bmp"; DestDir: "{app}"; Flags: dontcopy
[Messages]
WelcomeLabel2=This will install [name/ver] on your computer.
SelectDirLabel3=Please select your Heroes of Might and Magic III installation folder.
ReadyLabel1=Setup is now ready to begin installing [name/ver] on your computer.
SelectDirDesc=Where should [name/ver] be installed?
SetupAppTitle=Setup - SoD_SP 1.16.0
SetupWindowTitle=Setup - SoD_SP 1.16.0
WelcomeLabel1=Welcome to the [name/ver] Setup Wizard
ClickFinish=If you would like to automatically add SoD_SP to HDmod's plugin list, toggle the checkmark below and then click Finish.
InfoAfterLabel=When you are ready to continue, click Next.
InfoAfterClickLabel=Changelog for SoD_SP:
[Code]
{
* Global variables
}
var
{ the ID of the custom page with logo }
WelcomePageID: Integer;
{ the bitmap logo }
LogoBitmapImage: TBitmapImage;
{ custom page text }
WPStaticText1, WPStaticText2, WPStaticText3, LanguageText: TNewStaticText;
{ checkbox for Finished page to add pack }
CheckBox: TCheckBox;
RadioLanguage: TNewCheckListBox;
procedure CenterHInParent(Control: TControl);
{
* Centers item horizontally in page.
}
begin
if Assigned(Control) and Assigned(Control.Parent) then
begin
Control.Left := (Control.Parent.Width - Control.Width) div 2;
end;
end;
procedure InitializeWizard;
{
* This procedure creates a welcome page
* to show the SoD_SP logo (LogoBitmapImage)
* and some text underneath it.
* Additionally, it creates a checkbox
* on the wpFinished page which will
* prompt the user as to whether the plugin
* should be added to HDmod's list.
}
var
Finished, Page: TWizardPage;
V: String;
begin
Page := CreateCustomPage(wpWelcome, '', '');
WelcomePageID := Page.ID;
{ Create bitmap Logo }
LogoBitmapImage := TBitmapImage.Create(WizardForm);
ExtractTemporaryFile('SODSP.bmp');
LogoBitmapImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\SODSP.bmp'));
LogoBitmapImage.Top := 10;
LogoBitmapImage.AutoSize := True;
LogoBitmapImage.Cursor := crArrow;
LogoBitmapImage.Visible := False;
LogoBitmapImage.Parent := WizardForm.InnerPage;
CenterHInParent(LogoBitmapImage);
{ Create welcome text 1 }
WPStaticText1 := TNewStaticText.Create(Page);
WPStaticText1.Top := LogoBitmapImage.Top + LogoBitmapImage.Height + 30;
WPStaticText1.Caption := 'This setup wizard will install the';
WPStaticText1.AutoSize := True;
WPStaticText1.Parent := WizardForm;
WPStaticText1.Visible := True;
CenterHInParent(WPStaticText1);
{ Create welcome text 2 }
WPStaticText2 := TNewStaticText.Create(Page);
WPStaticText2.Top := WPStaticText1.Top + WPStaticText1.Height + 5;
WPStaticText2.Caption := 'HOMM3 plugin SoD_SP 1.16.0';
WPStaticText2.AutoSize := True;
WPStaticText2.Parent := WizardForm;
WPStaticText2.Font.Style := [fsBold];
WPStaticText2.Font.Color := clRed;
CenterHInParent(WPStaticText2);
{ Create welcome text 3 }
WPStaticText3 := TNewStaticText.Create(Page);
WPStaticText3.Top := WPStaticText2.Top + WPStaticText2.Height + 5;
WPStaticText3.Caption := 'on your computer.';
WPStaticText3.AutoSize := True;
WPStaticText3.Parent := WizardForm;
CenterHInParent(WPStaticText3);
{ Get Finished Page }
Finished:= PageFromID(wpFinished);
{ Create Checkbox for adding pack }
CheckBox := TCheckBox.Create(Finished);
CheckBox.Parent := Finished.Surface;
CheckBox.Caption := 'Add SoD_SP to packs.';
CheckBox.Checked := False;
CheckBox.Width := 200;
CheckBox.Top := 130;
CheckBox.Left := 176;
LanguageText := TNewStaticText.Create(Finished);
LanguageText.Top := CheckBox.Top + CheckBox.Height + 10;
LanguageText.Left := CheckBox.Left;
LanguageText.Parent := WizardForm;
LanguageText.AutoSize := True;
LanguageText.Caption := 'Select the language you would like to use in SoD_SP:';
LanguageText.Color := clWhite;
{ Create Language panel for SoD_SP.ini }
RadioLanguage := TNewCheckListBox.Create(Finished);
RadioLanguage.Parent := Finished.Surface;
RadioLanguage.Top := CheckBox.Top + CheckBox.Height + 30;
RadioLanguage.Width := 100;
RadioLanguage.Height := 85;
RadioLanguage.Left := CheckBox.Left;
RadioLanguage.AddRadioButton('English', '', 0, True, True, nil);
RadioLanguage.AddRadioButton('Pусский', '', 0, False, True, nil);
RadioLanguage.AddRadioButton('Deutsch', '', 0, False, True, nil);
RadioLanguage.AddRadioButton('Ελληνικά', '', 0, False, True, nil);
RadioLanguage.AddRadioButton('Polski', '', 0, False, True, nil);
end;
procedure CurPageChanged(CurPageID: Integer);
{
* This function shows data on our custom page
* and hides it elsewhere.
}
begin
WPStaticText1.Visible := CurPageID = WelcomePageID;
WPStaticText2.Visible := CurPageID = WelcomePageID;
WPStaticText3.Visible := CurPageID = WelcomePageID;
LogoBitmapImage.Visible := CurPageID = WelcomePageID;
WizardForm.Bevel1.Visible := CurPageID <> WelcomePageID;
WizardForm.MainPanel.Visible := CurPageID <> WelcomePageID;
WizardForm.InnerNotebook.Visible := CurPageID <> WelcomePageID;
LanguageText.Visible := CurPageID = wpFinished;
end;
function AddPack(const FileName: String): Boolean;
{
* This function opens the specified FileName (sod.ini).
* If successful, it parses the file to find the <Packs>
* entry and extracts that line's content.
* From this line, a search if made for the plugin name ("SoD_SP").
* If the plugin is already present, then return true.
* If not, we check if there's at least 1 other plugin ('=' is present)
* to determine what text needs to be inserted to correctly add
* the plugin. The string is then saved back to FileName.
}
var
rLen: Longint; { remaining length }
packsPos, lineEndPos: integer;
iniContent, packsLine, myPack: AnsiString;
begin
Result:= false;
if LoadStringFromFile(FileName, iniContent) then
begin
packsPos:= Pos('<Packs>', iniContent);
if packsPos > 0 then
begin
rLen:= Length(iniContent) - packsPos;
packsLine:= Copy(iniContent, packsPos, rLen);
{ look for line end \r\n }
lineEndPos:= Pos(#13#10, packsLine);
if lineEndPos > 0 then
begin
packsLine:= Copy(packsLine, 0, lineEndPos);
if Pos('"SoD_SP"', packsLine) = 0 then
begin
{ SoD_SP pack does not exist }
if Pos('=', packsLine) = 0 then
{ there is no pack }
myPack:= ' = "SoD_SP"'
else
{ there is at least one pack }
myPack:= ', "SoD_SP"';
{ insert myPack at end of <Packs> line }
Insert(myPack, iniContent, packsPos + lineEndPos - 1);
{ save back to FileName }
if SaveStringToFile(FileName, iniContent, false) then
Result:= true;
end
else
{ Pack is already there }
Result:= true;
end;
end;
end;
end;
function GetPathInstalled (Param: String): String;
{
* This functions looks in registry to find
* the known default installation keys.
* Upon failure, it instead uses default path
* 'C:\Heroes3'.
}
var
path: String;
begin
if RegQueryStringValue(HKLM, 'SOFTWARE\WOW6432Node\New World Computing\Heroes of Might and Magic® III\1.0\', 'AppPath', path) then
Result:= path
else if RegQueryStringValue(HKCU, 'SOFTWARE\WOW6432Node\New World Computing\Heroes of Might and Magic® III\1.0\', 'AppPath', path) then
Result:= path
else if RegQueryStringValue(HKLM, 'SOFTWARE\New World Computing\Heroes of Might and Magic® III\1.0\', 'AppPath', path) then
Result:= path
else if RegQueryStringValue(HKCU, 'SOFTWARE\New World Computing\Heroes of Might and Magic® III\1.0\', 'AppPath', path) then
Result:= path
else
Result:= 'C:\Heroes3' { Default path if not found }
end;
function NextButtonClick(CurPageID: Integer): Boolean;
{
* This function triggers on button click.
* If the page id is wpFinished
* (i.e. the last page and we're clicking 'Finish')
* then it will check if the user requested for the plugin
* to be added to HDmod packs list.
* If so, it then runs AddPack() to automatically add it.
* If it fails, a popup message is shown prompting
* the user to add the plugin manually.
* Also used to clear some pre-1.16.0 files
* and to set chosen SoD_SP language.
}
var
IniPath, OldData, OldLanguage, iniSODSP, entry : String;
selectedLang, i : Integer;
begin
Result:= true;
if CurPageID = wpFinished then
begin
if CheckBox.State then { CheckBox is global }
begin
IniPath := WizardDirValue + '\_HD3_Data\Settings\sod.ini';
if AddPack(IniPath) = false then
MsgBox('The plugin could not be added automatically.'#13#10'Please add it manually.', mbError, MB_OK);
end;
OldData := WizardDirValue + '\_HD3_Data\Packs\SoD_SP\Data';
if DirExists(OldData) then
DelTree(OldData, true, true, true);
OldLanguage := WizardDirValue + '\_HD3_Data\Packs\SoD_SP\Language';
if DirExists(OldLanguage) then
DelTree(OldLanguage, true, true, true);
{ Default language is English }
selectedLang := 0;
for i := 1 to 4 do
begin
if RadioLanguage.Checked[i] then
begin
selectedLang := i;
Break;
end;
end;
entry := ' ' + IntToStr(selectedLang);
iniSODSP := WizardDirValue + '\_HD3_Data\Packs\SoD_SP\SoD_SP.ini';
SetIniString('language', 'SoD_SPLanguage', entry, iniSODSP);
end;
end;