-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinno_setup.iss
More file actions
129 lines (113 loc) · 3.86 KB
/
inno_setup.iss
File metadata and controls
129 lines (113 loc) · 3.86 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
[Setup]
AppCopyright=Copyright (C) 2026 Discloud
AppName=Discloud CLI
AppPublisher=Discloud
AppPublisherURL=https://discloud.com
AppReadmeFile=https://github.com/discloud/cli-dart#readme
AppUpdatesURL=https://github.com/discloud/cli-dart/releases
; update with inno_setup script
AppVersion={{version}}
ArchitecturesAllowed=x64compatible or arm64
ArchitecturesInstallIn64BitMode=x64compatible or arm64
ChangesEnvironment=yes
Compression=lzma2/max
DefaultDirName={autopf}\Discloud\cli
DefaultGroupName=Discloud CLI
LicenseFile=LICENSE
OutputBaseFilename=discloud-cli-x64-setup
OutputDir=.
PrivilegesRequired=admin
SetupIconFile=assets\icons\favicon.ico
SolidCompression=yes
; update with inno_setup script
VersionInfoVersion={{version}}.0
WizardStyle=modern dark polar
[Files]
Source: discloud-cli-x64.exe; DestName: discloud.exe; DestDir: {app}; Check: PreferX64Files; Flags: ignoreversion
Source: discloud-cli-arm64.exe; DestName: discloud.exe; DestDir: {app}; Check: PreferArm64Files; Flags: ignoreversion
Source: assets\icons\favicon.ico; DestDir: {app}; Flags: ignoreversion
Source: LICENSE; DestDir: {app}; Flags: ignoreversion
Source: docs\*.html; DestDir: {app}\docs; Flags: ignoreversion
[Icons]
Name: {app}\CLI Documentation; Filename: {app}\docs\index.html;
Name: {group}\CLI Documentation; Filename: {app}\docs\index.html;
Name: {group}\Uninstall; Filename: {uninstallexe};
[Code]
[Code]
function PreferArm64Files: Boolean;
begin
Result := IsArm64;
end;
function PreferX64Files: Boolean;
begin
Result := not PreferArm64Files and IsX64Compatible;
end;
function PreferX86Files: Boolean;
begin
Result := not PreferArm64Files and not PreferX64Files;
end;
const
EnvironmentKey = 'System\CurrentControlSet\Control\Session Manager\Environment';
// Function to add the path to the PATH environment variable
procedure AddPath(Path: string);
var
Paths: string;
begin
// Try to read the current system PATH
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
Paths := '';
// Check if the path is already there (we use ';' at the ends to avoid false positives with similar paths)
if Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';') = 0 then
begin
// Add the new path
if Paths = '' then
Paths := Path
else if Copy(Paths, Length(Paths), 1) = ';' then
Paths := Paths + Path
else
Paths := Paths + ';' + Path;
// Save the new PATH to the registry
RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths);
end;
end;
// Function to remove the path from the PATH environment variable during uninstallation
procedure RemovePath(Path: string);
var
Paths: string;
P: Integer;
begin
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
Exit;
// Prepare strings with ';' to search for the exact block
Paths := ';' + Paths + ';';
Path := ';' + Path + ';';
P := Pos(Uppercase(Path), Uppercase(Paths));
if P > 0 then
begin
// Remove the found segment
Delete(Paths, P, Length(Path) - 1);
// Clean up the extra ';' we put at the ends
if Copy(Paths, 1, 1) = ';' then Delete(Paths, 1, 1);
if Copy(Paths, Length(Paths), 1) = ';' then Delete(Paths, Length(Paths), 1);
// Save the cleaned PATH to the registry
RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths);
end;
end;
// Standard Inno Setup event called during Installation
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
// Add the application directory ({app}) to the PATH
AddPath(ExpandConstant('{app}'));
end;
end;
// Standard Inno Setup event called during Uninstallation
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall then
begin
// Remove the application directory ({app}) from the PATH
RemovePath(ExpandConstant('{app}'));
end;
end;