Skip to content

Commit 9a3fd5e

Browse files
committed
fix(nsis): fix all nsis warnings
1 parent 5c3e313 commit 9a3fd5e

File tree

12 files changed

+128
-120
lines changed

12 files changed

+128
-120
lines changed

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Here documented only `electron-builder` specific options:
6565
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
6666
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
6767
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
68+
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
6869
| fileAssociations | <a name="BuildMetadata-fileAssociations"></a>File associations. (NSIS only for now).
6970

7071
<a name="MacOptions"></a>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@
112112
"ava-tf": "^0.15.3",
113113
"babel-plugin-array-includes": "^2.0.3",
114114
"babel-plugin-transform-es2015-destructuring": "^6.9.0",
115-
"babel-plugin-transform-es2015-parameters": "^6.11.3",
115+
"babel-plugin-transform-es2015-parameters": "^6.11.4",
116116
"babel-plugin-transform-es2015-spread": "^6.8.0",
117117
"decompress-zip": "^0.3.0",
118118
"diff": "^2.2.3",
119-
"json8": "^0.9.0",
119+
"json8": "^0.9.2",
120120
"pre-git": "^3.10.0",
121121
"should": "^10.0.0",
122122
"ts-babel": "^1.0.3",

src/metadata.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ export interface BuildMetadata {
190190
*/
191191
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null
192192

193-
// /*
194-
// Whether to [prune](https://docs.npmjs.com/cli/prune) dependencies (`npm prune --production`) before starting to package the app.
195-
// Defaults to `false`.
196-
// */
197-
// readonly npmPrune?: boolean
198-
// deprecated
199-
// readonly prune?: boolean
200-
201193
/*
202194
Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
203195
*/

src/targets/nsis.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export default class NsisTarget extends Target {
9191
defines.INSTALL_MODE_PER_ALL_USERS = null
9292
}
9393

94+
if (!oneClick || this.options.perMachine === true) {
95+
defines.INSTALL_MODE_PER_ALL_USERS_REQUIRED = null
96+
}
97+
9498
if (oneClick) {
9599
if (this.options.runAfterFinish !== false) {
96100
defines.RUN_AFTER_FINISH = null
@@ -162,7 +166,7 @@ export default class NsisTarget extends Target {
162166
}
163167

164168
private async executeMakensis(defines: any, commands: any) {
165-
const args: Array<string> = []
169+
const args: Array<string> = ["-WX"]
166170
for (let name of Object.keys(defines)) {
167171
const value = defines[name]
168172
if (value == null) {
@@ -195,7 +199,9 @@ export default class NsisTarget extends Target {
195199
const fileAssociations = asArray(packager.devMetadata.build.fileAssociations).concat(asArray(packager.platformSpecificBuildOptions.fileAssociations))
196200
let registerFileAssociationsScript = ""
197201
let unregisterFileAssociationsScript = ""
202+
let script = await readFile(path.join(nsisTemplatesDir, "installer.nsi"), "utf8")
198203
if (fileAssociations.length !== 0) {
204+
script = "!include FileAssociation.nsh\n" + script
199205
for (let item of fileAssociations) {
200206
registerFileAssociationsScript += '${RegisterExtension} "$INSTDIR\\${APP_EXECUTABLE_FILENAME}" ' + `"${normalizeExt(item.ext)}" "${item.name}"\n`
201207
}
@@ -205,7 +211,6 @@ export default class NsisTarget extends Target {
205211
}
206212
}
207213

208-
let script = await readFile(path.join(nsisTemplatesDir, "installer.nsi"), "utf8")
209214
script = script.replace("!insertmacro registerFileAssociations", registerFileAssociationsScript)
210215
script = script.replace("!insertmacro unregisterFileAssociations", unregisterFileAssociationsScript)
211216

templates/nsis/allowOnlyOneInstallerInstace.nsh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
!include "nsProcess.nsh"
2+
13
# http://nsis.sourceforge.net/Allow_only_one_installer_instance
24
!macro ALLOW_ONLY_ONE_INSTALLER_INSTACE
35
BringToFront
@@ -18,4 +20,18 @@
1820
notfound:
1921
Abort
2022
launch:
23+
!macroend
24+
25+
!macro CHECK_APP_RUNNING MODE
26+
${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
27+
${If} $R0 == 0
28+
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} is running. $\r$\nClick OK to close it and continue with ${MODE}." /SD IDCANCEL IDOK doStopProcess
29+
Abort
30+
doStopProcess:
31+
DetailPrint "Closing running ${PRODUCT_NAME} ..."
32+
${nsProcess::KillProcess} "${APP_EXECUTABLE_FILENAME}" $R0
33+
DetailPrint "Waiting for ${PRODUCT_NAME} to close."
34+
Sleep 2000
35+
${EndIf}
36+
${nsProcess::Unload}
2137
!macroend

templates/nsis/boring-installer.nsh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# http://nsis.sourceforge.net/Run_an_application_shortcut_after_an_install
2-
!include NsisMultiUser.nsh
2+
!include multiUserUi.nsh
3+
4+
Function StartApp
5+
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
6+
FunctionEnd
7+
38
!define MUI_FINISHPAGE_RUN
49
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"
510

@@ -9,11 +14,11 @@
914
!insertmacro MUI_PAGE_INSTFILES
1015
!insertmacro MUI_PAGE_FINISH
1116

12-
!insertmacro MUI_LANGUAGE "English"
13-
1417
# uninstall pages
1518
!insertmacro MUI_UNPAGE_INSTFILES
1619

20+
!insertmacro MUI_LANGUAGE "English"
21+
1722
Function GuiInit
1823
!insertmacro UAC_PageElevation_OnGuiInit
1924
FunctionEnd

templates/nsis/checkAppRunning.nsh

Lines changed: 0 additions & 13 deletions
This file was deleted.

templates/nsis/common.nsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
!include x64.nsh
2+
!include WinVer.nsh
23

34
BrandingText "${PRODUCT_NAME} ${VERSION}"
45
ShowInstDetails nevershow

templates/nsis/installer.nsi

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
!include "common.nsh"
22
!include "MUI2.nsh"
33
!include "multiUser.nsh"
4-
!include "nsProcess.nsh"
54
!include "allowOnlyOneInstallerInstace.nsh"
6-
!include "checkAppRunning.nsh"
7-
!include WinVer.nsh
8-
!include FileAssociation.nsh
95

106
!ifdef ONE_CLICK
11-
!ifdef RUN_AFTER_FINISH
12-
Function StartApp
13-
!ifdef INSTALL_MODE_PER_ALL_USERS
14-
!include UAC.nsh
15-
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
16-
!else
17-
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
18-
!endif
19-
FunctionEnd
20-
!endif
21-
22-
SilentUnInstall silent
23-
AutoCloseWindow true
24-
!insertmacro MUI_PAGE_INSTFILES
25-
!insertmacro MUI_UNPAGE_INSTFILES
26-
27-
!insertmacro MUI_LANGUAGE "English"
28-
29-
!ifdef INSTALL_MODE_PER_ALL_USERS
30-
RequestExecutionLevel admin
31-
!else
32-
RequestExecutionLevel user
33-
!endif
7+
!include "oneClick.nsh"
348
!else
359
!include "boring-installer.nsh"
3610
!endif

templates/nsis/multiUser.nsh

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,79 +17,87 @@
1717

1818
# Current Install Mode ("AllUsers" or "CurrentUser")
1919
Var MultiUser.InstallMode
20-
Var HasPerUserInstallation ; 0 (false) or 1 (true)
21-
Var HasPerMachineInstallation ; 0 (false) or 1 (true)
22-
Var PerUserInstallationFolder
23-
Var PerMachineInstallationFolder
2420

25-
# Sets install mode to "per-machine" (all users).
26-
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
27-
# Install mode initialization - per-machine
28-
StrCpy $MultiUser.InstallMode AllUsers
21+
!ifndef INSTALL_MODE_PER_ALL_USERS
22+
!ifndef ONE_CLICK
23+
Var HasPerUserInstallation ; 0 (false) or 1 (true)
24+
Var HasPerMachineInstallation ; 0 (false) or 1 (true)
25+
!endif
26+
Var PerUserInstallationFolder
27+
28+
# Sets install mode to "per-user".
29+
!macro MULTIUSER_INSTALLMODE_CURRENTUSER UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
30+
StrCpy $MultiUser.InstallMode CurrentUser
31+
32+
SetShellVarContext current
33+
34+
!if "${UNINSTALLER_PREFIX}" != UN
35+
# http://www.mathiaswestin.net/2012/09/how-to-make-per-user-installation-with.html
36+
StrCpy $0 "$LocalAppData\Programs"
37+
# Win7 has a per-user programfiles known folder and this can be a non-default location
38+
System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
39+
${If} $1 == 0
40+
System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
41+
StrCpy $0 $1
42+
System::Call 'Ole32::CoTaskMemFree(ir2)'
43+
${EndIf}
44+
StrCpy $Instdir "$0\${PRODUCT_FILENAME}"
45+
!endif
2946

30-
SetShellVarContext all
47+
# Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
48+
ReadRegStr $PerUserInstallationFolder HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation
49+
${if} $PerUserInstallationFolder != ""
50+
StrCpy $INSTDIR $PerUserInstallationFolder
51+
${endif}
3152

32-
!if "${UNINSTALLER_PREFIX}" != UN
33-
;Set default installation location for installer
34-
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
35-
!endif
53+
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
54+
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
55+
!endif
56+
!macroend
3657

37-
; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
38-
ReadRegStr $PerMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation
39-
${if} $PerMachineInstallationFolder != ""
40-
StrCpy $INSTDIR $PerMachineInstallationFolder
41-
${endif}
58+
Function MultiUser.InstallMode.CurrentUser
59+
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER "" ""
60+
FunctionEnd
4261

43-
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
44-
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
45-
!endif
46-
!macroend
62+
Function un.MultiUser.InstallMode.CurrentUser
63+
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER UN un.
64+
FunctionEnd
65+
!endif
4766

48-
# Sets install mode to "per-user".
49-
!macro MULTIUSER_INSTALLMODE_CURRENTUSER UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
50-
StrCpy $MultiUser.InstallMode CurrentUser
51-
52-
SetShellVarContext current
53-
54-
!if "${UNINSTALLER_PREFIX}" != UN
55-
# http://www.mathiaswestin.net/2012/09/how-to-make-per-user-installation-with.html
56-
StrCpy $0 "$LocalAppData\Programs"
57-
# Win7 has a per-user programfiles known folder and this can be a non-default location
58-
System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
59-
${If} $1 == 0
60-
System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
61-
StrCpy $0 $1
62-
System::Call 'Ole32::CoTaskMemFree(ir2)'
63-
${EndIf}
64-
StrCpy $Instdir "$0\${PRODUCT_FILENAME}"
65-
!endif
67+
!ifdef INSTALL_MODE_PER_ALL_USERS_REQUIRED
68+
Var PerMachineInstallationFolder
6669

67-
# Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
68-
ReadRegStr $PerUserInstallationFolder HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation
69-
${if} $PerUserInstallationFolder != ""
70-
StrCpy $INSTDIR $PerUserInstallationFolder
71-
${endif}
70+
# Sets install mode to "per-machine" (all users).
71+
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
72+
# Install mode initialization - per-machine
73+
StrCpy $MultiUser.InstallMode AllUsers
7274

73-
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
74-
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
75-
!endif
76-
!macroend
75+
SetShellVarContext all
7776

78-
Function MultiUser.InstallMode.AllUsers
79-
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS "" ""
80-
FunctionEnd
77+
!if "${UNINSTALLER_PREFIX}" != UN
78+
;Set default installation location for installer
79+
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
80+
!endif
8181

82-
Function MultiUser.InstallMode.CurrentUser
83-
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER "" ""
84-
FunctionEnd
82+
; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
83+
ReadRegStr $PerMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation
84+
${if} $PerMachineInstallationFolder != ""
85+
StrCpy $INSTDIR $PerMachineInstallationFolder
86+
${endif}
8587

86-
Function un.MultiUser.InstallMode.AllUsers
87-
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS UN un.
88-
FunctionEnd
88+
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
89+
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
90+
!endif
91+
!macroend
8992

90-
Function un.MultiUser.InstallMode.CurrentUser
91-
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER UN un.
92-
FunctionEnd
93+
Function MultiUser.InstallMode.AllUsers
94+
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS "" ""
95+
FunctionEnd
96+
97+
Function un.MultiUser.InstallMode.AllUsers
98+
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS UN un.
99+
FunctionEnd
100+
!endif
93101

94102
!macro MULTIUSER_INIT_TEXTS
95103
!ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED

0 commit comments

Comments
 (0)