-
Notifications
You must be signed in to change notification settings - Fork 156
/
morse.iss
183 lines (159 loc) · 5.61 KB
/
morse.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
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Morse"
; #define MyAppVersion 1.4
#define MyAppPublisher "MORSE contributors"
#define MyAppURL "http://morse-simulator.github.io/"
#define MyAppExeName "morserun.exe"
[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={{D81B2EDA-1357-462E-96E4-B47B74701F7C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
LicenseFile=LICENSE
OutputBaseFilename=MorseSetup-{#MyAppVersion}
Compression=lzma
SolidCompression=yes
ChangesEnvironment=yes
ArchitecturesInstallIn64BitMode={#MyAppArch}
[InstallDelete]
Type: filesandordirs; Name: {pf}\{#MyAppName}
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
;Source: "{code:GetBlenderExe}"; DestDir: "{app}"; Flags: external
Source: ".\dist\morserun\morse.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: ".\dist\morserun\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{group}\Startup Examples"; Filename: "{app}\share\morse\examples"
Name: "{group}\Documentation"; Filename: "http://morse-simulator.github.io/"
;[Run]
;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait ;postinstall skipifsilent
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{app}"; \
Check: NeedsAddPath('{app}')
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueName: "PATH"; ValueData: "{app}"; Flags: uninsdeletevalue
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "MORSE_ROOT"; ValueData: "{code:GetShortRoot}"; Flags: uninsdeletevalue
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "MORSE_BLENDER"; ValueData: "{code:GetBlenderExe}"; Flags: uninsdeletevalue
;All this code ensures that Morse is put on the system path, and that path is removed when uninstalled
[Code]
var
BlenderFilePage: TInputFileWizardPage;
procedure InitializeWizard();
begin
BlenderFilePage :=
CreateInputFilePage(
wpSelectDir,
'Select Location of Blender Executable',
'Morse requires the Blender application (V2.78). Ensure Blender is installed before installing Morse',
'Select where the Blender executable is located (usually in the Blender install folder), then click Next.');
BlenderFilePage.Add(
'Location of blender.exe :',
'Blender exe|blender.exe|All files|*.*',
'.exe');
end;
function GetBlenderExe(Param: string): string;
begin
Result := GetShortName(BlenderFilePage.Values[0]);
end;
function GetShortRoot(Param: string): string;
begin
Result := GetShortName(ExpandConstant('{app}'));
end;
function NeedsAddPath(Param: string): boolean;
var
OrigPath: string;
begin
if not RegQueryStringValue(
HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'Path', OrigPath)
then begin
Result := True;
exit;
end;
{ look for the path with leading and trailing semicolon }
{ Pos() returns 0 if not found }
Result :=
(Pos(';' + UpperCase(Param) + ';', ';' + UpperCase(OrigPath) + ';') = 0) and
(Pos(';' + UpperCase(Param) + '\;', ';' + UpperCase(OrigPath) + ';') = 0);
end;
var
Paths: string;
const
EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
SMTO_ABORTIFHUNG = 2;
WM_WININICHANGE = $001A;
WM_SETTINGCHANGE = WM_WININICHANGE;
type
WPARAM = UINT_PTR;
LPARAM = INT_PTR;
LRESULT = INT_PTR;
function SendTextMessageTimeout(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: PAnsiChar; fuFlags: UINT;
uTimeout: UINT; out lpdwResult: DWORD): LRESULT;
external '[email protected] stdcall';
procedure SaveOldPath();
begin
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
begin
Log('PATH not found');
end else begin
Log(Format('Old Path saved as [%s]', [Paths]));
end;
end;
procedure RemovePath(Path: string);
var
P: Integer;
begin
Log(Format('Prepare to remove from Old PATH [%s]', [Paths]));
P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';');
if P = 0 then
begin
Log(Format('Path [%s] not found in PATH', [Path]));
end
else
begin
Delete(Paths, P - 1, Length(Path) + 1);
Log(Format('Path [%s] removed from PATH => [%s]', [Path, Paths]));
if RegWriteExpandStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
begin
Log('PATH written');
end
else
begin
Log('Error writing PATH');
end;
end;
end;
procedure RefreshEnvironment;
var
S: AnsiString;
MsgResult: DWORD;
begin
S := 'Environment';
SendTextMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
PAnsiChar(S), SMTO_ABORTIFHUNG, 5000, MsgResult);
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
SaveOldPath();
end;
if CurUninstallStep = usPostUninstall then
begin
RemovePath(ExpandConstant('{app}'));
RefreshEnvironment();
end;
end;