diff --git a/bun.lock b/bun.lock index 92f21bf7d60..f85fab3a0ed 100644 --- a/bun.lock +++ b/bun.lock @@ -1055,6 +1055,7 @@ "patchedDependencies": { "@pierre/trees@1.0.0-beta.4": "patches/@pierre%2Ftrees@1.0.0-beta.4.patch", "@tanstack/virtual-core@3.17.8": "patches/@tanstack%2Fvirtual-core@3.17.8.patch", + "electron-updater@6.8.9": "patches/electron-updater@6.8.9.patch", "ghostty-web@github:anomalyco/ghostty-web#83c0a07": "patches/ghostty-web@0.3.0.patch", "@modelcontextprotocol/client@2.0.0": "patches/@modelcontextprotocol%2Fclient@2.0.0.patch", "pacote@21.5.1": "patches/pacote@21.5.1.patch", @@ -1063,6 +1064,7 @@ "solid-js@1.9.15": "patches/solid-js@1.9.15.patch", "vite@8.2.2": "patches/vite@8.2.2.patch", "@ff-labs/fff-bun@0.10.5": "patches/@ff-labs%2Ffff-bun@0.10.5.patch", + "app-builder-lib@26.15.7": "patches/app-builder-lib@26.15.7.patch", "@corvu/drawer@0.2.4": "patches/@corvu%2Fdrawer@0.2.4.patch", "@dnd-kit/dom@0.5.0": "patches/@dnd-kit%2Fdom@0.5.0.patch", "@ai-sdk/openai-compatible@2.0.41": "patches/@ai-sdk%2Fopenai-compatible@2.0.41.patch", diff --git a/package.json b/package.json index df4a41504ad..1073a9e3984 100644 --- a/package.json +++ b/package.json @@ -185,6 +185,8 @@ "ghostty-web@github:anomalyco/ghostty-web#83c0a07": "patches/ghostty-web@0.3.0.patch", "vite@8.2.2": "patches/vite@8.2.2.patch", "@modelcontextprotocol/client@2.0.0": "patches/@modelcontextprotocol%2Fclient@2.0.0.patch", - "@corvu/drawer@0.2.4": "patches/@corvu%2Fdrawer@0.2.4.patch" + "@corvu/drawer@0.2.4": "patches/@corvu%2Fdrawer@0.2.4.patch", + "app-builder-lib@26.15.7": "patches/app-builder-lib@26.15.7.patch", + "electron-updater@6.8.9": "patches/electron-updater@6.8.9.patch" } } diff --git a/packages/desktop/resources/windows/installer.nsh b/packages/desktop/resources/windows/installer.nsh index 5487b3a23e3..6c994e5d5d3 100644 --- a/packages/desktop/resources/windows/installer.nsh +++ b/packages/desktop/resources/windows/installer.nsh @@ -4,3 +4,174 @@ nsExec::ExecToLog '"$SYSDIR\icacls.exe" "$INSTDIR" /grant "*S-1-15-2-2:(OI)(CI)(RX)"' Pop $0 !macroend + +!macro customUnInstall + ${IfNot} ${isUpdated} + !insertmacro removeStagedUpdates $INSTDIR + ${EndIf} +!macroend + +; The stock check starts Windows PowerShell up to five times per installer and again in the old +; uninstaller, about 1.2 s each. This walks the process list in-process instead and keeps the stock +; behaviour: stop every process whose image lives under $INSTDIR. An update gives the quitting app +; 10 s to exit on its own; a manual install asks first, then stops it at once. +!macro customCheckAppRunning + System::Call "kernel32::GetCurrentProcessId() i .R9" + ; $R8 is the tick count after which processes still running are terminated. + System::Call "kernel32::GetTickCount() i .R8" + IntOp $R8 $R8 + 10000 + StrCpy $0 "" + + ${Do} + System::Call "kernel32::GetTickCount() i .r1" + IntOp $1 $1 - $R8 + StrCpy $R7 0 + System::Call "kernel32::CreateToolhelp32Snapshot(i 2, i 0) p .R0" + ${If} $R0 <> -1 + ; PROCESSENTRY32W for the 32-bit installer: nine 4-byte fields, then WCHAR szExeFile[260]. + System::Alloc 556 + Pop $R1 + System::Call "*$R1(i 556)" + System::Call "kernel32::Process32FirstW(p R0, p R1) i .R2" + ${DoWhile} $R2 != 0 + System::Call "*$R1(i, i, i .R3)" + ${If} $R3 != $R9 + System::Call "kernel32::OpenProcess(i 0x1000, i 0, i R3) p .R4" + ${If} $R4 != 0 + System::Call "kernel32::QueryFullProcessImageNameW(p R4, i 0, w .R5, *i ${NSIS_MAX_STRLEN}) i .R6" + System::Call "kernel32::CloseHandle(p R4)" + ${If} $R6 != 0 + StrLen $R6 "$INSTDIR\" + StrCpy $R5 $R5 $R6 + ${If} $R5 == "$INSTDIR\" + IntOp $R7 $R7 + 1 + ${If} $1 >= 0 + System::Call "kernel32::OpenProcess(i 1, i 0, i R3) p .R4" + ${If} $R4 != 0 + System::Call "kernel32::TerminateProcess(p R4, i 1)" + System::Call "kernel32::CloseHandle(p R4)" + ${EndIf} + ${EndIf} + ${EndIf} + ${EndIf} + ${EndIf} + ${EndIf} + System::Call "kernel32::Process32NextW(p R0, p R1) i .R2" + ${Loop} + System::Free $R1 + System::Call "kernel32::CloseHandle(p R0)" + ${EndIf} + + ${If} $R7 == 0 + ${ExitDo} + ${EndIf} + + ${If} $0 == "" + StrCpy $0 "running" + ${IfNot} ${isUpdated} + ${If} ${Cmd} `MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$(appRunning)" /SD IDOK IDCANCEL` + Quit + ${EndIf} + System::Call "kernel32::GetTickCount() i .R8" + ${EndIf} + DetailPrint "$(appClosing)" + ${ElseIf} $1 >= 2000 + ${If} ${Cmd} `MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)" /SD IDCANCEL IDCANCEL` + Quit + ${EndIf} + System::Call "kernel32::GetTickCount() i .R8" + ${EndIf} + + Sleep 100 + ${Loop} +!macroend + +; Staged updates. Once an update has downloaded, the running app starts its installer with --stage. +; That unpacks the app next to the install directory, as ".update-", +; while the user keeps working. After the restart, the install renames that directory into place +; instead of decompressing 700 MB. Anything unexpected falls back to the normal extraction. +!macro removeStagedUpdates DIR + RMDir /r "${DIR}.staging" + ${StdUtils.GetParentPath} $R8 "${DIR}" + FindFirst $R9 $R7 "${DIR}.update-*" + ${DoWhile} $R7 != "" + RMDir /r "$R8\$R7" + FindNext $R9 $R7 + ${Loop} + FindClose $R9 +!macroend + +!ifndef BUILD_UNINSTALLER +!ifdef APP_64 | APP_ARM64 + !ifdef APP_64 & APP_ARM64 + !error "Staged updates expect one architecture per installer" + !endif + !ifdef APP_ARM64 + !define STAGED_PACKAGE "${APP_ARM64}" + !define STAGED_PACKAGE_HASH "${APP_ARM64_HASH}" + !define STAGED_PACKAGE_SIZE "${APP_ARM64_UNPACKED_SIZE}" + !else + !define STAGED_PACKAGE "${APP_64}" + !define STAGED_PACKAGE_HASH "${APP_64_HASH}" + !define STAGED_PACKAGE_SIZE "${APP_64_UNPACKED_SIZE}" + !endif + + ; Runs first in .onInit, before the single-instance check, and exits 0 only when it staged. + !macro preInit + ${StdUtils.TestParameter} $R0 "stage" + ${If} $R0 == "true" + SetErrorLevel 2 + ReadRegStr $R1 HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation + ; Leave room for the staged copy and as much again, in MB. + ${DriveSpace} "$R1" "/D=F /S=M" $R2 + IntOp $R3 ${STAGED_PACKAGE_SIZE} / 512 + ${If} $R1 != "" + ${AndIf} ${FileExists} "$R1\${APP_EXECUTABLE_FILENAME}" + ${AndIf} $R2 > $R3 + !insertmacro removeStagedUpdates $R1 + InitPluginsDir + ; Stored like the template's copy, so the installer keeps one copy of the payload. + !ifdef COMPRESS + SetCompress off + !endif + File /oname=$PLUGINSDIR\staged.7z "${STAGED_PACKAGE}" + !ifdef COMPRESS + SetCompress "${COMPRESS}" + !endif + ClearErrors + SetOutPath "$R1.staging" + ${IfNot} ${Errors} + Nsis7z::Extract "$PLUGINSDIR\staged.7z" + SetOutPath $PLUGINSDIR + StrCpy $R4 "${STAGED_PACKAGE_HASH}" 16 + ClearErrors + Rename "$R1.staging" "$R1.update-$R4" + ${IfNot} ${Errors} + SetErrorLevel 0 + ${EndIf} + ${EndIf} + ${EndIf} + Quit + ${EndIf} + !macroend + + ; Called by the patched app-builder-lib template in place of extraction. Sets $R0 to "installed" + ; when it moved the staged app into the empty install directory. + !macro customInstallStagedApp + StrCpy $R0 "" + StrCpy $R1 "${STAGED_PACKAGE_HASH}" 16 + ${If} ${FileExists} "$INSTDIR.update-$R1\${APP_EXECUTABLE_FILENAME}" + SetOutPath $PLUGINSDIR + ; Removes the directory only while it is empty, so the rename never mixes two versions. + RMDir $INSTDIR + ClearErrors + Rename "$INSTDIR.update-$R1" $INSTDIR + ${IfNot} ${Errors} + StrCpy $R0 "installed" + ${EndIf} + SetOutPath $INSTDIR + ${EndIf} + !insertmacro removeStagedUpdates $INSTDIR + !macroend +!endif +!endif diff --git a/packages/desktop/scripts/windows-installer.test.ts b/packages/desktop/scripts/windows-installer.test.ts index e4f64fd0a8e..137569b3167 100644 --- a/packages/desktop/scripts/windows-installer.test.ts +++ b/packages/desktop/scripts/windows-installer.test.ts @@ -1,36 +1,89 @@ import { expect, test } from "bun:test" -import { mkdtemp, rm } from "node:fs/promises" +import { copyFile, mkdir, mkdtemp, readdir, rm } from "node:fs/promises" import os from "node:os" import path from "node:path" -test.skipIf(process.platform !== "win32")( +const windows = test.skipIf(process.platform !== "win32") + +// Matches the 16 hex characters the staged directory name takes from APP_64_HASH. +const payloadHash = "0123456789ABCDEF0123456789ABCDEF" + +async function harness() { + const { getMakeNsisPath, getNsisPluginsPath } = await import("app-builder-lib/out/toolsets/windows") + const { nsisTemplatesDir } = await import("app-builder-lib/out/targets/nsis/nsisUtil") + const { NsisScriptGenerator } = await import("app-builder-lib/out/targets/nsis/nsisScriptGenerator") + const config = (await import("../electron-builder.config")).default + const compiler = await getMakeNsisPath(config.toolsets?.nsis, config.nsis?.customNsisBinary) + const plugins = await getNsisPluginsPath(config.toolsets?.nsis, config.nsis?.customNsisResources) + const dir = await mkdtemp(path.join(os.tmpdir(), "opencode-installer-")) + // electron-builder generates the command-line flags such as ${isUpdated}. + const flags = new NsisScriptGenerator() + flags.flags(["updated"]) + + const run = async (cmd: string[], env: Record = {}) => { + const result = Bun.spawn(cmd, { env: { ...process.env, ...compiler.env, ...env }, stdout: "pipe", stderr: "pipe" }) + + const [stdout, stderr, code] = await Promise.all([ + new Response(result.stdout).text(), + new Response(result.stderr).text(), + result.exited, + ]) + + return { stdout: stdout.trim(), stderr, code } + } + + // Compiles the custom include with the template's flags and messages around one section body. + const compile = async (name: string, section: string) => { + const script = path.join(dir, `${name}.nsi`) + const exe = path.join(dir, `${name}.exe`) + await Bun.write( + script, + `Unicode true +RequestExecutionLevel user +SilentInstall silent +OutFile "${exe}" +!addplugindir /x86-unicode "${path.join(plugins, "x86-unicode")}" +!addincludedir "${path.join(nsisTemplatesDir, "include")}" +!include LogicLib.nsh +!include StdUtils.nsh +${flags.build()} +LoadLanguageFile "\${NSISDIR}\\Contrib\\Language files\\English.nlf" +LangString appRunning \${LANG_ENGLISH} "running" +LangString appClosing \${LANG_ENGLISH} "closing" +LangString appCannotBeClosed \${LANG_ENGLISH} "cannot close" +!define APP_EXECUTABLE_FILENAME "OpenCode.exe" +!define APP_64 "${path.join(dir, "app.7z")}" +!define APP_64_HASH "${payloadHash}" +!define APP_64_UNPACKED_SIZE 1 +!include "${config.nsis?.include}" +Section +${section} +SectionEnd +`, + ) + const result = await run([compiler.path, script]) + expect(result.code, `${result.stdout}\n${result.stderr}`).toBe(0) + + return exe + } + + return { dir, run, compile, cleanup: () => rm(dir, { recursive: true, force: true }) } +} + +windows( "installer grants sandbox access without changing unrelated permissions", async () => { - const { getMakeNsisPath } = await import("app-builder-lib/out/toolsets/windows") - const config = (await import("../electron-builder.config")).default - const compiler = await getMakeNsisPath(config.toolsets?.nsis, config.nsis?.customNsisBinary) - const dir = await mkdtemp(path.join(os.tmpdir(), "opencode-installer-")) + const installer = await harness() - const run = async (cmd: string[]) => { - const result = Bun.spawn(cmd, { - env: { ...process.env, ...compiler.env, OPENCODE_INSTALLER_TEST_ROOT: dir }, - stdout: "pipe", - stderr: "pipe", - }) + const succeed = async (cmd: string[]) => { + const result = await installer.run(cmd, { OPENCODE_INSTALLER_TEST_ROOT: installer.dir }) + expect(result.code, `${result.stdout}\n${result.stderr}`).toBe(0) - const [stdout, stderr, code] = await Promise.all([ - new Response(result.stdout).text(), - new Response(result.stderr).text(), - result.exited, - ]) - - expect(code, `${stdout}\n${stderr}`).toBe(0) - - return stdout.trim() + return result.stdout } const acl = (file: string) => - run([ + succeed([ "pwsh", "-NoProfile", "-NonInteractive", @@ -39,35 +92,158 @@ test.skipIf(process.platform !== "win32")( ]) try { - await Bun.write(path.join(dir, "app/runtime/icudtl.dat"), "runtime fixture") - await Bun.write(path.join(dir, "unrelated.txt"), "outside the installation") - await run(["icacls.exe", path.join(dir, "app"), "/grant", "*S-1-15-2-999-999-999:(OI)(CI)(F)"]) + await Bun.write(path.join(installer.dir, "app/runtime/icudtl.dat"), "runtime fixture") + await Bun.write(path.join(installer.dir, "unrelated.txt"), "outside the installation") + await succeed(["icacls.exe", path.join(installer.dir, "app"), "/grant", "*S-1-15-2-999-999-999:(OI)(CI)(F)"]) const parent = await acl(".") const unrelated = await acl("unrelated.txt") - await Bun.write( - path.join(dir, "installer.nsi"), - `Unicode true -RequestExecutionLevel user -SilentInstall silent -OutFile "${path.join(dir, "installer.exe")}" -!include "${config.nsis?.include}" -Section - StrCpy $INSTDIR "$EXEDIR\\app" - !insertmacro customInstall -SectionEnd -`, + + const exe = await installer.compile( + "acl", + ` StrCpy $INSTDIR "$EXEDIR\\app" + !insertmacro customInstall`, ) - await run([compiler.path, path.join(dir, "installer.nsi")]) - await run([path.join(dir, "installer.exe")]) + + await succeed([exe]) const installed = await acl("app/runtime/icudtl.dat") expect(installed).toContain("(A;ID;0x1200a9;;;S-1-15-2-2)") expect(installed).toContain("S-1-15-2-999-999-999") - await run([path.join(dir, "installer.exe")]) + await succeed([exe]) expect(await acl("app/runtime/icudtl.dat")).toBe(installed) expect(await acl(".")).toBe(parent) expect(await acl("unrelated.txt")).toBe(unrelated) } finally { - await rm(dir, { recursive: true, force: true }) + await installer.cleanup() + } + }, + 120_000, +) + +// The running app unpacks an update beside the install directory before the restart. The install takes it +// only when it belongs to this payload and the old version is gone, and never leaves a staged copy behind. +const stagedCases = [ + { + name: "moves the staged app into the emptied install directory", + installed: [], + staged: { [`update-${payloadHash.slice(0, 16)}`]: ["OpenCode.exe", "resources/app.asar"] }, + moved: true, + expected: ["OpenCode.exe", "resources/app.asar"], + }, + { + name: "keeps an install directory that still holds files", + installed: ["locked.dll"], + staged: { [`update-${payloadHash.slice(0, 16)}`]: ["OpenCode.exe"] }, + moved: false, + expected: ["locked.dll"], + }, + { + name: "discards an update staged from another payload", + installed: [], + staged: { "update-FEDCBA9876543210": ["OpenCode.exe"] }, + moved: false, + expected: [], + }, + { + name: "discards staging that never finished", + installed: [], + staged: { staging: ["OpenCode.exe"] }, + moved: false, + expected: [], + }, +] + +windows( + "installs a staged update only into an emptied install directory", + async () => { + const installer = await harness() + + try { + const exe = await installer.compile( + "staged", + ` InitPluginsDir + SetOutPath $INSTDIR + !insertmacro customInstallStagedApp + \${If} $R0 == "installed" + SetErrorLevel 0 + \${Else} + SetErrorLevel 3 + \${EndIf}`, + ) + + for (const item of stagedCases) { + const root = path.join(installer.dir, item.name.replaceAll(" ", "-")) + const install = path.join(root, "app") + await mkdir(install, { recursive: true }) + await Promise.all([ + ...item.installed.map((file) => Bun.write(path.join(install, file), "old")), + ...Object.entries(item.staged).flatMap(([suffix, files]) => + files.map((file) => Bun.write(path.join(`${install}.${suffix}`, file), "new")), + ), + ]) + + const result = await installer.run([exe, `/D=${install}`]) + const files = await readdir(install, { recursive: true, withFileTypes: true }) + + expect(result.code, item.name).toBe(item.moved ? 0 : 3) + expect( + files + .filter((entry) => entry.isFile()) + .map((entry) => path.relative(install, path.join(entry.parentPath, entry.name)).replaceAll("\\", "/")) + .toSorted(), + item.name, + ).toEqual(item.expected) + expect(await readdir(root), item.name).toEqual(["app"]) + } + } finally { + await installer.cleanup() + } + }, + 120_000, +) + +// Stand-ins for the app are copies of ping.exe: it exits with 0 when it finishes and 1 when terminated. +const runningCases = [ + { name: "a manual install stops the app at once", args: [], pings: 30, exitCode: 1 }, + { name: "an update lets the quitting app exit by itself", args: ["--updated"], pings: 2, exitCode: 0 }, +] + +windows( + "stops only the processes that run from the install directory", + async () => { + const installer = await harness() + const ping = path.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "PING.EXE") + + try { + const exe = await installer.compile("running", " !insertmacro customCheckAppRunning") + + for (const item of runningCases) { + const root = path.join(installer.dir, item.name.replaceAll(" ", "-")) + const install = path.join(root, "app") + // Shares the install directory's name as a prefix, so a match without the separator would stop it. + const sibling = path.join(root, "app-sibling") + await mkdir(path.join(install, "resources"), { recursive: true }) + await mkdir(sibling, { recursive: true }) + await copyFile(ping, path.join(install, "resources", "standin.exe")) + await copyFile(ping, path.join(sibling, "standin.exe")) + + const app = Bun.spawn([path.join(install, "resources", "standin.exe"), "-n", String(item.pings), "127.0.0.1"], { + stdout: "ignore", + }) + + const other = Bun.spawn([path.join(sibling, "standin.exe"), "-n", "30", "127.0.0.1"], { stdout: "ignore" }) + + try { + expect((await installer.run([exe, ...item.args, `/D=${install}`])).code, item.name).toBe(0) + expect(other.exitCode, item.name).toBeNull() + expect(await app.exited, item.name).toBe(item.exitCode) + } finally { + app.kill() + other.kill() + await Promise.all([app.exited, other.exited]) + } + } + } finally { + await installer.cleanup() } }, 120_000, diff --git a/packages/gui-extensions/src/updater/platform.ts b/packages/gui-extensions/src/updater/platform.ts index 047c13eb0db..e562c5a0db4 100644 --- a/packages/gui-extensions/src/updater/platform.ts +++ b/packages/gui-extensions/src/updater/platform.ts @@ -1,3 +1,5 @@ +import { execFile } from "node:child_process" +import { promisify } from "node:util" import { app, autoUpdater } from "electron" import pkg from "electron-updater" import { Effect } from "effect" @@ -5,8 +7,12 @@ import type { Platform } from "./machine" const updateClient = pkg.autoUpdater +const execFileAsync = promisify(execFile) + const restartTimeout = 10_000 +const unpackTimeout = 120_000 + export const make = Effect.fn("Updater.platform")(function* (channel: string) { const userAgent = `opencode/${channel === "prod" ? "latest" : channel}/${app.getVersion()}/desktop` const runFork = Effect.runForkWith(yield* Effect.context()) @@ -70,7 +76,7 @@ function stageUpdate(options: { readonly differential: boolean }) { return updateClient.downloadUpdate() }, catch: (error) => error, - }).pipe(Effect.asVoid) + }).pipe(Effect.flatMap(unpackInstaller)) return Effect.callback((resume) => { const cleanup = () => { @@ -96,6 +102,27 @@ function stageUpdate(options: { readonly differential: boolean }) { }) } +// The NSIS installer unpacks the update beside the install directory while the app keeps running, so the +// install after the restart moves one directory into place instead of decompressing the whole app. When this +// fails, the restart still installs the update, only slower. +function unpackInstaller(files: string[]) { + const installer = files.find((file) => file.endsWith(".exe")) + + if (process.platform !== "win32" || !app.isPackaged || !installer) return Effect.void + + return Effect.tryPromise(() => + execFileAsync(installer, ["--stage"], { windowsHide: true, timeout: unpackTimeout }), + ).pipe( + Effect.andThen(Effect.logInfo("update unpacked before restart", { installer })), + Effect.catch((error) => + Effect.logWarning("update not unpacked before restart", { + installer, + message: error.cause instanceof Error ? error.cause.message : String(error.cause), + }), + ), + ) +} + const installAndRestart = Effect.callback((resume) => { const cleanup = () => { autoUpdater.removeListener("before-quit-for-update", started) diff --git a/patches/app-builder-lib@26.15.7.patch b/patches/app-builder-lib@26.15.7.patch new file mode 100644 index 00000000000..11252d4c7ac --- /dev/null +++ b/patches/app-builder-lib@26.15.7.patch @@ -0,0 +1,70 @@ +diff --git a/templates/nsis/include/extractAppPackage.nsh b/templates/nsis/include/extractAppPackage.nsh +index f5470bf52e923dc47266cea4684c76ef78ced451..6c4a4c193a2ca1dc2413482606b9be5c1c2aa1a9 100644 +--- a/templates/nsis/include/extractAppPackage.nsh ++++ b/templates/nsis/include/extractAppPackage.nsh +@@ -1,4 +1,11 @@ + !macro extractEmbeddedAppPackage ++ # OpenCode: the custom include can install an update the running app already unpacked, and sets ++ # $R0 to "installed" when it did. ++ !ifmacrodef customInstallStagedApp ++ !insertmacro customInstallStagedApp ++ StrCmp $R0 "installed" extractEmbeddedAppPackageDone ++ !endif ++ + !ifdef COMPRESS + SetCompress off + !endif +@@ -13,6 +20,10 @@ + !endif + + !insertmacro decompress ++ ++ !ifmacrodef customInstallStagedApp ++ extractEmbeddedAppPackageDone: ++ !endif + !insertmacro custom_files_post_decompression + !macroend + +@@ -90,6 +101,15 @@ + !macroend + + !macro extractUsing7za FILE ++ # OpenCode: extract straight into an empty install directory. The copy through $PLUGINSDIR below ++ # only protects files that a running old version still holds, and an empty directory has none, ++ # so it would write the whole app a second time and delete it again on exit. ++ ${DirState} $OUTDIR $R0 ++ ${if} $R0 != 1 ++ Nsis7z::Extract "${FILE}" ++ Goto DoneExtract7za ++ ${endIf} ++ + Push $OUTDIR + CreateDirectory "$PLUGINSDIR\7z-out" + ClearErrors +diff --git a/templates/nsis/include/installer.nsh b/templates/nsis/include/installer.nsh +index 300ef3dd699d0f5a081b1934fcc22dbe12025bdb..6bc1c7f368208024c52aff9ae53f299ce4b632f3 100644 +--- a/templates/nsis/include/installer.nsh ++++ b/templates/nsis/include/installer.nsh +@@ -90,7 +90,21 @@ + ${if} $installMode == "all" + SetShellVarContext current + ${endif} +- !insertmacro copyFile "$EXEPATH" "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}" ++ # OpenCode: an update runs from the updater's pending download next to this cache file, so hard ++ # link it instead of copying a few hundred MB. The updater replaces that download rather than ++ # rewriting it, so the link never changes under the cache. ++ ${StdUtils.GetParentPath} $R5 "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}" ++ StrLen $R6 "$R5\" ++ StrCpy $R6 $EXEPATH $R6 ++ ${if} $R6 == "$R5\" ++ Delete "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}" ++ System::Call 'kernel32::CreateHardLinkW(w "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}", w "$EXEPATH", p 0) i .R6' ++ ${else} ++ StrCpy $R6 0 ++ ${endIf} ++ ${if} $R6 == 0 ++ !insertmacro copyFile "$EXEPATH" "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}" ++ ${endIf} + ${if} $installMode == "all" + SetShellVarContext all + ${endif} diff --git a/patches/electron-updater@6.8.9.patch b/patches/electron-updater@6.8.9.patch new file mode 100644 index 00000000000..28338f7b8b5 --- /dev/null +++ b/patches/electron-updater@6.8.9.patch @@ -0,0 +1,15 @@ +diff --git a/out/NsisUpdater.js b/out/NsisUpdater.js +index 6fb70b4275a59741d28aecc389c2736909130a3e..498e59ebbeb5e8648a6363b782d1a9d3ef63a8e7 100644 +--- a/out/NsisUpdater.js ++++ b/out/NsisUpdater.js +@@ -104,7 +104,9 @@ class NsisUpdater extends BaseUpdater_1.BaseUpdater { + this.dispatchError(new Error("No update filepath provided, can't quit and install")); + return false; + } +- const args = ["--updated"]; ++ // OpenCode: skip NSIS's CRC check of the whole installer, about 0.5 s for 230 MB. The updater already verified ++ // the download's SHA-512; manual installs keep the check. Must come before /D=. ++ const args = ["--updated", "/NCRC"]; + if (options.isSilent) { + args.push("/S"); + }