Skip to content

Commit

Permalink
Allowing boolean flag to unpackDirName to utilize $PLUGINSDIR (unique…
Browse files Browse the repository at this point in the history
… to each portable app launch) when set explicitly to false. Implements electron-userland#5764, electron-userland#5382, electron-userland#4105
  • Loading branch information
mmaietta committed Apr 15, 2021
1 parent 66f01bb commit 4a5f21e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/app-builder-lib/scheme.json
Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/nsisOptions.ts
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions packages/app-builder-lib/templates/nsis/portable.nsi
Expand Up @@ -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

Expand Down Expand Up @@ -82,6 +86,6 @@ Section
ExecWait "$INSTDIR\${APP_EXECUTABLE_FILENAME} $R0" $0
SetErrorLevel $0

SetOutPath $PLUGINSDIR
SetOutPath $EXEDIR
RMDir /r $INSTDIR
SectionEnd

0 comments on commit 4a5f21e

Please sign in to comment.