Change Win installer to avoid VC++ Redistributable installation by bundling the required DLLs automatically (local deployment). Fix #189
This commit is contained in:
		
							parent
							
								
									17fae78c8d
								
							
						
					
					
						commit
						ccae1d655a
					
				
							
								
								
									
										22
									
								
								packager.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user