-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSLAM-installer.iss
More file actions
138 lines (115 loc) · 4.09 KB
/
SLAM-installer.iss
File metadata and controls
138 lines (115 loc) · 4.09 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
[Setup]
AppName=SLAM
AppVersion=
AppVerName=SLAM
AppPublisher=HalfManBear
UninstallDisplayName=SLAM
UninstallDisplayIcon={app}\icon.ico
DefaultDirName={commonpf}\SLAM
DefaultGroupName=SLAM
OutputBaseFilename=SLAM_Installer
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
CreateUninstallRegKey=yes
DisableDirPage=no
DirExistsWarning=no
[Files]
; No static files—content fetched at install time
[UninstallDelete]
Type: filesandordirs; Name: "{app}\*"
[Run]
Filename: "explorer.exe"; Parameters: "{app}"; Flags: postinstall nowait unchecked; Description: "Open installation folder"
[Code]
const
PS7Path = 'C:\Program Files\PowerShell\7\pwsh.exe';
GitExe = 'C:\Program Files\Git\cmd\git.exe';
WingetExe = 'winget';
TempDir = '{tmp}\SLAMTempClone';
procedure ExecWithWait(const FilePath, Params: String);
var
ResultCode: Integer;
begin
if not Exec(FilePath, Params, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) or (ResultCode <> 0) then
MsgBox(Format('Command failed: %s %s (Exit code: %d)', [FilePath, Params, ResultCode]), mbError, MB_OK);
end;
function IsInstalled(const Path: String): Boolean;
begin
Result := FileExists(Path);
end;
function CheckWingetInstalled(): Boolean;
var
Res: Integer;
begin
Result := Exec('cmd.exe', '/c ' + WingetExe + ' --version', '', SW_HIDE, ewWaitUntilTerminated, Res) and (Res = 0);
end;
procedure InstallIfMissing(const Id, ExePath, FriendlyName: String);
begin
if not IsInstalled(ExePath) then
begin
if CheckWingetInstalled() then
ExecWithWait('cmd.exe', '/c ' + WingetExe + ' install --id ' + Id + ' -e --source winget')
else
MsgBox(FriendlyName + ' is missing and winget is unavailable. Please install it manually.', mbError, MB_OK);
end;
end;
procedure CloneAndCopySLAM();
var
InstallPath, ClonePath: String;
begin
InstallPath := ExpandConstant('{app}');
ClonePath := ExpandConstant(TempDir);
InstallIfMissing('Git.Git', GitExe, 'Git');
InstallIfMissing('Microsoft.PowerShell', PS7Path, 'PowerShell 7');
if DirExists(ClonePath) then
ExecWithWait('cmd.exe', '/c rmdir /S /Q "' + ClonePath + '"');
CreateDir(ClonePath);
ExecWithWait(GitExe, 'clone https://github.com/halfmanbear/SLAM.git "' + ClonePath + '"');
ExecWithWait('cmd.exe', '/c xcopy "' + ClonePath + '\*" "' + InstallPath + '" /E /H /C /I /Y');
ExecWithWait(PS7Path, '-ExecutionPolicy Bypass -File "' + InstallPath + '\create-shortcut.ps1"');
ExecWithWait('cmd.exe', '/c rmdir /S /Q "' + ClonePath + '"');
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
CloneAndCopySLAM();
end;
function InitializeUninstall(): Boolean;
var
WarningMsg: String;
begin
WarningMsg := 'WARNING: Before proceeding, ensure that:' + #13#10 + #13#10 +
'- No mods are currently Installed within SLAM' + #13#10 +
'- All mods are BACKED UP' + #13#10 + #13#10 +
'This will DELETE the SLAM directory contents. ' +
'Mods that have not been backed up will be permanently lost.' + #13#10 + #13#10 +
'Do you want to continue?';
Result := MsgBox(WarningMsg, mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = IDYES;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
ShortcutPath: String;
AppPath: String;
begin
if CurUninstallStep = usUninstall then
begin
ShortcutPath := ExpandConstant('{userdesktop}\SLAM.lnk');
if FileExists(ShortcutPath) then
DeleteFile(ShortcutPath);
ShortcutPath := ExpandConstant('{commondesktop}\SLAM.lnk');
if FileExists(ShortcutPath) then
DeleteFile(ShortcutPath);
ShortcutPath := ExpandConstant('{userprograms}\SLAM.lnk');
if FileExists(ShortcutPath) then
DeleteFile(ShortcutPath);
ShortcutPath := ExpandConstant('{commonprograms}\SLAM.lnk');
if FileExists(ShortcutPath) then
DeleteFile(ShortcutPath);
end;
if CurUninstallStep = usPostUninstall then
begin
AppPath := ExpandConstant('{app}');
if DirExists(AppPath) then
RemoveDir(AppPath);
end;
end;