Skip to content

Commit

Permalink
feat(nsis): option to delete app data on manual uninstall
Browse files Browse the repository at this point in the history
Close #885
  • Loading branch information
develar committed Feb 14, 2017
1 parent 7ed9d7a commit 2e1b21e
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 111 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<a name=""></a>
# [](https://github.com/electron-userland/electron-builder/compare/v13.5.0...v) (2017-02-13)


### Bug Fixes

* Incorrect error message ([bc0952e](https://github.com/electron-userland/electron-builder/commit/bc0952e)), closes [#1236](https://github.com/electron-userland/electron-builder/issues/1236)
* **deployment:** NSIS Web Installer update info is not generated #1207 ([9f7c825](https://github.com/electron-userland/electron-builder/commit/9f7c825))
* **electron-updater:** Github Update Fails Due to Undefined ([591873a](https://github.com/electron-userland/electron-builder/commit/591873a)), closes [#1228](https://github.com/electron-userland/electron-builder/issues/1228)
* **nsis:** Custom NSIS Script !include could not find nsh file ([3fbf113](https://github.com/electron-userland/electron-builder/commit/3fbf113)), closes [#1239](https://github.com/electron-userland/electron-builder/issues/1239)


### Features

* **electron-updater:** include full GitHub request url in the error message ([a7d2992](https://github.com/electron-userland/electron-builder/commit/a7d2992))
* **linux:** assert that linux.icon is a directory ([5352b8c](https://github.com/electron-userland/electron-builder/commit/5352b8c)), closes [#1242](https://github.com/electron-userland/electron-builder/issues/1242)
* --config option ([472ef7e](https://github.com/electron-userland/electron-builder/commit/472ef7e)), closes [#1229](https://github.com/electron-userland/electron-builder/issues/1229)
* --config option ([a9f2ad8](https://github.com/electron-userland/electron-builder/commit/a9f2ad8))



**Here changelog only for previous major releases.**
To see changes for current major release, please use [GiHub releases](https://github.com/electron-userland/electron-builder/releases).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A complete solution to package and build a ready for distribution Electron app f
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir` (unpacked directory).
* [macOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `pkg`, `mas`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, AppX (Windows Store), Squirrel.Windows.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Web installer, AppX (Windows Store), Squirrel.Windows.
* [Two package.json structure](https://github.com/electron-userland/electron-builder/wiki/Two-package.json-Structure) is supported, but you are not forced to use it even if you have native production dependencies.
* [Publishing artifacts](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts) to GitHub Releases, Amazon S3 and Bintray.
* Pack in a distributable format [already packaged app](#pack-only-in-a-distributable-format).
Expand Down Expand Up @@ -133,7 +133,7 @@ Examples:
build --linux deb tar.xz build deb and tar.xz for Linux
build --win --ia32 build for Windows ia32
build --em.foo=bar set package.json property `foo` to `bar`
build --config.nsis.unicode= configure unicode options for NSIS
build --config.nsis.unicode=false configure unicode options for NSIS
```
## Programmatic Usage
Expand Down
4 changes: 3 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| script | <a name="NsisOptions-script"></a>The path to NSIS script to customize installer. Defaults to `build/installer.nsi`. See [Custom NSIS script](https://github.com/electron-userland/electron-builder/wiki/NSIS#custom-nsis-script).
| license | <a name="NsisOptions-license"></a>The path to EULA license file. Defaults to `build/license.rtf` or `build/license.txt`.
| language | <a name="NsisOptions-language"></a>* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).
| multiLanguageInstaller | <a name="NsisOptions-multiLanguageInstaller"></a><p>*boring installer only.* Whether to create multi-language installer. Defaults to <code>unicode</code> option value. [Not all strings are translated](https://github.com/electron-userland/electron-builder/issues/646#issuecomment-238155800).</p>
| warningsAsErrors | <a name="NsisOptions-warningsAsErrors"></a>Defaults to `true`. If `warningsAsErrors` is `true` (default): NSIS will treat warnings as errors. If `warningsAsErrors` is `false`: NSIS will allow warnings.
| menuCategory | <a name="NsisOptions-menuCategory"></a>Whether to create submenu for start menu shortcut and program files directory. Defaults to `false`. If `true`, company name will be used. Or string value.
| artifactName | <a name="NsisOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.
| unicode | <a name="NsisOptions-unicode"></a>Whether to create [Unicode installer](http://nsis.sourceforge.net/Docs/Chapter1.html#intro-unicode). Defaults to `true`.
| deleteAppDataOnUninstall | <a name="NsisOptions-deleteAppDataOnUninstall"></a>*one-click installer only.* Whether to delete app data on uninstall. Defaults to `false`.

<a name="NsisWebOptions"></a>
### `nsis` Web Installer Specific Options
Expand Down Expand Up @@ -236,7 +238,7 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
### `win` Windows Specific Options
| Name | Description
| --- | ---
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p> <p>To use Squirrel.Windows please install <code>electron-builder-squirrel-windows</code> dependency.</p>
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>nsis-web</code> (Web installer), <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p> <p>To use Squirrel.Windows please install <code>electron-builder-squirrel-windows</code> dependency.</p>
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a><p>Array of signing algorithms used. Defaults to <code>['sha1', 'sha256']</code></p> <p>For AppX <code>sha256</code> is always used.</p>
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"semver": "^5.3.0",
"stat-mode": "^0.2.2",
"tunnel-agent": "^0.4.3",
"update-notifier": "^1.0.3",
"update-notifier": "^2.0.0",
"uuid-1345": "^0.99.6",
"yargs": "^6.6.0"
},
Expand All @@ -65,11 +65,11 @@
"@types/xml2js": "^0.0.32",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.22.0",
"babel-plugin-transform-es2015-destructuring": "^6.22.0",
"babel-plugin-transform-es2015-parameters": "^6.22.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"convert-source-map": "^1.3.0",
"convert-source-map": "^1.4.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
"electron-download-tf": "3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"plist": "^2.0.1",
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"update-notifier": "^1.0.3",
"update-notifier": "^2.0.0",
"uuid-1345": "^0.99.6",
"yargs": "^6.6.0",
"node-forge": "^0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/cli/cliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createYargs(): any {
.example("build --linux deb tar.xz", "build deb and tar.xz for Linux")
.example("build --win --ia32", "build for Windows ia32")
.example("build --em.foo=bar", "set package.json property `foo` to `bar`")
.example("build --config.nsis.unicode=", "configure unicode options for NSIS")
.example("build --config.nsis.unicode=false", "configure unicode options for NSIS")
.option("mac", {
group: buildGroup,
alias: ["m", "o", "macos"],
Expand Down
13 changes: 12 additions & 1 deletion packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlatformSpecificBuildOptions } from "../metadata"
*/
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
/*
Target package type: list of `nsis`, `appx`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
Target package type: list of `nsis`, `nsis-web` (Web installer), `appx`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
AppX package can be built only on Windows 10.
Expand Down Expand Up @@ -139,6 +139,12 @@ export interface NsisOptions {
*/
readonly language?: string | null

/*
*boring installer only.* Whether to create multi-language installer. Defaults to `unicode` option value.
[Not all strings are translated](https://github.com/electron-userland/electron-builder/issues/646#issuecomment-238155800).
*/
readonly multiLanguageInstaller?: boolean

/*
Defaults to `true`. If `warningsAsErrors` is `true` (default): NSIS will treat warnings as errors. If `warningsAsErrors` is `false`: NSIS will allow warnings.
*/
Expand All @@ -161,6 +167,11 @@ export interface NsisOptions {
Whether to create [Unicode installer](http://nsis.sourceforge.net/Docs/Chapter1.html#intro-unicode). Defaults to `true`.
*/
readonly unicode?: boolean

/*
*one-click installer only.* Whether to delete app data on uninstall. Defaults to `false`.
*/
readonly deleteAppDataOnUninstall?: boolean
}

/*
Expand Down
19 changes: 18 additions & 1 deletion packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export default class NsisTarget extends Target {
BUILD_RESOURCES_DIR: packager.buildResourcesDir,
}

// electron uses product file name as app data, define it as well to remove on uninstall
if (defines.APP_FILENAME != appInfo.productFilename) {
defines.APP_PRODUCT_FILENAME = appInfo.productFilename
}

if (iconPath != null) {
defines.MUI_ICON = iconPath
defines.MUI_UNICON = iconPath
Expand Down Expand Up @@ -151,7 +156,7 @@ export default class NsisTarget extends Target {
OutFile: `"${installerPath}"`,
VIProductVersion: appInfo.versionInWeirdWindowsForm,
VIAddVersionKey: this.computeVersionKey(),
Unicode: options.unicode == null ? true : options.unicode,
Unicode: this.isUnicodeEnabled(),
}

if (packager.config.compression === "store") {
Expand All @@ -177,6 +182,10 @@ export default class NsisTarget extends Target {
packager.dispatchArtifactCreated(installerPath, this, `${packager.appInfo.name}-${this.isWebInstaller ? "Web-" : ""}Setup-${version}.exe`)
}

private isUnicodeEnabled() {
return this.options.unicode == null ? true : this.options.unicode
}

private get isWebInstaller(): boolean {
return this.name === "nsis-web"
}
Expand Down Expand Up @@ -283,6 +292,14 @@ export default class NsisTarget extends Target {
}

use(await packager.getResource(options.license, "license.rtf", "license.txt"), it => defines.LICENSE_FILE = it)

if (options.multiLanguageInstaller == null ? this.isUnicodeEnabled() : options.multiLanguageInstaller) {
defines.MULTI_LANGUAGE_INSTALLER = null
}

if (options.deleteAppDataOnUninstall) {
defines.DELETE_APP_DATA_ON_UNINSTALL = null
}
}

private async executeMakensis(defines: any, commands: any, isInstaller: boolean, originalScript: string) {
Expand Down
16 changes: 8 additions & 8 deletions packages/electron-builder/templates/nsis/boringInstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

!ifndef BUILD_UNINSTALLER
Function StartApp
${GetParameters} $R0
${GetOptions} $R0 "--update" $R1
${IfNot} ${Errors}
${if} ${Updated}
${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" "--updated"
${Else}
${else}
${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" ""
${endif}
FunctionEnd
Expand All @@ -21,9 +19,7 @@

!ifdef LICENSE_FILE
Function licensePre
${GetParameters} $R0
${GetOptions} $R0 "--update" $R1
${IfNot} ${Errors}
${if} ${Updated}
Abort
${endif}
FunctionEnd
Expand Down Expand Up @@ -118,4 +114,8 @@
!endif
!macroend

!include "langs.nsh"
!ifdef MULTI_LANGUAGE_INSTALLER
!include "langs.nsh"
!else
!insertmacro MUI_LANGUAGE "English"
!endif
10 changes: 9 additions & 1 deletion packages/electron-builder/templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ FunctionEnd
!else
StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
!endif
!macroend
!macroend

!macro _Updated _a _b _t _f
ClearErrors
${GetParameters} $R9
${GetOptions} $R9 "--updated" $R8
IfErrors `${_f}` `${_t}`
!macroend
!define Updated `"" Updated ""`
10 changes: 3 additions & 7 deletions packages/electron-builder/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@
StrCpy $0 "/allusers"
${endif}

ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--update" $R2
${ifNot} ${Errors}
StrCpy $0 "$0 --update"
${endif}

ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--delete-app-data" $R2
${ifNot} ${Errors}
StrCpy $0 "$0 --delete-app-data"
${else}
# always pass --updated flag - to ensure that if DELETE_APP_DATA_ON_UNINSTALL is defined, user data will be not removed
StrCpy $0 "$0 --updated"
${endif}

ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 _?=$R1'
Expand Down
26 changes: 10 additions & 16 deletions packages/electron-builder/templates/nsis/oneClick.nsh
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
!ifdef RUN_AFTER_FINISH
!ifndef BUILD_UNINSTALLER
!ifndef BUILD_UNINSTALLER
!ifdef RUN_AFTER_FINISH
!include StdUtils.nsh
Function StartApp
!ifdef INSTALL_MODE_PER_ALL_USERS
${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" ""
!else
${GetParameters} $R0
${GetOptions} $R0 "--update" $R1
${ifNot} ${Errors}
${if} ${Updated}
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "--updated"
${else}
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
${endif}
!endif
FunctionEnd
!endif
!endif


!ifdef LICENSE_FILE

Function licensePre
${GetParameters} $R0
${GetOptions} $R0 "--update" $R1
${IfNot} ${Errors}
!ifdef LICENSE_FILE
Function licensePre
${if} ${Updated}
Abort
${endif}
FunctionEnd
FunctionEnd

!define MUI_PAGE_CUSTOMFUNCTION_PRE licensePre
!insertmacro MUI_PAGE_LICENSE "${LICENSE_FILE}"
!define MUI_PAGE_CUSTOMFUNCTION_PRE licensePre
!insertmacro MUI_PAGE_LICENSE "${LICENSE_FILE}"
!endif
!endif

!insertmacro MUI_PAGE_INSTFILES
Expand Down
20 changes: 18 additions & 2 deletions packages/electron-builder/templates/nsis/uninstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,35 @@ Section "un.install"
# delete the installed files
RMDir /r /REBOOTOK $INSTDIR

Var /GLOBAL isDeleteAppData
StrCpy $isDeleteAppData "0"

ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--delete-app-data" $R1
${IfNot} ${Errors}
${if} ${Errors}
!ifdef DELETE_APP_DATA_ON_UNINSTALL
${ifNot} ${Updated}
StrCpy $isDeleteAppData "1"
${endif}
!endif
${else}
StrCpy $isDeleteAppData "1"
${endIf}

${if} $isDeleteAppData == "1"
# electron always uses per user app data
${if} $installMode == "all"
SetShellVarContext current
${endif}
RMDir /r "$APPDATA\${APP_FILENAME}"
!ifdef APP_PRODUCT_FILENAME
RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
!endif
${if} $installMode == "all"
SetShellVarContext all
${endif}
${EndIf}
${endif}

DeleteRegKey SHCTX "${UNINSTALL_REGISTRY_KEY}"
DeleteRegKey SHCTX "${INSTALL_REGISTRY_KEY}"
Expand Down
5 changes: 2 additions & 3 deletions test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ test("one-click", app({
},
nsis: {
unicode: false,
}
// wine creates incorrect filenames and registry entries for unicode, so, we use ASCII
// productName: "TestApp",
deleteAppDataOnUninstall: true,
},
}
}, {
useTempDir: true,
Expand Down
Loading

0 comments on commit 2e1b21e

Please sign in to comment.