From 1a685876841593f4216473983dc3befb973190f2 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 30 Dec 2024 15:07:31 +0800 Subject: [PATCH] fix: Microsoft Visual C++ Redistributable #577 --- build/nsis-installer.nsh | 47 ++++++++++++++++++++++++++++++++++++++++ electron-builder.yml | 1 + 2 files changed, 48 insertions(+) create mode 100644 build/nsis-installer.nsh diff --git a/build/nsis-installer.nsh b/build/nsis-installer.nsh new file mode 100644 index 00000000..75ef5c00 --- /dev/null +++ b/build/nsis-installer.nsh @@ -0,0 +1,47 @@ +;Inspired by: +; https://gist.github.com/bogdibota/062919938e1ed388b3db5ea31f52955c +; https://stackoverflow.com/questions/34177547/detect-if-visual-c-redistributable-for-visual-studio-2013-is-installed +; https://stackoverflow.com/a/54391388 +; https://github.com/GitCommons/cpp-redist-nsis/blob/main/installer.nsh + +;Find latests downloads here: +; https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist + +!include LogicLib.nsh + +; https://github.com/electron-userland/electron-builder/issues/1122 +!ifndef BUILD_UNINSTALLER + Function checkVCRedist + ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed" + FunctionEnd +!endif + +!macro customInit + Push $0 + Call checkVCRedist + ${If} $0 != "1" + MessageBox MB_YESNO "\ + NOTE: ${PRODUCT_NAME} requires $\r$\n\ + 'Microsoft Visual C++ Redistributable'$\r$\n\ + to function properly.$\r$\n$\r$\n\ + Download and install now?" /SD IDYES IDYES InstallVCRedist IDNO DontInstall + InstallVCRedist: + inetc::get /CAPTION " " /BANNER "Downloading Microsoft Visual C++ Redistributable..." "https://aka.ms/vs/17/release/vc_redist.x64.exe" "$TEMP\vc_redist.x64.exe" + ExecWait "$TEMP\vc_redist.x64.exe /install /norestart" + ;IfErrors InstallError ContinueInstall ; vc_redist exit code is unreliable :( + Call checkVCRedist + ${If} $0 == "1" + Goto ContinueInstall + ${EndIf} + + ;InstallError: + MessageBox MB_ICONSTOP "\ + There was an unexpected error installing$\r$\n\ + Microsoft Visual C++ Redistributable.$\r$\n\ + The installation of ${PRODUCT_NAME} cannot continue." + DontInstall: + Abort + ${EndIf} + ContinueInstall: + Pop $0 +!macroend \ No newline at end of file diff --git a/electron-builder.yml b/electron-builder.yml index 49675912..ef0ba20d 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -39,6 +39,7 @@ nsis: createDesktopShortcut: always allowToChangeInstallationDirectory: true oneClick: false + include: build/nsis-installer.nsh mac: entitlementsInherit: build/entitlements.mac.plist notarize: false