From a0e71319bdd0287b28b9529079670628ffe832e4 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 18 Oct 2016 17:33:39 +0200 Subject: [PATCH] fix(nsis): EULA Closes #829 --- .idea/dictionaries/develar.xml | 19 +++++++++++++++++++ .idea/electron-builder.iml | 1 - .idea/inspectionProfiles/Project_Default.xml | 1 + .../ArtifactPublisherTest.xml | 2 +- docs/Options.md | 1 + nsis-auto-updater/package.json | 2 +- nsis-auto-updater/yarn.lock | 6 +++--- src/options/winOptions.ts | 5 +++++ src/platformPackager.ts | 16 ++++++++-------- src/targets/nsis.ts | 5 +++++ ....nsh => allowOnlyOneInstallerInstance.nsh} | 2 +- templates/nsis/boringInstaller.nsh | 5 +++++ templates/nsis/installer.nsi | 6 +++--- templates/nsis/oneClick.nsh | 4 ++++ test/fixtures/license.txt | 1 + test/src/nsisTest.ts | 9 +++++++-- yarn.lock | 10 +++++----- 17 files changed, 70 insertions(+), 25 deletions(-) rename templates/nsis/{allowOnlyOneInstallerInstace.nsh => allowOnlyOneInstallerInstance.nsh} (97%) create mode 100644 test/fixtures/license.txt diff --git a/.idea/dictionaries/develar.xml b/.idea/dictionaries/develar.xml index 2fa690fefa7..1c07cfcd61f 100644 --- a/.idea/dictionaries/develar.xml +++ b/.idea/dictionaries/develar.xml @@ -3,6 +3,9 @@ actperepo addincludedir + adminrequired + allusersnotpossible + andif appdir appimage appleid @@ -24,6 +27,7 @@ cpus crypto cuint + customfunction debian difflet digester @@ -33,39 +37,50 @@ electronuserland enoent eperm + finishpage fseventsd github globaldots globby gnubin + goglobal graphicsmagick grĂ¼n gsettings gtar guid + guiinit hdiutil headerimage hicolor + hkcu + hklm hrtime icnsutils icnv iconset iconutil idms + ifdef + ifmacrodef + ifndef inno insertmacro installmode instdir + instfiles ircs isbinaryfile joliet keyserver + langs lcid libappindicator libexec libgcrypt libgnome libnotify + lockfile lzfse lzip lzma @@ -86,6 +101,7 @@ noninteractive npmrc nsis + nsisdir nuget nupkg nuspec @@ -95,6 +111,7 @@ passin pkcs postinstall + powerrequired prerelease productbuild progexe @@ -110,6 +127,7 @@ shorthash signcode signtool + smprograms srcfolder templating testapp @@ -125,6 +143,7 @@ unicon unmounting unorm + unpage userprofile valuename versioner diff --git a/.idea/electron-builder.iml b/.idea/electron-builder.iml index 627ffc64c96..86576276fb4 100644 --- a/.idea/electron-builder.iml +++ b/.idea/electron-builder.iml @@ -3,7 +3,6 @@ - diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 2b02d3814ed..1cde07c6116 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -4,6 +4,7 @@ + diff --git a/.idea/runConfigurations/ArtifactPublisherTest.xml b/.idea/runConfigurations/ArtifactPublisherTest.xml index a330eaab560..5705e49b0a6 100644 --- a/.idea/runConfigurations/ArtifactPublisherTest.xml +++ b/.idea/runConfigurations/ArtifactPublisherTest.xml @@ -8,7 +8,7 @@ - \ No newline at end of file diff --git a/docs/Options.md b/docs/Options.md index c00e63e2a9c..476d66efb3f 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -188,6 +188,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi | installerHeaderIcon | *one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/installerHeaderIcon.ico` or application icon. | include | The path to NSIS include script to customize installer. Defaults to `build/installer.nsh`. See [Custom NSIS script](https://github.com/electron-userland/electron-builder/wiki/NSIS#custom-nsis-script). | script | 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 | The path to EULA license file. Defaults to `build/license.rtf` or `build/license.txt`. | language | * [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`). | warningsAsErrors |

Defaults to false.

If warningsAsErrors is true (default): NSIS will treat warnings as errors.

If warningsAsErrors is false: NSIS will allow warnings.

