diff --git a/.gitignore b/.gitignore index b028691..11fde10 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ dyn2py.egg-info build dist docs -tests/output_files \ No newline at end of file +tests/output_files +Output \ No newline at end of file diff --git a/README.md b/README.md index e1334b7..e6464df 100644 --- a/README.md +++ b/README.md @@ -169,13 +169,27 @@ venv .venv pip install -e . ``` -### Build +### Build for Windows ``` pip install -e .[build] pyinstaller dyn2py.spec ``` +### Create installer for Windows + +- The already built exe should be in `dist\dyn2py.exe` +- Install Inno Setup: https://jrsoftware.org/isdl.php +- Run this in powershell: + +```powershell +# Read version number from pyproject.toml and update in innosetup: +$regex = Select-String -Path pyproject.toml -Pattern '^version = "((?:\d\.){2}\d)"$' +$version = $regex.Matches.Groups[1].Value +(Get-Content dyn2py-installer.iss).Replace("x.x.x",$version) | Set-Content dyn2py-installer.iss +# Build: +& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" -Qp $(Join-Path $PWD.Path dyn2py-installer.iss) +``` ### Live module documentation ``` diff --git a/dyn2py-installer.iss b/dyn2py-installer.iss new file mode 100644 index 0000000..076e3ec --- /dev/null +++ b/dyn2py-installer.iss @@ -0,0 +1,82 @@ +[Setup] +AppId={{E924F481-6909-43F8-8469-11155A5EB9A2} +AppName=dyn2py +AppVersion=x.x.x +AppPublisher=infeeeee +AppPublisherURL=https://github.com/infeeeee/dyn2py +AppSupportURL=https://github.com/infeeeee/dyn2py/issues +AppUpdatesURL=https://github.com/infeeeee/dyn2py/releases/latest +DefaultDirName={autopf}\dyn2py +DisableProgramGroupPage=yes +LicenseFile=LICENSE +PrivilegesRequired=admin +OutputBaseFilename=dyn2py-installer +Compression=lzma +SolidCompression=yes +WizardStyle=modern +ChangesEnvironment=yes + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" + +[Files] +Source: "dist\dyn2py.exe"; DestDir: "{app}"; Flags: ignoreversion + + +[Code] +const EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; + +procedure EnvAddPath(Path: string); +var + Paths: string; +begin + { Retrieve current path (use empty string if entry not exists) } + if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) + then Paths := ''; + + { Skip if string already found in path } + if Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';') > 0 then exit; + + { App string to the end of the path variable } + Paths := Paths + ';'+ Path +';' + + { Overwrite (or create if missing) path environment variable } + if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) + then Log(Format('The [%s] added to PATH: [%s]', [Path, Paths])) + else Log(Format('Error while adding the [%s] to PATH: [%s]', [Path, Paths])); +end; + +procedure EnvRemovePath(Path: string); +var + Paths: string; + P: Integer; +begin + { Skip if registry entry not exists } + if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then + exit; + + { Skip if string not found in path } + P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';'); + if P = 0 then exit; + + { Update path variable } + Delete(Paths, P - 1, Length(Path) + 1); + + { Overwrite path environment variable } + if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) + then Log(Format('The [%s] removed from PATH: [%s]', [Path, Paths])) + else Log(Format('Error while removing the [%s] from PATH: [%s]', [Path, Paths])); +end; + + +procedure CurStepChanged(CurStep: TSetupStep); +begin + if CurStep = ssPostInstall + then EnvAddPath(ExpandConstant('{app}')); +end; + +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); +begin + if CurUninstallStep = usPostUninstall + then EnvRemovePath(ExpandConstant('{app}')); +end;