From ccae1d655a2e5f834d7c02dcb2f62747498ff36c Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 29 Feb 2020 20:56:47 +0100 Subject: [PATCH] Change Win installer to avoid VC++ Redistributable installation by bundling the required DLLs automatically (local deployment). Fix #189 --- packager.py | 22 +++++++++++++++++++--- packager/win/setupscript.iss | 8 +------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packager.py b/packager.py index 1aa9ae2..8cf1726 100644 --- a/packager.py +++ b/packager.py @@ -7,6 +7,7 @@ import click import shutil import toml import hashlib +import glob import urllib.request from dataclasses import dataclass @@ -79,9 +80,23 @@ def build_windows(package_info): TARGET_DIR = os.path.join(PACKAGER_TARGET_DIR, "win") os.makedirs(TARGET_DIR, exist_ok=True) - print("Downloading Visual C++ redistributable") - vc_redist_file = os.path.join(TARGET_DIR, "vc_redist.x64.exe") - urllib.request.urlretrieve("https://aka.ms/vs/16/release/vc_redist.x64.exe", vc_redist_file) + print("Gathering CRT DLLs...") + msvc_dirs = glob.glob("C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\*\\VC\\Redist\\MSVC\\*") + print("Found Redists: ", msvc_dirs) + + msvc_dir = msvc_dirs[0] + print("Using: ",msvc_dir) + if len(msvc_dir) == 0: + raise Exception("Cannot find redistributable dlls") + dll_files = glob.glob(msvc_dir + "\\x64\\*CRT\\*.dll") + + print("Found DLLs:") + dll_include_list = [] + for dll in dll_files: + print("Including: "+dll) + dll_include_list.append("Source: \""+dll+"\"; DestDir: \"{app}\"; Flags: ignoreversion") + + dll_include = "\r\n".join(dll_include_list) INSTALLER_NAME = f"espanso-win-installer" @@ -102,6 +117,7 @@ def build_windows(package_info): 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) + content = content.replace("{{{dll_include}}}", dll_include) with open(os.path.join(TARGET_DIR, "setupscript.iss"), "w") as output_script: output_script.write(content) diff --git a/packager/win/setupscript.iss b/packager/win/setupscript.iss index 0e24a1b..b177a9d 100644 --- a/packager/win/setupscript.iss +++ b/packager/win/setupscript.iss @@ -30,7 +30,6 @@ Compression=lzma SolidCompression=yes WizardStyle=modern ChangesEnvironment=yes -AlwaysRestart = yes [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" @@ -38,7 +37,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" [Files] Source: "{{{executable_path}}}"; DestDir: "{app}"; Flags: ignoreversion Source: "{{{app_icon}}}"; DestDir: "{app}"; Flags: ignoreversion -Source: "vc_redist.x64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall +{{{dll_include}}} ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] @@ -53,18 +52,13 @@ Name: "StartMenuEntry" ; Description: "Start espanso at Windows startup" ; const ModPathName = 'modifypath'; ModPathType = 'user'; - function ModPathDir(): TArrayOfString; begin setArrayLength(Result, 1) Result[0] := ExpandConstant('{app}'); end; #include "modpath.iss" - [Run] -Filename: {tmp}\vc_redist.x64.exe; \ - Parameters: "/install /quiet /norestart"; \ - StatusMsg: "Installing Visual C++ 2019 Redistributable"; Filename: "{app}\{#MyAppExeName}"; Parameters: "start"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent [UninstallRun]