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

Commit 3f475a6

Browse files
committed
Move more code into separate files
1 parent 76b26fd commit 3f475a6

File tree

4 files changed

+120
-81
lines changed

4 files changed

+120
-81
lines changed

ElixirWeb.iss

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ Name: "erlpath"; Description: "Append Erlang directory to Path environment varia
7272
[Code]
7373
#include "src\util.iss"
7474
#include "src\elixir_release.iss"
75+
#include "src\elixir_lookup.iss"
7576
#include "src\erlang_data.iss"
77+
#include "src\erlang_env.iss"
7678
7779
var
7880
GlobalPageSelRelease: TInputOptionWizardPage;
@@ -83,8 +85,6 @@ var
8385
8486
CacheSelectedRelease: TElixirRelease;
8587
86-
_int: Integer;
87-
8888
function GetElixirCSVFilePath: String;
8989
begin
9090
Result := ExpandConstant('{tmp}\' + GetURLFilePart('{#ELIXIR_CSV_URL}'));
@@ -95,62 +95,10 @@ begin
9595
Result := ExpandConstant('{tmp}\' + GetURLFilePart('{#ERLANG_CSV_URL}'));
9696
end;
9797
98-
function GetErlangPath(Of64Bit: Boolean): String;
99-
var
100-
Versions: TArrayOfString;
101-
Path: String;
102-
KeyPath: String;
103-
begin
104-
Result := '';
105-
106-
if Of64Bit then begin
107-
KeyPath := 'SOFTWARE\Wow6432Node\Ericsson\Erlang';
108-
end else begin
109-
KeyPath := 'SOFTWARE\Ericsson\Erlang';
110-
end;
111-
112-
if RegGetSubkeyNames(HKEY_LOCAL_MACHINE, KeyPath, Versions) then begin
113-
if RegQueryStringValue(HKEY_LOCAL_MACHINE, KeyPath + '\' + GlobalErlangData.ERTSVersion, '', Path) then begin
114-
Result := Path;
115-
end else if RegQueryStringValue(HKEY_LOCAL_MACHINE, KeyPath + '\' + Versions[GetArrayLength(Versions) - 1], '', Path) then begin
116-
Result := Path;
117-
end;
118-
end;
119-
end;
120-
121-
function ErlangInPath: Boolean;
122-
begin
123-
Result := Exec('erl.exe', '+V', '', SW_HIDE, ewWaitUntilTerminated, _int);
124-
end;
125-
12698
procedure AppendErlangPathIfTaskSelected(Of64Bit: Boolean);
127-
var
128-
Path: String;
129-
RegValue: String;
13099
begin
131-
if IsTaskSelected('erlpath') then begin
132-
Path := GetErlangPath(Of64Bit);
133-
if not (Path = '') then begin
134-
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', RegValue);
135-
if Pos(Path, RegValue) = 0 then begin
136-
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', RegValue + ';' + Path + '\bin');
137-
end;
138-
end;
139-
end;
140-
end;
141-
142-
function FindSelectedRelease(ListBoxes: array of TNewCheckListBox; Releases: array of TElixirRelease): TElixirRelease;
143-
var
144-
i, j, k: Integer;
145-
begin
146-
for i := 0 to GetArrayLength(ListBoxes) - 1 do begin
147-
for j := 0 to ListBoxes[i].Items.Count - 1 do begin
148-
if ListBoxes[i].ItemObject[j] <> nil then begin
149-
Result := FindFirstReleaseMatchingRef(Releases, ListBoxes[i].ItemObject[j]);
150-
exit;
151-
end;
152-
end;
153-
end;
100+
if IsTaskSelected('erlpath') then
101+
AppendErlangPath(Of64Bit, GlobalErlangData.ERTSVersion);
154102
end;
155103
156104
procedure CurPageChanged(CurPageID: Integer);
@@ -234,7 +182,11 @@ begin
234182
end;
235183
236184
function CheckToInstallErlang: Boolean; begin
237-
Result := (not ErlangInPath) and ((GetErlangPath(False) = '') or (GetErlangPath(True) = '')); end;
185+
Result := (not ErlangInPath) and
186+
(
187+
(GetErlangPath(False, GlobalErlangData.ERTSVersion) = '') or
188+
(GetErlangPath(True, GlobalErlangData.ERTSVersion) = '' )
189+
); end;
238190
function CheckToAddErlangPath: Boolean; begin
239191
Result := not ErlangInPath; end;
240192

src/elixir_lookup.iss

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// elixir_lookup.iss - Functions for finding releases within TElixirRelease
2+
// arrays and other structures
3+
// Copyright 2014 Chris Hyndman
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
function FindFirstReleaseOfType(Releases: array of TElixirRelease; ReleaseType: TElixirReleaseType): TElixirRelease;
18+
var
19+
i: Integer;
20+
begin
21+
for i := 0 to GetArrayLength(Releases) - 1 do begin
22+
if Releases[i].ReleaseType = ReleaseType then begin
23+
Result := Releases[i];
24+
exit;
25+
end;
26+
end;
27+
end;
28+
29+
function FindFirstReleaseMatchingRef(Releases: array of TElixirRelease; RefMatch: TObject): TElixirRelease;
30+
var
31+
i: Integer;
32+
begin
33+
for i := 0 to GetArrayLength(Releases) - 1 do begin
34+
if Releases[i].Ref = RefMatch then begin
35+
Result := Releases[i];
36+
exit;
37+
end;
38+
end;
39+
end;
40+
41+
function FindSelectedRelease(ListBoxes: array of TNewCheckListBox; Releases: array of TElixirRelease): TElixirRelease;
42+
var
43+
i, j: Integer;
44+
begin
45+
for i := 0 to GetArrayLength(ListBoxes) - 1 do begin
46+
for j := 0 to ListBoxes[i].Items.Count - 1 do begin
47+
if ListBoxes[i].ItemObject[j] <> nil then begin
48+
Result := FindFirstReleaseMatchingRef(Releases, ListBoxes[i].ItemObject[j]);
49+
exit;
50+
end;
51+
end;
52+
end;
53+
end;

src/elixir_release.iss

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,3 @@ begin
103103
end
104104
end;
105105
end;
106-
107-
function FindFirstReleaseOfType(Releases: array of TElixirRelease; ReleaseType: TElixirReleaseType): TElixirRelease;
108-
var
109-
i: Integer;
110-
begin
111-
for i := 0 to GetArrayLength(Releases) - 1 do begin
112-
if Releases[i].ReleaseType = ReleaseType then begin
113-
Result := Releases[i];
114-
exit;
115-
end;
116-
end;
117-
end;
118-
119-
function FindFirstReleaseMatchingRef(Releases: array of TElixirRelease; RefMatch: TObject): TElixirRelease;
120-
var
121-
i: Integer;
122-
begin
123-
for i := 0 to GetArrayLength(Releases) - 1 do begin
124-
if Releases[i].Ref = RefMatch then begin
125-
Result := Releases[i];
126-
exit;
127-
end;
128-
end;
129-
end;

src/erlang_env.iss

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// erlang_env.iss - Functions relating to Erlang's environment properties
2+
// Copyright 2014 Chris Hyndman
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
function GetErlangPath(Of64Bit: Boolean; PrefVersion: String): String;
17+
var
18+
Versions: TArrayOfString;
19+
Path: String;
20+
KeyPath: String;
21+
begin
22+
Result := '';
23+
24+
if Of64Bit then begin
25+
KeyPath := 'SOFTWARE\Wow6432Node\Ericsson\Erlang';
26+
end else begin
27+
KeyPath := 'SOFTWARE\Ericsson\Erlang';
28+
end;
29+
30+
if RegGetSubkeyNames(HKEY_LOCAL_MACHINE, KeyPath, Versions) then begin
31+
if RegQueryStringValue(HKEY_LOCAL_MACHINE, KeyPath + '\' + PrefVersion, '', Path) then begin
32+
Result := Path;
33+
end else if RegQueryStringValue(HKEY_LOCAL_MACHINE, KeyPath + '\' + Versions[GetArrayLength(Versions) - 1], '', Path) then begin
34+
Result := Path;
35+
end;
36+
end;
37+
end;
38+
39+
function ErlangInPath: Boolean;
40+
var
41+
_int: Integer;
42+
begin
43+
Result := Exec('erl.exe', '+V', '', SW_HIDE, ewWaitUntilTerminated, _int);
44+
end;
45+
46+
procedure AppendErlangPath(Of64Bit: Boolean; PrefVersion: String);
47+
var
48+
Path: String;
49+
RegValue: String;
50+
begin
51+
Path := GetErlangPath(Of64Bit, PrefVersion);
52+
if not (Path = '') then begin
53+
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', RegValue);
54+
if Pos(Path, RegValue) = 0 then begin
55+
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', RegValue + ';' + Path + '\bin');
56+
end;
57+
end;
58+
end;

0 commit comments

Comments
 (0)