Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit a6ab203

Browse files
committed
Some refactoring
1 parent 13683bc commit a6ab203

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

ElixirWeb.iss

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ Source: "compiler:SetupLdr.e32"; DestDir: "{tmp}\_offlineinstaller"; Flags: dele
5353

5454
[Run]
5555
Filename: "powershell.exe"; Parameters: "-File {tmp}\extract-zip.ps1 {tmp}\Precompiled.zip {tmp}\_offlineinstaller\elixir"; Flags: waituntilterminated runhidden; StatusMsg: "Extracting precompiled package..."
56-
Filename: "{tmp}\_offlineinstaller\ISCC.exe"; Parameters: "/dElixirVersion={code:GetSelectedReleaseVersion} /dSkipPages /dNoCompression Elixir.iss"; WorkingDir: "{tmp}\_offlineinstaller"; Flags: waituntilterminated runhidden; StatusMsg: "Preparing Elixir installer..."
57-
Filename: "{tmp}\_offlineinstaller\Output\elixir-v{code:GetSelectedReleaseVersion}-setup.exe"; Flags: nowait; StatusMsg: "Running Elixir installer..."
56+
Filename: "{tmp}\_offlineinstaller\ISCC.exe"; Parameters: "/dElixirVersion={code:ConstGetTargetReleaseVersion} /dSkipPages /dNoCompression Elixir.iss"; WorkingDir: "{tmp}\_offlineinstaller"; Flags: waituntilterminated runhidden; StatusMsg: "Preparing Elixir installer..."
57+
Filename: "{tmp}\_offlineinstaller\Output\elixir-v{code:ConstGetTargetReleaseVersion}-setup.exe"; Flags: nowait; StatusMsg: "Running Elixir installer..."
5858

5959
[Code]
6060
type
@@ -64,6 +64,9 @@ var
6464
PSelInstallType: TInputOptionWizardPage;
6565
PSelRelease: TWizardPage;
6666
PSelReleaseListBox: TNewCheckListBox;
67+
68+
TargetRelease: TStrings;
69+
6770
i: Integer;
6871
_int: Integer;
6972
@@ -94,6 +97,26 @@ begin
9497
Result := SplitStringRec(Str, Delim, TStringList.Create);
9598
end;
9699
100+
function GetVersion(Release: TStrings): String;
101+
begin
102+
Result := Release[0];
103+
end;
104+
105+
function GetURL(Release: TStrings): String;
106+
begin
107+
Result := Release[1];
108+
end;
109+
110+
function IsPrerelease(Release: TStrings): Boolean;
111+
begin
112+
Result := (Release[2] = 'prerelease');
113+
end;
114+
115+
function IsCompatibleForInstall(Release: TStrings): Boolean;
116+
begin
117+
Result := (StrToInt(Release[3]) = {#COMPAT_MASK});
118+
end;
119+
97120
function CSVToStringTable(Filename: String): TStringTable;
98121
var
99122
Rows: TArrayOfString;
@@ -109,18 +132,24 @@ end;
109132
procedure PopulatePSelReleaseListBox(StringTable: TStringTable);
110133
var
111134
SelectFirst: Boolean;
135+
ReleaseDesc: String;
112136
begin
113137
PSelReleaseListBox.Items.Clear;
114138
SelectFirst := True;
115139
for i := 0 to GetArrayLength(StringTable) - 1 do begin
116-
if (StrToInt(StringTable[i][3]) = {#COMPAT_MASK}) then begin
117-
PSelReleaseListBox.AddRadioButton('Elixir version ' + StringTable[i][0], StringTable[i][2], 0, SelectFirst, True, StringTable[i]);
140+
if IsCompatibleForInstall(StringTable[i]) then begin
141+
if IsPrerelease(StringTable[i]) then begin
142+
ReleaseDesc := 'Prerelease';
143+
end else begin
144+
ReleaseDesc := 'Release';
145+
end;
146+
PSelReleaseListBox.AddRadioButton('Elixir version ' + GetVersion(StringTable[i]), ReleaseDesc, 0, SelectFirst, True, StringTable[i]);
118147
SelectFirst := False;
119148
end;
120149
end;
121150
end;
122151
123-
function GetSelectedReleaseValues(): TStrings;
152+
function GetListBoxSelectedRelease(): TStrings;
124153
begin
125154
for i := 0 to PSelReleaseListBox.Items.Count - 1 do begin
126155
if PSelReleaseListBox.Checked[i] then begin
@@ -130,14 +159,20 @@ begin
130159
end;
131160
end;
132161
133-
function GetSelectedReleaseVersion(Param: String): String;
162+
function GetListBoxLatestRelease(Prerelease: Boolean): TStrings;
134163
begin
135-
Result := GetSelectedReleaseValues[0];
164+
for i := 0 to PSelReleaseListBox.Items.Count - 1 do begin
165+
if Prerelease = IsPrerelease(TStrings(PSelReleaseListBox.ItemObject[i])) then begin
166+
Result := TStrings(PSelReleaseListBox.ItemObject[i]);
167+
break;
168+
end;
169+
end;
170+
Result := nil;
136171
end;
137172
138-
function GetSelectedReleaseURL(): String;
173+
function ConstGetTargetReleaseVersion(Param: String): String;
139174
begin
140-
Result := GetSelectedReleaseValues[1];
175+
Result := GetVersion(TargetRelease);
141176
end;
142177
143178
function ErlangIsInstalled: Boolean;
@@ -147,8 +182,8 @@ end;
147182
148183
procedure CurPageChanged(CurPageID: Integer);
149184
begin
150-
if CurPageID = wpReady then begin
151-
idpAddFile(GetSelectedReleaseURL, ExpandConstant('{tmp}\Precompiled.zip'));
185+
if CurPageID = wpPreparing then begin
186+
idpAddFile(GetURL(TargetRelease), ExpandConstant('{tmp}\Precompiled.zip'));
152187
idpDownloadAfter(wpPreparing);
153188
end;
154189
end;
@@ -177,6 +212,7 @@ begin
177212
PSelReleaseListBox.Parent := PSelRelease.Surface;
178213
179214
PopulatePSelReleaseListBox(CSVToStringTable(ExpandConstant('{tmp}\releases.csv')));
215+
TargetRelease := GetListBoxLatestRelease(False);
180216
end;
181217
182218
function InitializeSetup(): Boolean;

0 commit comments

Comments
 (0)