diff --git a/nsis-auto-updater/package.json b/nsis-auto-updater/package.json index e5f7d112289..290fbc311da 100644 --- a/nsis-auto-updater/package.json +++ b/nsis-auto-updater/package.json @@ -16,7 +16,7 @@ "fs-extra-p": "^1.1.10", "ini": "^1.3.4", "semver": "^5.3.0", - "source-map-support": "^0.4.4", + "source-map-support": "^0.4.5", "tunnel-agent": "^0.4.3" }, "typings": "./out/electron-auto-updater.d.ts" diff --git a/nsis-auto-updater/yarn.lock b/nsis-auto-updater/yarn.lock index bfc93065aea..01b80df40d4 100644 --- a/nsis-auto-updater/yarn.lock +++ b/nsis-auto-updater/yarn.lock @@ -106,9 +106,9 @@ semver@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" -source-map-support: - version "0.4.4" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.4.tgz#0df5765a05a560c91bc8f8641cf79f2affc0322e" +source-map-support@^0.4.5: + version "0.4.5" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.5.tgz#4438df4219e1b3c7feb674614b4c67f9722db1e4" dependencies: source-map "^0.5.3" diff --git a/src/options/winOptions.ts b/src/options/winOptions.ts index 20da3f5e591..9f4170b7ee0 100644 --- a/src/options/winOptions.ts +++ b/src/options/winOptions.ts @@ -102,6 +102,11 @@ export interface NsisOptions { */ readonly script?: string | null + /* + The path to EULA license file. Defaults to `build/license.rtf` or `build/license.txt`. + */ + readonly license?: string | null + /* * [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`). */ diff --git a/src/platformPackager.ts b/src/platformPackager.ts index 4ad8a7428e6..630ad6f742a 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -467,18 +467,18 @@ export abstract class PlatformPackager return asArray(this.devMetadata.build.fileAssociations).concat(asArray(this.platformSpecificBuildOptions.fileAssociations)) } - async getResource(custom: string | n, name: string): Promise { - let result = custom - if (result === undefined) { + async getResource(custom: string | n, ...names: Array): Promise { + if (custom === undefined) { const resourceList = await this.resourceList - if (resourceList.includes(name)) { - return path.join(this.buildResourcesDir, name) + for (let name of names) { + if (resourceList.includes(name)) { + return path.join(this.buildResourcesDir, name) + } } } - else { - return path.resolve(this.projectDir, result) + else if (!isEmptyOrSpaces(custom)) { + return path.resolve(this.projectDir, custom) } - return null } } diff --git a/src/targets/nsis.ts b/src/targets/nsis.ts index 363459c430a..e620eb4d4ce 100644 --- a/src/targets/nsis.ts +++ b/src/targets/nsis.ts @@ -176,6 +176,11 @@ export default class NsisTarget extends TargetEx { return } + const licenseFile = await this.packager.getResource(this.options.license, "license.rtf", "license.txt") + if (licenseFile != null) { + defines.LICENSE_FILE = licenseFile + } + const customScriptPath = await this.packager.getResource(this.options.script, "installer.nsi") const script = await readFile(customScriptPath || path.join(this.nsisTemplatesDir, "installer.nsi"), "utf8") diff --git a/templates/nsis/allowOnlyOneInstallerInstace.nsh b/templates/nsis/allowOnlyOneInstallerInstance.nsh similarity index 97% rename from templates/nsis/allowOnlyOneInstallerInstace.nsh rename to templates/nsis/allowOnlyOneInstallerInstance.nsh index 2be623ae5db..36b92984f58 100644 --- a/templates/nsis/allowOnlyOneInstallerInstace.nsh +++ b/templates/nsis/allowOnlyOneInstallerInstance.nsh @@ -1,7 +1,7 @@ !include "nsProcess.nsh" # http://nsis.sourceforge.net/Allow_only_one_installer_instance -!macro ALLOW_ONLY_ONE_INSTALLER_INSTACE +!macro ALLOW_ONLY_ONE_INSTALLER_INSTANCE BringToFront !define /ifndef SYSTYPE_PTR p ; NSIS v3.0+ System::Call 'kernel32::CreateMutex(${SYSTYPE_PTR}0, i1, t"${APP_GUID}")?e' diff --git a/templates/nsis/boringInstaller.nsh b/templates/nsis/boringInstaller.nsh index 7a239ae28f1..faa1eebb924 100644 --- a/templates/nsis/boringInstaller.nsh +++ b/templates/nsis/boringInstaller.nsh @@ -12,6 +12,10 @@ !define MUI_FINISHPAGE_RUN !define MUI_FINISHPAGE_RUN_FUNCTION "StartApp" + !ifdef LICENSE_FILE + !insertmacro MUI_PAGE_LICENSE "${LICENSE_FILE}" + !endif + !ifndef INSTALL_MODE_PER_ALL_USERS !insertmacro PAGE_INSTALL_MODE Function GuiInit @@ -20,6 +24,7 @@ !define MUI_CUSTOMFUNCTION_GUIINIT GuiInit !endif + !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !else diff --git a/templates/nsis/installer.nsi b/templates/nsis/installer.nsi index f9cf3c53d23..002565ebc57 100644 --- a/templates/nsis/installer.nsi +++ b/templates/nsis/installer.nsi @@ -1,7 +1,7 @@ !include "common.nsh" !include "MUI2.nsh" !include "multiUser.nsh" -!include "allowOnlyOneInstallerInstace.nsh" +!include "allowOnlyOneInstallerInstance.nsh" !ifdef INSTALL_MODE_PER_ALL_USERS !ifdef BUILD_UNINSTALLER @@ -41,10 +41,10 @@ Function .onInit !insertmacro initMultiUser !ifdef ONE_CLICK - !insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE + !insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTANCE !else ${IfNot} ${UAC_IsInnerInstance} - !insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE + !insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTANCE ${EndIf} !endif diff --git a/templates/nsis/oneClick.nsh b/templates/nsis/oneClick.nsh index 1b7459133d7..ffc04890666 100644 --- a/templates/nsis/oneClick.nsh +++ b/templates/nsis/oneClick.nsh @@ -11,6 +11,10 @@ !endif !endif +!ifdef LICENSE_FILE + !insertmacro MUI_PAGE_LICENSE "${LICENSE_FILE}" +!endif + !insertmacro MUI_PAGE_INSTFILES !ifdef BUILD_UNINSTALLER !insertmacro MUI_UNPAGE_INSTFILES diff --git a/test/fixtures/license.txt b/test/fixtures/license.txt new file mode 100644 index 00000000000..2f9031f0ec7 --- /dev/null +++ b/test/fixtures/license.txt @@ -0,0 +1 @@ +Hi! \ No newline at end of file diff --git a/test/src/nsisTest.ts b/test/src/nsisTest.ts index 27c83a5e708..0a6887a5358 100644 --- a/test/src/nsisTest.ts +++ b/test/src/nsisTest.ts @@ -63,7 +63,7 @@ test.ifDevOrLinuxCi("perMachine, no run after finish", app({ }, { projectDirCreated: projectDir => { let headerIconPath = path.join(projectDir, "build", "foo.ico") - return copy(getTestAsset("headerIcon.ico"), headerIconPath) + return BluebirdPromise.all([copy(getTestAsset("headerIcon.ico"), headerIconPath), copy(getTestAsset("license.txt"), path.join(projectDir, "build", "license.txt"))]) }, packed: context => { return doTest(context.outDir, false) @@ -134,7 +134,12 @@ test.ifNotCiOsx("boring", app({ }, } } -}, {signed: true})) +}, { + signed: true, + projectDirCreated: projectDir => { + return copy(getTestAsset("license.txt"), path.join(projectDir, "build", "license.txt")) + }, +})) test.ifNotCiOsx("boring, only perMachine", app({ targets: nsisTarget, diff --git a/yarn.lock b/yarn.lock index 06470ac4334..c17ca8e7219 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2480,8 +2480,8 @@ map-stream@~0.1.0: resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194" markdown-it@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.0.0.tgz#e66255497a0e409e816fbc67807975f4f26f6f82" + version "8.0.1" + resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.0.1.tgz#ff60e2103d17896cb6c57407baa9766f916495cb" dependencies: argparse "^1.0.7" entities "~1.1.1" @@ -3436,9 +3436,9 @@ sort-keys@^1.1.1: dependencies: is-plain-obj "^1.0.0" -source-map-support@^0.4.2, source-map-support@^0.4.3, source-map-support@^0.4.4: - version "0.4.4" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.4.tgz#0df5765a05a560c91bc8f8641cf79f2affc0322e" +source-map-support@^0.4.2, source-map-support@^0.4.3, source-map-support@^0.4.4, source-map-support@^0.4.5: + version "0.4.5" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.5.tgz#4438df4219e1b3c7feb674614b4c67f9722db1e4" dependencies: source-map "^0.5.3"