diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 9f05359b6f..43e0e02e0b 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -4380,8 +4380,11 @@ "type": "boolean" }, "unpackDirName": { - "description": "The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\n\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).", - "type": "string" + "description": "The unpack directory for the portable app resources.\nIf set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory.\nIf set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application.\nDefaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable).", + "type": [ + "string", + "boolean" + ] }, "useZip": { "default": false, diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 8ca3365b56..a1816df0ae 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -244,12 +244,18 @@ export class NsisTarget extends Target { this.configureDefinesForAllTypeOfInstaller(defines) if (isPortable) { - const portableOptions = options as PortableOptions - defines.REQUEST_EXECUTION_LEVEL = portableOptions.requestExecutionLevel || "user" - defines.UNPACK_DIR_NAME = portableOptions.unpackDirName || (await executeAppBuilder(["ksuid"])) + const { unpackDirName, requestExecutionLevel, splashImage} = options as PortableOptions + defines.REQUEST_EXECUTION_LEVEL = requestExecutionLevel || "user" + + // https://github.com/electron-userland/electron-builder/issues/5764 + if (typeof unpackDirName === 'string') { + defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) + } else if (unpackDirName !== false) { + defines.UNPACK_DIR_NAME = executeAppBuilder(["ksuid"]) + } - if (portableOptions.splashImage != null) { - defines.SPLASH_IMAGE = path.resolve(packager.projectDir, portableOptions.splashImage) + if (splashImage != null) { + defines.SPLASH_IMAGE = path.resolve(packager.projectDir, splashImage) } } else { await this.configureDefines(oneClick, defines) diff --git a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts index 6a8de5853b..9f45ab266d 100644 --- a/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts +++ b/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts @@ -169,11 +169,14 @@ export interface PortableOptions extends TargetSpecificOptions, CommonNsisOption readonly requestExecutionLevel?: "user" | "highest" | "admin" /** - * The unpack directory name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory. + * The unpack directory for the portable app resources. * + * If set to a string, it will be the name in [TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/) directory + * If set explicitly to `false`, it will use the Windows temp directory ($PLUGINSDIR) that is unique to each launch of the portable application. + * * Defaults to [uuid](https://github.com/segmentio/ksuid) of build (changed on each build of portable executable). */ - readonly unpackDirName?: string + readonly unpackDirName?: string | boolean /** * The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image. diff --git a/packages/app-builder-lib/templates/nsis/portable.nsi b/packages/app-builder-lib/templates/nsis/portable.nsi index e9085494e8..e5436bb0f8 100644 --- a/packages/app-builder-lib/templates/nsis/portable.nsi +++ b/packages/app-builder-lib/templates/nsis/portable.nsi @@ -30,7 +30,11 @@ Section HideWindow !endif - StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}" + StrCpy $INSTDIR "$PLUGINSDIR\app" + !ifdef UNPACK_DIR_NAME + StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}" + !endif + RMDir /r $INSTDIR SetOutPath $INSTDIR @@ -82,6 +86,6 @@ Section ExecWait "$INSTDIR\${APP_EXECUTABLE_FILENAME} $R0" $0 SetErrorLevel $0 - SetOutPath $PLUGINSDIR + SetOutPath $EXEDIR RMDir /r $INSTDIR SectionEnd