|
1 |
| -; Copyright (C) 2021-2023 by Bill Stewart (bstewart at iname.com) |
2 |
| -; |
3 |
| -; This program is free software; you can redistribute it and/or modify it under |
4 |
| -; the terms of the GNU Lesser General Public License as published by the Free |
5 |
| -; Software Foundation; either version 3 of the License, or (at your option) any |
6 |
| -; later version. |
7 |
| -; |
8 |
| -; This program is distributed in the hope that it will be useful, but WITHOUT |
9 |
| -; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
10 |
| -; FOR A PARTICULAR PURPOSE. See the GNU General Lesser Public License for more |
11 |
| -; details. |
12 |
| -; |
13 |
| -; You should have received a copy of the GNU Lesser General Public License |
14 |
| -; along with this program. If not, see https://www.gnu.org/licenses/. |
15 |
| - |
16 |
| -; Sample Inno Setup (https://www.jrsoftware.org/isinfo.php) script |
17 |
| -; demonstrating use of PathMgr.dll. |
18 |
| -; |
19 |
| -; This script uses PathMgr.dll in the following ways: |
20 |
| -; * Copies PathMgr.dll to the target machine (required for uninstall) |
21 |
| -; * Defines a task in [Tasks] that should modify the Path |
22 |
| -; * Imports the AddDirToPath() DLL function at setup time |
23 |
| -; * Imports the RemoveDirFromPath() DLL function at uninstall time |
24 |
| -; * Stores task state as custom setting using RegisterPreviousData() |
25 |
| -; * Retrieves task state custom setting during setup and uninstall initialize |
26 |
| -; * At post install, adds app dir to Path if task selected |
27 |
| -; * At uninstall, removes dir from Path if custom setting present |
28 |
| -; * Unloads and deletes DLL and removes app dir at uninstall deinitialize |
29 |
| - |
30 |
| -#if Ver < EncodeVer(6,0,0,0) |
31 |
| - #error This script requires Inno Setup 6 or later |
32 |
| -#endif |
33 |
| - |
34 |
| -[Setup] |
35 |
| -AppId={{A17D2D05-C729-4F2A-9CC7-E04906C5A842} |
36 |
| -AppName=EditPath |
37 |
| -AppVersion=4.0.4.0 |
38 |
| -UsePreviousAppDir=false |
39 |
| -DefaultDirName={autopf}\EditPath |
40 |
| -Uninstallable=true |
41 |
| -OutputDir=. |
42 |
| -OutputBaseFilename=EditPath_Setup |
43 |
| -ArchitecturesInstallIn64BitMode=x64 |
44 |
| -PrivilegesRequired=none |
45 |
| -PrivilegesRequiredOverridesAllowed=dialog |
46 |
| - |
47 |
| -[Files] |
48 |
| -; Install PathMgr.dll for use with both setup and uninstall; use |
49 |
| -; uninsneveruninstall flag because DeinitializeSetup() will delete after |
50 |
| -; unloading the DLL; install the 32-bit version of PathMgr.dll because both |
51 |
| -; setup and uninstall executables are 32-bit |
52 |
| -Source: "i386\PathMgr.dll"; DestDir: "{app}"; Flags: uninsneveruninstall |
53 |
| - |
54 |
| -; Other files to install on target system |
55 |
| -Source: "i386\EditPath.exe"; DestDir: "{app}"; Check: not Is64BitInstallMode() |
56 |
| -Source: "x86_64\EditPath.exe"; DestDir: "{app}"; Check: Is64BitInstallMode() |
57 |
| -Source: "EditPath.md"; DestDir: "{app}" |
58 |
| - |
59 |
| -[Tasks] |
60 |
| -Name: modifypath; Description: "&Add to Path" |
61 |
| - |
62 |
| -[Code] |
63 |
| -const |
64 |
| - MODIFY_PATH_TASK_NAME = 'modifypath'; // Specify name of task |
65 |
| -
|
66 |
| -var |
67 |
| - PathIsModified: Boolean; // Cache task selection from previous installs |
68 |
| - ApplicationUninstalled: Boolean; // Has application been uninstalled? |
69 |
| -
|
70 |
| -// Import AddDirToPath() at setup time ('files:' prefix) |
71 |
| -function DLLAddDirToPath(DirName: string; PathType, AddType: DWORD): DWORD; |
72 |
| - external 'AddDirToPath@files:PathMgr.dll stdcall setuponly'; |
73 |
| -
|
74 |
| -// Import RemoveDirFromPath() at uninstall time ('{app}\' prefix) |
75 |
| -function DLLRemoveDirFromPath(DirName: string; PathType: DWORD): DWORD; |
76 |
| - external 'RemoveDirFromPath@{app}\PathMgr.dll stdcall uninstallonly'; |
77 |
| -
|
78 |
| -// Wrapper for AddDirToPath() DLL function |
79 |
| -function AddDirToPath(const DirName: string): DWORD; |
80 |
| -var |
81 |
| - PathType, AddType: DWORD; |
82 |
| -begin |
83 |
| - // PathType = 0 - use system Path |
84 |
| - // PathType = 1 - use user Path |
85 |
| - // AddType = 0 - add to end of Path |
86 |
| - // AddType = 1 - add to beginning of Path |
87 |
| - if IsAdminInstallMode() then |
88 |
| - PathType := 0 |
89 |
| - else |
90 |
| - PathType := 1; |
91 |
| - AddType := 0; |
92 |
| - result := DLLAddDirToPath(DirName, PathType, AddType); |
93 |
| -end; |
94 |
| -
|
95 |
| -// Wrapper for RemoveDirFromPath() DLL function |
96 |
| -function RemoveDirFromPath(const DirName: string): DWORD; |
97 |
| -var |
98 |
| - PathType: DWORD; |
99 |
| -begin |
100 |
| - // PathType = 0 - use system Path |
101 |
| - // PathType = 1 - use user Path |
102 |
| - if IsAdminInstallMode() then |
103 |
| - PathType := 0 |
104 |
| - else |
105 |
| - PathType := 1; |
106 |
| - result := DLLRemoveDirFromPath(DirName, PathType); |
107 |
| -end; |
108 |
| -
|
109 |
| -procedure RegisterPreviousData(PreviousDataKey: Integer); |
110 |
| -begin |
111 |
| - // Store previous or current task selection as custom user setting |
112 |
| - if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then |
113 |
| - SetPreviousData(PreviousDataKey, MODIFY_PATH_TASK_NAME, 'true'); |
114 |
| -end; |
115 |
| -
|
116 |
| -function InitializeSetup(): Boolean; |
117 |
| -begin |
118 |
| - result := true; |
119 |
| - // Was task selected during a previous install? |
120 |
| - PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true'; |
121 |
| -end; |
122 |
| -
|
123 |
| -function InitializeUninstall(): Boolean; |
124 |
| -begin |
125 |
| - result := true; |
126 |
| - // Was task selected during a previous install? |
127 |
| - PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true'; |
128 |
| - ApplicationUninstalled := false; |
129 |
| -end; |
130 |
| -
|
131 |
| -procedure CurStepChanged(CurStep: TSetupStep); |
132 |
| -begin |
133 |
| - if CurStep = ssPostInstall then |
134 |
| - begin |
135 |
| - // Add app directory to Path at post-install step if task selected |
136 |
| - if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then |
137 |
| - AddDirToPath(ExpandConstant('{app}')); |
138 |
| - end; |
139 |
| -end; |
140 |
| -
|
141 |
| -procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); |
142 |
| -begin |
143 |
| - if CurUninstallStep = usUninstall then |
144 |
| - begin |
145 |
| - // Remove app directory from path during uninstall if task was selected; |
146 |
| - // use variable because we can't use WizardIsTaskSelected() at uninstall |
147 |
| - if PathIsModified then |
148 |
| - RemoveDirFromPath(ExpandConstant('{app}')); |
149 |
| - end |
150 |
| - else if CurUninstallStep = usPostUninstall then |
151 |
| - begin |
152 |
| - ApplicationUninstalled := true; |
153 |
| - end; |
154 |
| -end; |
155 |
| -
|
156 |
| -procedure DeinitializeUninstall(); |
157 |
| -begin |
158 |
| - if ApplicationUninstalled then |
159 |
| - begin |
160 |
| - // Unload and delete PathMgr.dll and remove app dir when uninstalling |
161 |
| - UnloadDLL(ExpandConstant('{app}\PathMgr.dll')); |
162 |
| - DeleteFile(ExpandConstant('{app}\PathMgr.dll')); |
163 |
| - RemoveDir(ExpandConstant('{app}')); |
164 |
| - end; |
165 |
| -end; |
| 1 | +; Copyright (C) 2021-2023 by Bill Stewart (bstewart at iname.com) |
| 2 | +; |
| 3 | +; This program is free software; you can redistribute it and/or modify it under |
| 4 | +; the terms of the GNU Lesser General Public License as published by the Free |
| 5 | +; Software Foundation; either version 3 of the License, or (at your option) any |
| 6 | +; later version. |
| 7 | +; |
| 8 | +; This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | +; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 | +; FOR A PARTICULAR PURPOSE. See the GNU General Lesser Public License for more |
| 11 | +; details. |
| 12 | +; |
| 13 | +; You should have received a copy of the GNU Lesser General Public License |
| 14 | +; along with this program. If not, see https://www.gnu.org/licenses/. |
| 15 | + |
| 16 | +; Sample Inno Setup (https://www.jrsoftware.org/isinfo.php) script |
| 17 | +; demonstrating use of PathMgr.dll. |
| 18 | +; |
| 19 | +; This script uses PathMgr.dll in the following ways: |
| 20 | +; * Copies PathMgr.dll to the target machine (required for uninstall) |
| 21 | +; * Defines a task in [Tasks] that should modify the Path |
| 22 | +; * Imports the AddDirToPath() DLL function at setup time |
| 23 | +; * Imports the RemoveDirFromPath() DLL function at uninstall time |
| 24 | +; * Stores task state as custom setting using RegisterPreviousData() |
| 25 | +; * Retrieves task state custom setting during setup and uninstall initialize |
| 26 | +; * At post install, adds app dir to Path if task selected |
| 27 | +; * At uninstall, removes dir from Path if custom setting present |
| 28 | +; * Unloads and deletes DLL and removes app dir at uninstall deinitialize |
| 29 | + |
| 30 | +#if Ver < EncodeVer(6,0,0,0) |
| 31 | + #error This script requires Inno Setup 6 or later |
| 32 | +#endif |
| 33 | + |
| 34 | +[Setup] |
| 35 | +AppId={{A17D2D05-C729-4F2A-9CC7-E04906C5A842} |
| 36 | +AppName=EditPath |
| 37 | +AppVersion=4.0.4.0 |
| 38 | +UsePreviousAppDir=false |
| 39 | +DefaultDirName={autopf}\EditPath |
| 40 | +Uninstallable=true |
| 41 | +OutputDir=. |
| 42 | +OutputBaseFilename=EditPath_Setup |
| 43 | +ArchitecturesInstallIn64BitMode=x64 |
| 44 | +PrivilegesRequired=none |
| 45 | +PrivilegesRequiredOverridesAllowed=dialog |
| 46 | + |
| 47 | +[Files] |
| 48 | +; Install PathMgr.dll for use with both setup and uninstall; use |
| 49 | +; uninsneveruninstall flag because DeinitializeSetup() will delete after |
| 50 | +; unloading the DLL; install the 32-bit version of PathMgr.dll because both |
| 51 | +; setup and uninstall executables are 32-bit |
| 52 | +Source: "i386\PathMgr.dll"; DestDir: "{app}"; Flags: uninsneveruninstall |
| 53 | + |
| 54 | +; Other files to install on target system |
| 55 | +Source: "i386\EditPath.exe"; DestDir: "{app}"; Check: not Is64BitInstallMode() |
| 56 | +Source: "x86_64\EditPath.exe"; DestDir: "{app}"; Check: Is64BitInstallMode() |
| 57 | +Source: "EditPath.md"; DestDir: "{app}" |
| 58 | + |
| 59 | +[Tasks] |
| 60 | +Name: modifypath; Description: "&Add to Path" |
| 61 | + |
| 62 | +[Code] |
| 63 | +const |
| 64 | + MODIFY_PATH_TASK_NAME = 'modifypath'; // Specify name of task |
| 65 | +
|
| 66 | +var |
| 67 | + PathIsModified: Boolean; // Cache task selection from previous installs |
| 68 | + ApplicationUninstalled: Boolean; // Has application been uninstalled? |
| 69 | +
|
| 70 | +// Import AddDirToPath() at setup time ('files:' prefix) |
| 71 | +function DLLAddDirToPath(DirName: string; PathType, AddType: DWORD): DWORD; |
| 72 | + external 'AddDirToPath@files:PathMgr.dll stdcall setuponly'; |
| 73 | +
|
| 74 | +// Import RemoveDirFromPath() at uninstall time ('{app}\' prefix) |
| 75 | +function DLLRemoveDirFromPath(DirName: string; PathType: DWORD): DWORD; |
| 76 | + external 'RemoveDirFromPath@{app}\PathMgr.dll stdcall uninstallonly'; |
| 77 | +
|
| 78 | +// Wrapper for AddDirToPath() DLL function |
| 79 | +function AddDirToPath(const DirName: string): DWORD; |
| 80 | +var |
| 81 | + PathType, AddType: DWORD; |
| 82 | +begin |
| 83 | + // PathType = 0 - use system Path |
| 84 | + // PathType = 1 - use user Path |
| 85 | + // AddType = 0 - add to end of Path |
| 86 | + // AddType = 1 - add to beginning of Path |
| 87 | + if IsAdminInstallMode() then |
| 88 | + PathType := 0 |
| 89 | + else |
| 90 | + PathType := 1; |
| 91 | + AddType := 0; |
| 92 | + result := DLLAddDirToPath(DirName, PathType, AddType); |
| 93 | +end; |
| 94 | +
|
| 95 | +// Wrapper for RemoveDirFromPath() DLL function |
| 96 | +function RemoveDirFromPath(const DirName: string): DWORD; |
| 97 | +var |
| 98 | + PathType: DWORD; |
| 99 | +begin |
| 100 | + // PathType = 0 - use system Path |
| 101 | + // PathType = 1 - use user Path |
| 102 | + if IsAdminInstallMode() then |
| 103 | + PathType := 0 |
| 104 | + else |
| 105 | + PathType := 1; |
| 106 | + result := DLLRemoveDirFromPath(DirName, PathType); |
| 107 | +end; |
| 108 | +
|
| 109 | +procedure RegisterPreviousData(PreviousDataKey: Integer); |
| 110 | +begin |
| 111 | + // Store previous or current task selection as custom user setting |
| 112 | + if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then |
| 113 | + SetPreviousData(PreviousDataKey, MODIFY_PATH_TASK_NAME, 'true'); |
| 114 | +end; |
| 115 | +
|
| 116 | +function InitializeSetup(): Boolean; |
| 117 | +begin |
| 118 | + result := true; |
| 119 | + // Was task selected during a previous install? |
| 120 | + PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true'; |
| 121 | +end; |
| 122 | +
|
| 123 | +function InitializeUninstall(): Boolean; |
| 124 | +begin |
| 125 | + result := true; |
| 126 | + // Was task selected during a previous install? |
| 127 | + PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true'; |
| 128 | + ApplicationUninstalled := false; |
| 129 | +end; |
| 130 | +
|
| 131 | +procedure CurStepChanged(CurStep: TSetupStep); |
| 132 | +begin |
| 133 | + if CurStep = ssPostInstall then |
| 134 | + begin |
| 135 | + // Add app directory to Path at post-install step if task selected |
| 136 | + if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then |
| 137 | + AddDirToPath(ExpandConstant('{app}')); |
| 138 | + end; |
| 139 | +end; |
| 140 | +
|
| 141 | +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); |
| 142 | +begin |
| 143 | + if CurUninstallStep = usUninstall then |
| 144 | + begin |
| 145 | + // Remove app directory from path during uninstall if task was selected; |
| 146 | + // use variable because we can't use WizardIsTaskSelected() at uninstall |
| 147 | + if PathIsModified then |
| 148 | + RemoveDirFromPath(ExpandConstant('{app}')); |
| 149 | + end |
| 150 | + else if CurUninstallStep = usPostUninstall then |
| 151 | + begin |
| 152 | + ApplicationUninstalled := true; |
| 153 | + end; |
| 154 | +end; |
| 155 | +
|
| 156 | +procedure DeinitializeUninstall(); |
| 157 | +begin |
| 158 | + if ApplicationUninstalled then |
| 159 | + begin |
| 160 | + // Unload and delete PathMgr.dll and remove app dir when uninstalling |
| 161 | + UnloadDLL(ExpandConstant('{app}\PathMgr.dll')); |
| 162 | + DeleteFile(ExpandConstant('{app}\PathMgr.dll')); |
| 163 | + RemoveDir(ExpandConstant('{app}')); |
| 164 | + end; |
| 165 | +end; |
0 commit comments