Repository navigation
Expand file tree
/
Copy pathMorganSetup.iss
More file actions
381 lines (350 loc) · 16.2 KB
/
Copy pathMorganSetup.iss
File metadata and controls
381 lines (350 loc) · 16.2 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#ifndef MorganSourceDir
#define MorganSourceDir "C:\Morgan"
#endif
#ifndef MorganVersion
#define MorganVersion GetStringFileInfo(MorganSourceDir + "\Morgan.exe", "ProductVersion")
#endif
#ifndef MorganRepositoryDir
#define MorganRepositoryDir SourcePath
#endif
[Setup]
AppId={{EFC7E428-7C68-4FF5-A608-C737BD547853}
AppName=Morgan
AppVersion={#MorganVersion}
AppPublisher=Nullbyte
DefaultDirName=C:\Morgan
DisableDirPage=no
DisableProgramGroupPage=yes
PrivilegesRequired=lowest
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
MinVersion=10.0
ChangesEnvironment=yes
SetupLogging=yes
OutputDir=build\installer
OutputBaseFilename=MorganSetup
Compression=lzma2/ultra64
SolidCompression=yes
WizardStyle=modern
SetupIconFile=assets\morgan.ico
UninstallDisplayIcon={app}\Morgan.exe
LicenseFile=LICENSE
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "Create a desktop shortcut"; Flags: unchecked
Name: "hotkey"; Description: "Launch with the Ctrl+Alt+M hotkey"
[Files]
Source: "{#MorganSourceDir}\Morgan.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MorganSourceDir}\_internal\*"; DestDir: "{app}\_internal"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "LICENSE"; DestDir: "{app}"; Flags: ignoreversion
Source: "licenses\*"; DestDir: "{app}\licenses"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "scripts\morgan-services.ps1"; DestDir: "{app}\scripts"; Flags: ignoreversion
Source: "scripts\morgan-hotkey.ps1"; DestDir: "{app}\scripts"; Flags: ignoreversion
Source: "src\__init__.py"; DestDir: "{app}\src"; Flags: ignoreversion
Source: "src\init\__init__.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\attachments.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\config.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\identity.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\lang.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\speech_text.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\subtitle_timing.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\tts_server.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_client.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_ipc.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_naturalness.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_profiles.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_prosody.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\voice_service.py"; DestDir: "{app}\src\init"; Flags: ignoreversion
Source: "src\init\locales\*"; DestDir: "{app}\src\init\locales"; Flags: ignoreversion
Source: "src\platforms\__init__.py"; DestDir: "{app}\src\platforms"; Flags: ignoreversion
Source: "src\platforms\base.py"; DestDir: "{app}\src\platforms"; Flags: ignoreversion
Source: "src\platforms\winx64\*.py"; DestDir: "{app}\src\platforms\winx64"; Flags: ignoreversion
Source: "src\cosyvoice\*"; DestDir: "{app}\src\cosyvoice"; Excludes: "__pycache__"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "src\third_party\Matcha-TTS\*"; DestDir: "{app}\src\third_party\Matcha-TTS"; Excludes: "__pycache__"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "src\voices\*"; DestDir: "{app}\src\voices"; Flags: ignoreversion
Source: "scripts\setup-runtime.ps1"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Registry]
Root: HKCU; Subkey: "Environment"; ValueType: string; ValueName: "{code:GetEnvironmentPrefix}"; ValueData: "{app}"
Root: HKCU; Subkey: "Environment"; ValueType: string; ValueName: "ASSISTANT_NAME"; ValueData: "{code:GetAssistantName}"
Root: HKCU; Subkey: "Environment"; ValueType: string; ValueName: "{code:GetEnvironmentPrefix}_HOME"; ValueData: "{code:GetRepositoryScripts}"; Check: HasMorganRepository
Root: HKCU; Subkey: "Software\Morgan\Installer"; ValueType: string; ValueName: "AssistantName"; ValueData: "{code:GetAssistantName}"; Flags: uninsdeletevalue uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\Morgan\Installer"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Flags: uninsdeletevalue uninsdeletekeyifempty
[InstallDelete]
Type: filesandordirs; Name: "{app}\tui"
Type: files; Name: "{app}\MorganTUI.exe"
Type: files; Name: "{autoprograms}\{code:GetAssistantName} Terminal.lnk"
Type: filesandordirs; Name: "{app}\src\init"
Type: filesandordirs; Name: "{app}\dev"
[UninstallDelete]
Type: filesandordirs; Name: "{app}\.venv"
Type: filesandordirs; Name: "{app}\src"
[Icons]
Name: "{autoprograms}\{code:GetAssistantName}"; Filename: "{app}\Morgan.exe"; WorkingDir: "{app}"
Name: "{autodesktop}\{code:GetAssistantName}"; Filename: "{app}\Morgan.exe"; WorkingDir: "{app}"; Tasks: desktopicon
[Code]
var
AssistantPage: TInputQueryWizardPage;
BashPath: String;
PreviousAssistantName: String;
PreviousInstallPath: String;
UninstallPrefix: String;
UninstallPath: String;
function GetAssistantName(Param: String): String;
begin
Result := Trim(AssistantPage.Values[0]);
end;
function GetEnvironmentPrefix(Param: String): String;
begin
Result := Uppercase(GetAssistantName(''));
end;
function IsCustomAssistantName: Boolean;
begin
Result := CompareText(GetAssistantName(''), 'Morgan') <> 0;
end;
function AssistantNameError: String;
var
Name: String;
Prefix: String;
Index: Integer;
HasAlphanumeric: Boolean;
begin
Result := '';
Name := GetAssistantName('');
HasAlphanumeric := False;
if (Length(Name) < 1) or (Length(Name) > 80) then
Result := 'The name must contain between 1 and 80 characters.'
else begin
for Index := 1 to Length(Name) do begin
if ((Name[Index] >= 'A') and (Name[Index] <= 'Z')) or
((Name[Index] >= 'a') and (Name[Index] <= 'z')) or
((Name[Index] >= '0') and (Name[Index] <= '9')) then
HasAlphanumeric := True;
if not (((Name[Index] >= 'A') and (Name[Index] <= 'Z')) or
((Name[Index] >= 'a') and (Name[Index] <= 'z')) or
(Name[Index] = '_') or
((Index > 1) and (Name[Index] >= '0') and (Name[Index] <= '9'))) then
Result := 'Use ASCII letters, digits and underscores; start with a letter or an underscore.';
end;
if not HasAlphanumeric then
Result := 'The name must include at least one letter or digit.';
Prefix := GetEnvironmentPrefix('');
if Pos('|' + Prefix + '|',
'|ALLUSERSPROFILE|APPDATA|BASH_ENV|COMMONPROGRAMFILES|COMPUTERNAME|COMSPEC|ENV|GIT_INSTALL_ROOT|HOME|HOMEDRIVE|HOMEPATH|LOCALAPPDATA|LOGONSERVER|NUMBER_OF_PROCESSORS|OS|PATH|PATHEXT|PROCESSOR_ARCHITECTURE|PROCESSOR_IDENTIFIER|PROGRAMDATA|PROGRAMFILES|PSMODULEPATH|PYTHONHOME|PYTHONPATH|SHELL|SYSTEMDRIVE|SYSTEMROOT|TEMP|TMP|USERDOMAIN|USERNAME|USERPROFILE|WINDIR|') > 0 then
Result := 'That name is reserved for a system environment variable. Choose another name.';
end;
end;
procedure InitializeWizard;
begin
RegQueryStringValue(HKCU, 'Software\Morgan\Installer', 'AssistantName', PreviousAssistantName);
RegQueryStringValue(HKCU, 'Software\Morgan\Installer', 'InstallPath', PreviousInstallPath);
AssistantPage := CreateInputQueryPage(wpSelectDir,
'Assistant name', 'Customize the assistant and its environment variables.',
'This name will be saved in the application settings and names the data folder (.name in your user profile). Morgan creates MORGAN and MORGAN_HOME; Luna creates LUNA and LUNA_HOME. The first variable points to the installation folder. The second is only created when a cloned Morgan repository is found and points to its scripts folder.');
AssistantPage.Add('Assistant name:', False);
AssistantPage.Values[0] := ExpandConstant('{param:ASSISTANTNAME|' + GetPreviousData('AssistantName', 'Morgan') + '}');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
Error: String;
begin
Result := True;
if CurPageID = AssistantPage.ID then begin
Error := AssistantNameError;
Result := Error = '';
if not Result then
MsgBox(Error, mbError, MB_OK);
end;
end;
procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
SetPreviousData(PreviousDataKey, 'AssistantName', GetAssistantName(''));
end;
function BashUnder(GitDirectory: String): String;
begin
Result := '';
if FileExists(AddBackslash(GitDirectory) + 'cmd\git.exe') and
FileExists(AddBackslash(GitDirectory) + 'bin\bash.exe') then
Result := AddBackslash(GitDirectory) + 'bin\bash.exe';
end;
function FindGitBash: String;
var
Directory: String;
GitPath: String;
begin
Result := '';
if RegQueryStringValue(HKCU, 'Software\GitForWindows', 'InstallPath', Directory) then
Result := BashUnder(Directory);
if (Result = '') and RegQueryStringValue(HKLM64, 'Software\GitForWindows', 'InstallPath', Directory) then
Result := BashUnder(Directory);
if (Result = '') and RegQueryStringValue(HKLM32, 'Software\GitForWindows', 'InstallPath', Directory) then
Result := BashUnder(Directory);
if Result = '' then
Result := BashUnder(ExpandConstant('{localappdata}\Programs\Git'));
if Result = '' then
Result := BashUnder(ExpandConstant('{commonpf64}\Git'));
if Result = '' then
Result := BashUnder(ExpandConstant('{commonpf32}\Git'));
if Result = '' then begin
GitPath := FileSearch('git.exe', GetEnv('PATH'));
if GitPath <> '' then
Result := BashUnder(ExtractFileDir(ExtractFileDir(GitPath)));
end;
end;
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
Winget: String;
ResultCode: Integer;
begin
Result := AssistantNameError;
if Result <> '' then
Exit;
BashPath := FindGitBash;
if BashPath <> '' then
Exit;
Winget := FileSearch('winget.exe', GetEnv('PATH'));
if Winget = '' then
Winget := ExpandConstant('{localappdata}\Microsoft\WindowsApps\winget.exe');
if not FileExists(Winget) then begin
Result := 'Install Git for Windows (including Git Bash) or WinGet, then run this installer again.';
Exit;
end;
WizardForm.StatusLabel.Caption := 'Installing Git for Windows to run install.sh...';
if not Exec(Winget,
'install --id Git.Git --exact --source winget --silent --accept-package-agreements --accept-source-agreements --disable-interactivity',
'', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
Result := 'Could not run WinGet: ' + SysErrorMessage(ResultCode);
Exit;
end;
if ResultCode <> 0 then begin
Result := 'Git installation failed with exit code ' + IntToStr(ResultCode) + '.';
Exit;
end;
BashPath := FindGitBash;
if BashPath = '' then
Result := 'Git Bash could not be found after installing Git for Windows.';
end;
procedure DependencyOutput(const Line: String; const Error, FirstLine: Boolean);
begin
Log(Line);
if (not Error) and (Trim(Line) <> '') then
WizardForm.StatusLabel.Caption := Copy(Line, 1, 180);
end;
procedure DeleteEnvironmentIfMatching(Name, ExpectedValue: String);
var
Value: String;
begin
if RegQueryStringValue(HKCU, 'Environment', Name, Value) and
(CompareText(Value, ExpectedValue) = 0) then
RegDeleteValue(HKCU, 'Environment', Name);
end;
function IsMorganRepository(Directory: String): Boolean;
begin
Directory := RemoveBackslashUnlessRoot(Trim(Directory));
Result := (Directory <> '') and
(DirExists(Directory + '\.git') or FileExists(Directory + '\.git')) and
FileExists(Directory + '\scripts\morgan-services.ps1') and
FileExists(Directory + '\src\init\core.py');
end;
function RepositoryFromHome(Name: String): String;
var
Value: String;
begin
Result := '';
if RegQueryStringValue(HKCU, 'Environment', Name, Value) then begin
Value := RemoveBackslashUnlessRoot(Trim(Value));
if (CompareText(ExtractFileName(Value), 'scripts') = 0) and
IsMorganRepository(ExtractFileDir(Value)) then
Result := ExtractFileDir(Value);
end;
end;
function FindMorganRepository: String;
begin
Result := RepositoryFromHome(GetEnvironmentPrefix('') + '_HOME');
if Result = '' then
Result := RepositoryFromHome('MORGAN_HOME');
if (Result = '') and IsMorganRepository('{#MorganRepositoryDir}') then
Result := RemoveBackslashUnlessRoot('{#MorganRepositoryDir}');
end;
function HasMorganRepository: Boolean;
begin
Result := FindMorganRepository <> '';
end;
function GetRepositoryScripts(Param: String): String;
begin
Result := AddBackslash(FindMorganRepository) + 'scripts';
end;
function GetRuntimeSwitches(Param: String): String;
begin
if HasMorganRepository then
Result := ' -SkipVoiceRuntime'
else
Result := '';
end;
procedure PrepareRuntime;
var
Parameters: String;
ResultCode: Integer;
begin
WizardForm.StatusLabel.Caption := 'Preparing ' + GetAssistantName('') + ' runtime...';
Parameters := '-NoProfile -ExecutionPolicy Bypass -File "' + ExpandConstant('{tmp}\setup-runtime.ps1') +
'" -InstallDir "' + ExpandConstant('{app}') + '" -AssistantName "' + GetAssistantName('') + '"' +
GetRuntimeSwitches('');
if not Exec('powershell.exe', Parameters, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
Log('Could not start the runtime setup: ' + SysErrorMessage(ResultCode));
MsgBox('The ' + GetAssistantName('') + ' runtime could not be prepared: ' + SysErrorMessage(ResultCode) + #13#10#13#10 +
'Run this installer again to retry.', mbError, MB_OK);
end else if ResultCode <> 0 then begin
Log('The runtime setup failed with exit code ' + IntToStr(ResultCode) + '.');
MsgBox('The ' + GetAssistantName('') + ' runtime setup did not finish (exit code ' + IntToStr(ResultCode) + ').' + #13#10#13#10 +
GetAssistantName('') + ' will not start its local services until it completes. ' +
'Check your internet connection and run this installer again to resume.', mbError, MB_OK);
end;
end;
procedure BindHotkey;
var
Parameters: String;
ResultCode: Integer;
begin
Parameters := '-NoProfile -ExecutionPolicy Bypass -File "' + ExpandConstant('{app}\scripts\morgan-hotkey.ps1') +
'" -InstallDir "' + ExpandConstant('{app}') + '" -AssistantName "' + GetAssistantName('') + '"';
if (not Exec('powershell.exe', Parameters, '', SW_HIDE, ewWaitUntilTerminated, ResultCode)) or (ResultCode <> 0) then
Log('The hotkey could not be bound (exit code ' + IntToStr(ResultCode) + ').');
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssPostInstall) and WizardIsTaskSelected('hotkey') then
BindHotkey;
if CurStep = ssPostInstall then begin
if HasMorganRepository then
Log('Morgan repository found: ' + GetRepositoryScripts(''))
else begin
Log('No cloned Morgan repository found; ' + GetEnvironmentPrefix('') + '_HOME is not configured.');
DeleteEnvironmentIfMatching(GetEnvironmentPrefix('') + '_HOME', ExpandConstant('{app}\scripts'));
end;
end;
if (CurStep = ssPostInstall) and (PreviousAssistantName <> '') and
(PreviousInstallPath <> '') and
(CompareText(PreviousAssistantName, GetAssistantName('')) <> 0) then begin
DeleteEnvironmentIfMatching(Uppercase(PreviousAssistantName), PreviousInstallPath);
DeleteEnvironmentIfMatching(Uppercase(PreviousAssistantName) + '_HOME', AddBackslash(PreviousInstallPath) + 'scripts');
end;
if CurStep = ssPostInstall then
PrepareRuntime;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
Name: String;
begin
if CurUninstallStep = usUninstall then begin
if RegQueryStringValue(HKCU, 'Software\Morgan\Installer', 'AssistantName', Name) then
UninstallPrefix := Uppercase(Name);
RegQueryStringValue(HKCU, 'Software\Morgan\Installer', 'InstallPath', UninstallPath);
end;
if (CurUninstallStep = usPostUninstall) and
(UninstallPrefix <> '') and (UninstallPath <> '') then begin
DeleteEnvironmentIfMatching(UninstallPrefix, UninstallPath);
DeleteEnvironmentIfMatching('ASSISTANT_NAME', UninstallPrefix);
DeleteEnvironmentIfMatching(UninstallPrefix + '_HOME', AddBackslash(UninstallPath) + 'scripts');
end;
end;