|
| 1 | +; Script generated by the Inno Setup Script Wizard. |
| 2 | +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! |
| 3 | + |
| 4 | +#define MyAppName "PVM" |
| 5 | +#define MyAppVersion "1.3.1" |
| 6 | +#define MyAppPublisher "hjb.dev" |
| 7 | +#define MyAppURL "https://github.com/hjbdev/pvm" |
| 8 | +#define MyAppExeName "pvm.exe" |
| 9 | + |
| 10 | +[Setup] |
| 11 | +; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. |
| 12 | +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) |
| 13 | +AppId={{DA006438-7CC4-41E4-B2BF-2AD84AAA18E9} |
| 14 | +AppName={#MyAppName} |
| 15 | +AppVersion={#MyAppVersion} |
| 16 | +;AppVerName={#MyAppName} {#MyAppVersion} |
| 17 | +AppPublisher={#MyAppPublisher} |
| 18 | +AppPublisherURL={#MyAppURL} |
| 19 | +AppSupportURL={#MyAppURL} |
| 20 | +AppUpdatesURL={#MyAppURL} |
| 21 | +DefaultDirName={%USERPROFILE}\.pvm |
| 22 | +UninstallDisplayIcon={app}\{#MyAppExeName} |
| 23 | +; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run |
| 24 | +; on anything but x64 and Windows 11 on Arm. |
| 25 | +ArchitecturesAllowed=x64os |
| 26 | +; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the |
| 27 | +; install be done in "64-bit mode" on x64 or Windows 11 on Arm, |
| 28 | +; meaning it should use the native 64-bit Program Files directory and |
| 29 | +; the 64-bit view of the registry. |
| 30 | +ArchitecturesInstallIn64BitMode=x64compatible |
| 31 | +DefaultGroupName={#MyAppName} |
| 32 | +AllowNoIcons=yes |
| 33 | +LicenseFile=LICENSE |
| 34 | +InfoAfterFile=README.md |
| 35 | +; Uncomment the following line to run in non administrative install mode (install for current user only). |
| 36 | +PrivilegesRequired=lowest |
| 37 | +PrivilegesRequiredOverridesAllowed=dialog |
| 38 | +OutputDir=. |
| 39 | +OutputBaseFilename=pvm-setup |
| 40 | +SolidCompression=yes |
| 41 | +WizardStyle=modern |
| 42 | + |
| 43 | +[Languages] |
| 44 | +Name: "english"; MessagesFile: "compiler:Default.isl" |
| 45 | + |
| 46 | +[Files] |
| 47 | +Source: "src\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion |
| 48 | +; NOTE: Don't use "Flags: ignoreversion" on any shared system files |
| 49 | + |
| 50 | +[Dirs] |
| 51 | +Name: "{app}\bin" |
| 52 | +Name: "{app}\versions" |
| 53 | + |
| 54 | +[UninstallDelete] |
| 55 | +Type: filesandordirs; Name: "{app}" |
| 56 | + |
| 57 | +[Code] |
| 58 | +var |
| 59 | + path: string; |
| 60 | +
|
| 61 | +procedure InitializePath(); |
| 62 | +begin |
| 63 | + if RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path) then |
| 64 | + begin |
| 65 | + if Pos(ExpandConstant('{app}'), path) = 0 then |
| 66 | + begin |
| 67 | + // Check if PATH is empty |
| 68 | + if path <> '' then |
| 69 | + path := path + ';'; |
| 70 | + |
| 71 | + // Add the app directory and bin directory to the PATH |
| 72 | + path := path + ExpandConstant('{app}') + ';' + ExpandConstant('{app}') + '\bin'; |
| 73 | + |
| 74 | + // Remove extra semicolons (e.g., ;; becomes ; or ;;; becomes ;) |
| 75 | + StringChangeEx(path, ';;', ';', True); |
| 76 | +
|
| 77 | + // Remove any leading semicolon at the start of the path if present |
| 78 | + if (Pos(';', path) = 1) then |
| 79 | + path := Copy(path, 2, Length(path) - 1); |
| 80 | +
|
| 81 | + // Ensure there's no trailing semicolon at the end of the path |
| 82 | + if (Pos(';', path) = Length(path)) then |
| 83 | + path := Copy(path, 1, Length(path) - 1); |
| 84 | + |
| 85 | + // Write the added path back to the registry |
| 86 | + RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path); |
| 87 | + end; |
| 88 | + end |
| 89 | + else |
| 90 | + begin |
| 91 | + MsgBox('Unable to read PATH environment variable.', mbError, MB_OK); |
| 92 | + end; |
| 93 | +end; |
| 94 | +
|
| 95 | +procedure RemovePath(); |
| 96 | +begin |
| 97 | + if RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path) then |
| 98 | + begin |
| 99 | + // Remove the app directory and bin directory from the PATH |
| 100 | + StringChangeEx(path, ExpandConstant('{app}') + ';', '', True); |
| 101 | + StringChangeEx(path, ExpandConstant('{app}') + '\bin' + ';', '', True); |
| 102 | +
|
| 103 | + // Remove extra semicolons (e.g., ;; becomes ; or ;;; becomes ;) |
| 104 | + StringChangeEx(path, ';;', ';', True); |
| 105 | +
|
| 106 | + // Remove any leading semicolon at the start of the path if present |
| 107 | + if (Pos(';', path) = 1) then |
| 108 | + path := Copy(path, 2, Length(path) - 1); |
| 109 | +
|
| 110 | + // Ensure there's no trailing semicolon at the end of the path |
| 111 | + if (Pos(';', path) = Length(path)) then |
| 112 | + path := Copy(path, 1, Length(path) - 1); |
| 113 | +
|
| 114 | + // Write the cleaned path back to the registry |
| 115 | + RegWriteExpandStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', path); |
| 116 | + end |
| 117 | + else |
| 118 | + begin |
| 119 | + MsgBox('Unable to read PATH environment variable.', mbError, MB_OK); |
| 120 | + end; |
| 121 | +end; |
| 122 | +
|
| 123 | +procedure CurStepChanged(CurStep: TSetupStep); |
| 124 | +begin |
| 125 | + if CurStep = ssPostInstall then |
| 126 | + begin |
| 127 | + InitializePath(); |
| 128 | + end |
| 129 | +end; |
| 130 | +
|
| 131 | +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); |
| 132 | +begin |
| 133 | + if CurUninstallStep = usUninstall then |
| 134 | + begin |
| 135 | + RemovePath(); |
| 136 | + end; |
| 137 | +end; |
| 138 | +
|
| 139 | +
|
0 commit comments