diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index a9afab352b..4ebba1ecc0 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -4401,8 +4401,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 9908040e1a..8fcf0c1ebf 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -247,12 +247,16 @@ 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" - if (portableOptions.splashImage != null) { - defines.SPLASH_IMAGE = path.resolve(packager.projectDir, portableOptions.splashImage) + // https://github.com/electron-userland/electron-builder/issues/5764 + if (typeof unpackDirName === "string" || !unpackDirName) { + defines.UNPACK_DIR_NAME = unpackDirName || (await executeAppBuilder(["ksuid"])) + } + + 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..4aada863fe 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 diff --git a/test/src/windows/portableTest.ts b/test/src/windows/portableTest.ts index ca3ef42397..e3d201df51 100644 --- a/test/src/windows/portableTest.ts +++ b/test/src/windows/portableTest.ts @@ -39,6 +39,7 @@ test.ifAll.ifNotCi( publish: null, portable: { useZip: true, + unpackDirName: false, }, compression: "store", }, @@ -57,6 +58,7 @@ test.ifNotCiMac( installerIcon: "foo test space.ico", }, portable: { + unpackDirName: true, requestExecutionLevel: "admin", //tslint:disable-next-line:no-invalid-template-strings artifactName: "${productName}Portable.${version}.${ext}",