From f1d97ac8348de44cb0a29eb38b050898d390fa9c Mon Sep 17 00:00:00 2001 From: Minh141120 Date: Tue, 23 Sep 2025 20:42:34 +0700 Subject: [PATCH] chore: install vc_redist.x64 from script --- scripts/download-lib.mjs | 19 ++++++++++++++ src-tauri/tauri.windows.conf.json | 2 +- src-tauri/windows/hooks.nsh | 42 +++++++++++++------------------ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/scripts/download-lib.mjs b/scripts/download-lib.mjs index d2086b36e..ab73b8d79 100644 --- a/scripts/download-lib.mjs +++ b/scripts/download-lib.mjs @@ -77,6 +77,25 @@ async function main() { // Expect EEXIST error } + // Download VC++ Redistributable 17 + if (platform == 'win32') { + const vcFilename = 'vc_redist.x64.exe' + const vcUrl = 'https://aka.ms/vs/17/release/vc_redist.x64.exe' + + console.log(`Downloading VC++ Redistributable...`) + const vcSavePath = path.join(tempDir, vcFilename) + if (!fs.existsSync(vcSavePath)) { + await download(vcUrl, vcSavePath) + } + + // copy to tauri resources + try { + copySync(vcSavePath, resourcesDir) + } catch (err) { + // Expect EEXIST error + } + } + console.log('Downloads completed.') } diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 664053705..16cb9b10a 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -1,7 +1,7 @@ { "bundle": { "targets": ["nsis"], - "resources": ["resources/pre-install/**/*", "resources/lib/vulkan-1.dll", "resources/LICENSE"], + "resources": ["resources/pre-install/**/*", "resources/lib/vulkan-1.dll", "resources/lib/vc_redist.x64.exe", "resources/LICENSE"], "externalBin": ["resources/bin/bun", "resources/bin/uv"], "windows": { "nsis": { diff --git a/src-tauri/windows/hooks.nsh b/src-tauri/windows/hooks.nsh index 60aec1c80..5e1a32141 100644 --- a/src-tauri/windows/hooks.nsh +++ b/src-tauri/windows/hooks.nsh @@ -8,37 +8,31 @@ ${If} $0 == "" ; VC++ Redistributable not found, need to install - DetailPrint "Visual C++ Redistributable not found, downloading and installing..." - - ; Download VC++ Redistributable - Delete "$TEMP\vc_redist.x64.exe" - DetailPrint "Downloading Visual C++ Redistributable..." - NSISdl::download "https://aka.ms/vs/17/release/vc_redist.x64.exe" "$TEMP\vc_redist.x64.exe" - Pop $1 - - ${If} $1 == "success" - DetailPrint "Visual C++ Redistributable download successful" - - ; Install VC++ Redistributable silently + DetailPrint "Visual C++ Redistributable not found, installing from bundled file..." + + ; Install from bundled EXE if not installed + ${If} ${FileExists} "$INSTDIR\resources\lib\vc_redist.x64.exe" DetailPrint "Installing Visual C++ Redistributable..." - ExecWait '"$TEMP\vc_redist.x64.exe" /quiet /norestart' $2 - - ${If} $2 == 0 + ; Copy to TEMP folder and then execute installer + CopyFiles "$INSTDIR\resources\lib\vc_redist.x64.exe" "$TEMP\vc_redist.x64.exe" + ExecWait '"$TEMP\vc_redist.x64.exe" /quiet /norestart' $1 + + ; Check whether installation process exited successfully (code 0) or not + ${If} $1 == 0 DetailPrint "Visual C++ Redistributable installed successfully" - ${ElseIf} $2 == 1638 + ${ElseIf} $1 == 1638 DetailPrint "Visual C++ Redistributable already installed (newer version)" - ${ElseIf} $2 == 3010 + ${ElseIf} $1 == 3010 DetailPrint "Visual C++ Redistributable installed successfully (restart required)" ${Else} - DetailPrint "Visual C++ installation failed with exit code: $2" - MessageBox MB_ICONEXCLAMATION "Visual C++ installation failed. Some features may not work." + DetailPrint "Visual C++ installation failed with exit code: $1" ${EndIf} - - ; Clean up downloaded file + + ; Clean up setup files from TEMP and your installed app Delete "$TEMP\vc_redist.x64.exe" + Delete "$INSTDIR\resources\lib\vc_redist.x64.exe" ${Else} - DetailPrint "Failed to download Visual C++ Redistributable: $1" - MessageBox MB_ICONEXCLAMATION "Failed to download Visual C++ Redistributable. Some features may not work." + DetailPrint "Visual C++ Redistributable not found at expected location: $INSTDIR\resources\lib\vc_redist.x64.exe" ${EndIf} ${Else} DetailPrint "Visual C++ Redistributable already installed (version: $0)" @@ -57,7 +51,7 @@ ; Optional cleanup - remove from resources folder Delete "$INSTDIR\resources\lib\vulkan-1.dll" - ; Only remove the lib directory if it's empty + ; Only remove the lib directory if it's empty after removing both files RMDir "$INSTDIR\resources\lib" ${Else} DetailPrint "vulkan-1.dll not found at expected location: $INSTDIR\resources\lib\vulkan-1.dll"