Add packager on Windows
This commit is contained in:
parent
ce45cd1ca1
commit
bebd8e860e
110
packager.py
Normal file
110
packager.py
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
import click
|
||||||
|
import glob
|
||||||
|
import shutil
|
||||||
|
import toml
|
||||||
|
|
||||||
|
PACKAGER_TARGET_DIR = "target/packager"
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PackageInfo:
|
||||||
|
name: str
|
||||||
|
version: str
|
||||||
|
description: str
|
||||||
|
publisher: str
|
||||||
|
url: str
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option('--skipcargo', default=False, is_flag=True, help="Skip cargo release build")
|
||||||
|
def build(skipcargo):
|
||||||
|
"""Build espanso distribution"""
|
||||||
|
# Check operating system
|
||||||
|
TARGET_OS = "macosx"
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
TARGET_OS = "windows"
|
||||||
|
elif platform.system() == "Linux":
|
||||||
|
TARGET_OS = "linux"
|
||||||
|
|
||||||
|
print("Detected OS:", TARGET_OS)
|
||||||
|
|
||||||
|
print("Loading info from Cargo.toml")
|
||||||
|
cargo_info = toml.load("Cargo.toml")
|
||||||
|
package_info = PackageInfo(cargo_info["package"]["name"],
|
||||||
|
cargo_info["package"]["version"],
|
||||||
|
cargo_info["package"]["description"],
|
||||||
|
cargo_info["package"]["authors"][0],
|
||||||
|
cargo_info["package"]["homepage"])
|
||||||
|
print(package_info)
|
||||||
|
|
||||||
|
if not skipcargo:
|
||||||
|
print("Building release version...")
|
||||||
|
subprocess.run(["cargo", "build", "--release"])
|
||||||
|
else:
|
||||||
|
print("Skipping build")
|
||||||
|
|
||||||
|
if TARGET_OS == "windows":
|
||||||
|
build_windows(package_info)
|
||||||
|
|
||||||
|
|
||||||
|
def build_windows(package_info):
|
||||||
|
print("Starting packaging process on windows...")
|
||||||
|
|
||||||
|
# Check javapackager
|
||||||
|
try:
|
||||||
|
subprocess.run(["iscc"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise Exception("Could not find Inno Setup compiler. Please install it from here: http://www.jrsoftware.org/isdl.php")
|
||||||
|
|
||||||
|
print("Clearing target dirs")
|
||||||
|
|
||||||
|
# Clearing previous build directory
|
||||||
|
if os.path.isdir(PACKAGER_TARGET_DIR):
|
||||||
|
print("Cleaning packager temp directory...")
|
||||||
|
shutil.rmtree(PACKAGER_TARGET_DIR)
|
||||||
|
|
||||||
|
TARGET_DIR = os.path.join(PACKAGER_TARGET_DIR, "win")
|
||||||
|
os.makedirs(TARGET_DIR, exist_ok=True)
|
||||||
|
|
||||||
|
INSTALLER_NAME = "espanso-setup"
|
||||||
|
|
||||||
|
# Inno setup
|
||||||
|
shutil.copy("packager/win/modpath.iss", os.path.join(TARGET_DIR, "modpath.iss"))
|
||||||
|
|
||||||
|
print("Processing inno setup template")
|
||||||
|
with open("packager/win/setupscript.iss", "r") as iss_script:
|
||||||
|
content = iss_script.read()
|
||||||
|
|
||||||
|
# Replace variables
|
||||||
|
content = content.replace("{{{app_name}}}", package_info.name)
|
||||||
|
content = content.replace("{{{app_version}}}", package_info.version)
|
||||||
|
content = content.replace("{{{app_publisher}}}", package_info.publisher)
|
||||||
|
content = content.replace("{{{app_url}}}", package_info.url)
|
||||||
|
content = content.replace("{{{app_license}}}", os.path.abspath("LICENSE"))
|
||||||
|
content = content.replace("{{{app_icon}}}", os.path.abspath("packager/win/icon.ico"))
|
||||||
|
content = content.replace("{{{executable_path}}}", os.path.abspath("target/release/espanso.exe"))
|
||||||
|
content = content.replace("{{{output_dir}}}", os.path.abspath(TARGET_DIR))
|
||||||
|
content = content.replace("{{{output_name}}}", INSTALLER_NAME)
|
||||||
|
|
||||||
|
with open(os.path.join(TARGET_DIR, "setupscript.iss"), "w") as output_script:
|
||||||
|
output_script.write(content)
|
||||||
|
|
||||||
|
print("Compiling installer with Inno setup")
|
||||||
|
subprocess.run(["iscc", os.path.abspath(os.path.join(TARGET_DIR, "setupscript.iss"))])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print("[[ espanso packager ]]")
|
||||||
|
|
||||||
|
# Check python version 3
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
raise Exception("Must be using Python 3")
|
||||||
|
|
||||||
|
cli()
|
BIN
packager/win/icon.ico
Normal file
BIN
packager/win/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
219
packager/win/modpath.iss
Normal file
219
packager/win/modpath.iss
Normal file
|
@ -0,0 +1,219 @@
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Inno Setup Ver: 5.4.2
|
||||||
|
// Script Version: 1.4.2
|
||||||
|
// Author: Jared Breland <jbreland@legroom.net>
|
||||||
|
// Homepage: http://www.legroom.net/software
|
||||||
|
// License: GNU Lesser General Public License (LGPL), version 3
|
||||||
|
// http://www.gnu.org/licenses/lgpl.html
|
||||||
|
//
|
||||||
|
// Script Function:
|
||||||
|
// Allow modification of environmental path directly from Inno Setup installers
|
||||||
|
//
|
||||||
|
// Instructions:
|
||||||
|
// Copy modpath.iss to the same directory as your setup script
|
||||||
|
//
|
||||||
|
// Add this statement to your [Setup] section
|
||||||
|
// ChangesEnvironment=true
|
||||||
|
//
|
||||||
|
// Add this statement to your [Tasks] section
|
||||||
|
// You can change the Description or Flags
|
||||||
|
// You can change the Name, but it must match the ModPathName setting below
|
||||||
|
// Name: modifypath; Description: &Add application directory to your environmental path; Flags: unchecked
|
||||||
|
//
|
||||||
|
// Add the following to the end of your [Code] section
|
||||||
|
// ModPathName defines the name of the task defined above
|
||||||
|
// ModPathType defines whether the 'user' or 'system' path will be modified;
|
||||||
|
// this will default to user if anything other than system is set
|
||||||
|
// setArrayLength must specify the total number of dirs to be added
|
||||||
|
// Result[0] contains first directory, Result[1] contains second, etc.
|
||||||
|
// const
|
||||||
|
// ModPathName = 'modifypath';
|
||||||
|
// ModPathType = 'user';
|
||||||
|
//
|
||||||
|
// function ModPathDir(): TArrayOfString;
|
||||||
|
// begin
|
||||||
|
// setArrayLength(Result, 1);
|
||||||
|
// Result[0] := ExpandConstant('{app}');
|
||||||
|
// end;
|
||||||
|
// #include "modpath.iss"
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
procedure ModPath();
|
||||||
|
var
|
||||||
|
oldpath: String;
|
||||||
|
newpath: String;
|
||||||
|
updatepath: Boolean;
|
||||||
|
pathArr: TArrayOfString;
|
||||||
|
aExecFile: String;
|
||||||
|
aExecArr: TArrayOfString;
|
||||||
|
i, d: Integer;
|
||||||
|
pathdir: TArrayOfString;
|
||||||
|
regroot: Integer;
|
||||||
|
regpath: String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
// Get constants from main script and adjust behavior accordingly
|
||||||
|
// ModPathType MUST be 'system' or 'user'; force 'user' if invalid
|
||||||
|
if ModPathType = 'system' then begin
|
||||||
|
regroot := HKEY_LOCAL_MACHINE;
|
||||||
|
regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
|
||||||
|
end else begin
|
||||||
|
regroot := HKEY_CURRENT_USER;
|
||||||
|
regpath := 'Environment';
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Get array of new directories and act on each individually
|
||||||
|
pathdir := ModPathDir();
|
||||||
|
for d := 0 to GetArrayLength(pathdir)-1 do begin
|
||||||
|
updatepath := true;
|
||||||
|
|
||||||
|
// Modify WinNT path
|
||||||
|
if UsingWinNT() = true then begin
|
||||||
|
|
||||||
|
// Get current path, split into an array
|
||||||
|
RegQueryStringValue(regroot, regpath, 'Path', oldpath);
|
||||||
|
oldpath := oldpath + ';';
|
||||||
|
i := 0;
|
||||||
|
|
||||||
|
while (Pos(';', oldpath) > 0) do begin
|
||||||
|
SetArrayLength(pathArr, i+1);
|
||||||
|
pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);
|
||||||
|
oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath));
|
||||||
|
i := i + 1;
|
||||||
|
|
||||||
|
// Check if current directory matches app dir
|
||||||
|
if pathdir[d] = pathArr[i-1] then begin
|
||||||
|
// if uninstalling, remove dir from path
|
||||||
|
if IsUninstaller() = true then begin
|
||||||
|
continue;
|
||||||
|
// if installing, flag that dir already exists in path
|
||||||
|
end else begin
|
||||||
|
updatepath := false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Add current directory to new path
|
||||||
|
if i = 1 then begin
|
||||||
|
newpath := pathArr[i-1];
|
||||||
|
end else begin
|
||||||
|
newpath := newpath + ';' + pathArr[i-1];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Append app dir to path if not already included
|
||||||
|
if (IsUninstaller() = false) AND (updatepath = true) then
|
||||||
|
newpath := newpath + ';' + pathdir[d];
|
||||||
|
|
||||||
|
// Write new path
|
||||||
|
RegWriteStringValue(regroot, regpath, 'Path', newpath);
|
||||||
|
|
||||||
|
// Modify Win9x path
|
||||||
|
end else begin
|
||||||
|
|
||||||
|
// Convert to shortened dirname
|
||||||
|
pathdir[d] := GetShortName(pathdir[d]);
|
||||||
|
|
||||||
|
// If autoexec.bat exists, check if app dir already exists in path
|
||||||
|
aExecFile := 'C:\AUTOEXEC.BAT';
|
||||||
|
if FileExists(aExecFile) then begin
|
||||||
|
LoadStringsFromFile(aExecFile, aExecArr);
|
||||||
|
for i := 0 to GetArrayLength(aExecArr)-1 do begin
|
||||||
|
if IsUninstaller() = false then begin
|
||||||
|
// If app dir already exists while installing, skip add
|
||||||
|
if (Pos(pathdir[d], aExecArr[i]) > 0) then
|
||||||
|
updatepath := false;
|
||||||
|
break;
|
||||||
|
end else begin
|
||||||
|
// If app dir exists and = what we originally set, then delete at uninstall
|
||||||
|
if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then
|
||||||
|
aExecArr[i] := '';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// If app dir not found, or autoexec.bat didn't exist, then (create and) append to current path
|
||||||
|
if (IsUninstaller() = false) AND (updatepath = true) then begin
|
||||||
|
SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d], True);
|
||||||
|
|
||||||
|
// If uninstalling, write the full autoexec out
|
||||||
|
end else begin
|
||||||
|
SaveStringsToFile(aExecFile, aExecArr, False);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Split a string into an array using passed delimeter
|
||||||
|
procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
i := 0;
|
||||||
|
repeat
|
||||||
|
SetArrayLength(Dest, i+1);
|
||||||
|
if Pos(Separator,Text) > 0 then begin
|
||||||
|
Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1);
|
||||||
|
Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text));
|
||||||
|
i := i + 1;
|
||||||
|
end else begin
|
||||||
|
Dest[i] := Text;
|
||||||
|
Text := '';
|
||||||
|
end;
|
||||||
|
until Length(Text)=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure CurStepChanged(CurStep: TSetupStep);
|
||||||
|
var
|
||||||
|
taskname: String;
|
||||||
|
begin
|
||||||
|
taskname := ModPathName;
|
||||||
|
if CurStep = ssPostInstall then
|
||||||
|
if IsTaskSelected(taskname) then
|
||||||
|
ModPath();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
||||||
|
var
|
||||||
|
aSelectedTasks: TArrayOfString;
|
||||||
|
i: Integer;
|
||||||
|
taskname: String;
|
||||||
|
regpath: String;
|
||||||
|
regstring: String;
|
||||||
|
appid: String;
|
||||||
|
begin
|
||||||
|
// only run during actual uninstall
|
||||||
|
if CurUninstallStep = usUninstall then begin
|
||||||
|
// get list of selected tasks saved in registry at install time
|
||||||
|
appid := '{#emit SetupSetting("AppId")}';
|
||||||
|
if appid = '' then appid := '{#emit SetupSetting("AppName")}';
|
||||||
|
regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1');
|
||||||
|
RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring);
|
||||||
|
if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring);
|
||||||
|
|
||||||
|
// check each task; if matches modpath taskname, trigger patch removal
|
||||||
|
if regstring <> '' then begin
|
||||||
|
taskname := ModPathName;
|
||||||
|
MPExplode(aSelectedTasks, regstring, ',');
|
||||||
|
if GetArrayLength(aSelectedTasks) > 0 then begin
|
||||||
|
for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin
|
||||||
|
if comparetext(aSelectedTasks[i], taskname) = 0 then
|
||||||
|
ModPath();
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function NeedRestart(): Boolean;
|
||||||
|
var
|
||||||
|
taskname: String;
|
||||||
|
begin
|
||||||
|
taskname := ModPathName;
|
||||||
|
if IsTaskSelected(taskname) and not UsingWinNT() then begin
|
||||||
|
Result := True;
|
||||||
|
end else begin
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
end;
|
61
packager/win/setupscript.iss
Normal file
61
packager/win/setupscript.iss
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
; Script generated by the Inno Setup Script Wizard.
|
||||||
|
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
||||||
|
|
||||||
|
#define MyAppName "{{{app_name}}}"
|
||||||
|
#define MyAppVersion "{{{app_version}}}"
|
||||||
|
#define MyAppPublisher "{{{app_publisher}}}"
|
||||||
|
#define MyAppURL "{{{app_url}}}"
|
||||||
|
#define MyAppExeName "espanso.exe"
|
||||||
|
|
||||||
|
[Setup]
|
||||||
|
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
|
||||||
|
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
|
||||||
|
AppId={{0E3D83CE-A644-4E0E-8487-657C7ECF6BF9}
|
||||||
|
AppName={#MyAppName}
|
||||||
|
AppVersion={#MyAppVersion}
|
||||||
|
;AppVerName={#MyAppName} {#MyAppVersion}
|
||||||
|
AppPublisher={#MyAppPublisher}
|
||||||
|
AppPublisherURL={#MyAppURL}
|
||||||
|
AppSupportURL={#MyAppURL}
|
||||||
|
AppUpdatesURL={#MyAppURL}
|
||||||
|
DefaultDirName={autopf}\{#MyAppName}
|
||||||
|
DisableProgramGroupPage=yes
|
||||||
|
LicenseFile="{{{app_license}}}"
|
||||||
|
; Remove the following line to run in administrative install mode (install for all users.)
|
||||||
|
PrivilegesRequired=lowest
|
||||||
|
OutputDir="{{{output_dir}}}"
|
||||||
|
OutputBaseFilename={{{output_name}}}
|
||||||
|
SetupIconFile="{{{app_icon}}}"
|
||||||
|
Compression=lzma
|
||||||
|
SolidCompression=yes
|
||||||
|
WizardStyle=modern
|
||||||
|
ChangesEnvironment=yes
|
||||||
|
|
||||||
|
[Languages]
|
||||||
|
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||||
|
|
||||||
|
[Files]
|
||||||
|
Source: "{{{executable_path}}}"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
|
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||||
|
|
||||||
|
[Icons]
|
||||||
|
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
|
||||||
|
|
||||||
|
[Tasks]
|
||||||
|
Name: modifypath; Description: Add espanso to PATH ( recommended );
|
||||||
|
|
||||||
|
[Code]
|
||||||
|
const
|
||||||
|
ModPathName = 'modifypath';
|
||||||
|
ModPathType = 'user';
|
||||||
|
|
||||||
|
function ModPathDir(): TArrayOfString;
|
||||||
|
begin
|
||||||
|
setArrayLength(Result, 1)
|
||||||
|
Result[0] := ExpandConstant('{app}');
|
||||||
|
end;
|
||||||
|
#include "modpath.iss"
|
||||||
|
|
||||||
|
[Run]
|
||||||
|
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
|
||||||
|
|
Loading…
Reference in New Issue
Block a user