Skip to content

Commit

Permalink
fix(nsis): fix all nsis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 20, 2016
1 parent 5c3e313 commit 9a3fd5e
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 120 deletions.
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Here documented only `electron-builder` specific options:
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| 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.
| 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.
| 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`.
| fileAssociations | <a name="BuildMetadata-fileAssociations"></a>File associations. (NSIS only for now).

<a name="MacOptions"></a>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@
"ava-tf": "^0.15.3",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-destructuring": "^6.9.0",
"babel-plugin-transform-es2015-parameters": "^6.11.3",
"babel-plugin-transform-es2015-parameters": "^6.11.4",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"decompress-zip": "^0.3.0",
"diff": "^2.2.3",
"json8": "^0.9.0",
"json8": "^0.9.2",
"pre-git": "^3.10.0",
"should": "^10.0.0",
"ts-babel": "^1.0.3",
Expand Down
8 changes: 0 additions & 8 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ export interface BuildMetadata {
*/
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null

// /*
// Whether to [prune](https://docs.npmjs.com/cli/prune) dependencies (`npm prune --production`) before starting to package the app.
// Defaults to `false`.
// */
// readonly npmPrune?: boolean
// deprecated
// readonly prune?: boolean

/*
Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default class NsisTarget extends Target {
defines.INSTALL_MODE_PER_ALL_USERS = null
}

if (!oneClick || this.options.perMachine === true) {
defines.INSTALL_MODE_PER_ALL_USERS_REQUIRED = null
}

if (oneClick) {
if (this.options.runAfterFinish !== false) {
defines.RUN_AFTER_FINISH = null
Expand Down Expand Up @@ -162,7 +166,7 @@ export default class NsisTarget extends Target {
}

private async executeMakensis(defines: any, commands: any) {
const args: Array<string> = []
const args: Array<string> = ["-WX"]
for (let name of Object.keys(defines)) {
const value = defines[name]
if (value == null) {
Expand Down Expand Up @@ -195,7 +199,9 @@ export default class NsisTarget extends Target {
const fileAssociations = asArray(packager.devMetadata.build.fileAssociations).concat(asArray(packager.platformSpecificBuildOptions.fileAssociations))
let registerFileAssociationsScript = ""
let unregisterFileAssociationsScript = ""
let script = await readFile(path.join(nsisTemplatesDir, "installer.nsi"), "utf8")
if (fileAssociations.length !== 0) {
script = "!include FileAssociation.nsh\n" + script
for (let item of fileAssociations) {
registerFileAssociationsScript += '${RegisterExtension} "$INSTDIR\\${APP_EXECUTABLE_FILENAME}" ' + `"${normalizeExt(item.ext)}" "${item.name}"\n`
}
Expand All @@ -205,7 +211,6 @@ export default class NsisTarget extends Target {
}
}

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

Expand Down
16 changes: 16 additions & 0 deletions templates/nsis/allowOnlyOneInstallerInstace.nsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
!include "nsProcess.nsh"

# http://nsis.sourceforge.net/Allow_only_one_installer_instance
!macro ALLOW_ONLY_ONE_INSTALLER_INSTACE
BringToFront
Expand All @@ -18,4 +20,18 @@
notfound:
Abort
launch:
!macroend

!macro CHECK_APP_RUNNING MODE
${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
${If} $R0 == 0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} is running. $\r$\nClick OK to close it and continue with ${MODE}." /SD IDCANCEL IDOK doStopProcess
Abort
doStopProcess:
DetailPrint "Closing running ${PRODUCT_NAME} ..."
${nsProcess::KillProcess} "${APP_EXECUTABLE_FILENAME}" $R0
DetailPrint "Waiting for ${PRODUCT_NAME} to close."
Sleep 2000
${EndIf}
${nsProcess::Unload}
!macroend
11 changes: 8 additions & 3 deletions templates/nsis/boring-installer.nsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# http://nsis.sourceforge.net/Run_an_application_shortcut_after_an_install
!include NsisMultiUser.nsh
!include multiUserUi.nsh

Function StartApp
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
FunctionEnd

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"

Expand All @@ -9,11 +14,11 @@
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

# uninstall pages
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

Function GuiInit
!insertmacro UAC_PageElevation_OnGuiInit
FunctionEnd
13 changes: 0 additions & 13 deletions templates/nsis/checkAppRunning.nsh

This file was deleted.

1 change: 1 addition & 0 deletions templates/nsis/common.nsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!include x64.nsh
!include WinVer.nsh

BrandingText "${PRODUCT_NAME} ${VERSION}"
ShowInstDetails nevershow
Expand Down
28 changes: 1 addition & 27 deletions templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
!include "common.nsh"
!include "MUI2.nsh"
!include "multiUser.nsh"
!include "nsProcess.nsh"
!include "allowOnlyOneInstallerInstace.nsh"
!include "checkAppRunning.nsh"
!include WinVer.nsh
!include FileAssociation.nsh

!ifdef ONE_CLICK
!ifdef RUN_AFTER_FINISH
Function StartApp
!ifdef INSTALL_MODE_PER_ALL_USERS
!include UAC.nsh
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
!else
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
!endif
FunctionEnd
!endif

SilentUnInstall silent
AutoCloseWindow true
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

!ifdef INSTALL_MODE_PER_ALL_USERS
RequestExecutionLevel admin
!else
RequestExecutionLevel user
!endif
!include "oneClick.nsh"
!else
!include "boring-installer.nsh"
!endif
Expand Down
130 changes: 69 additions & 61 deletions templates/nsis/multiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,87 @@

# Current Install Mode ("AllUsers" or "CurrentUser")
Var MultiUser.InstallMode
Var HasPerUserInstallation ; 0 (false) or 1 (true)
Var HasPerMachineInstallation ; 0 (false) or 1 (true)
Var PerUserInstallationFolder
Var PerMachineInstallationFolder

# Sets install mode to "per-machine" (all users).
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
# Install mode initialization - per-machine
StrCpy $MultiUser.InstallMode AllUsers
!ifndef INSTALL_MODE_PER_ALL_USERS
!ifndef ONE_CLICK
Var HasPerUserInstallation ; 0 (false) or 1 (true)
Var HasPerMachineInstallation ; 0 (false) or 1 (true)
!endif
Var PerUserInstallationFolder

# Sets install mode to "per-user".
!macro MULTIUSER_INSTALLMODE_CURRENTUSER UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
StrCpy $MultiUser.InstallMode CurrentUser

SetShellVarContext current

!if "${UNINSTALLER_PREFIX}" != UN
# http://www.mathiaswestin.net/2012/09/how-to-make-per-user-installation-with.html
StrCpy $0 "$LocalAppData\Programs"
# Win7 has a per-user programfiles known folder and this can be a non-default location
System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
${If} $1 == 0
System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
StrCpy $0 $1
System::Call 'Ole32::CoTaskMemFree(ir2)'
${EndIf}
StrCpy $Instdir "$0\${PRODUCT_FILENAME}"
!endif

SetShellVarContext all
# Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
ReadRegStr $PerUserInstallationFolder HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation
${if} $PerUserInstallationFolder != ""
StrCpy $INSTDIR $PerUserInstallationFolder
${endif}

!if "${UNINSTALLER_PREFIX}" != UN
;Set default installation location for installer
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
!endif
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
!endif
!macroend

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

!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
!endif
!macroend
Function un.MultiUser.InstallMode.CurrentUser
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER UN un.
FunctionEnd
!endif

# Sets install mode to "per-user".
!macro MULTIUSER_INSTALLMODE_CURRENTUSER UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
StrCpy $MultiUser.InstallMode CurrentUser

SetShellVarContext current

!if "${UNINSTALLER_PREFIX}" != UN
# http://www.mathiaswestin.net/2012/09/how-to-make-per-user-installation-with.html
StrCpy $0 "$LocalAppData\Programs"
# Win7 has a per-user programfiles known folder and this can be a non-default location
System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
${If} $1 == 0
System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
StrCpy $0 $1
System::Call 'Ole32::CoTaskMemFree(ir2)'
${EndIf}
StrCpy $Instdir "$0\${PRODUCT_FILENAME}"
!endif
!ifdef INSTALL_MODE_PER_ALL_USERS_REQUIRED
Var PerMachineInstallationFolder

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

!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
!endif
!macroend
SetShellVarContext all

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

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

Function un.MultiUser.InstallMode.AllUsers
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS UN un.
FunctionEnd
!ifdef MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION
Call "${MULTIUSER_INSTALLMODE_${UNINSTALLER_PREFIX}FUNCTION}"
!endif
!macroend

Function un.MultiUser.InstallMode.CurrentUser
!insertmacro MULTIUSER_INSTALLMODE_CURRENTUSER UN un.
FunctionEnd
Function MultiUser.InstallMode.AllUsers
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS "" ""
FunctionEnd

Function un.MultiUser.InstallMode.AllUsers
!insertmacro MULTIUSER_INSTALLMODE_ALLUSERS UN un.
FunctionEnd
!endif

!macro MULTIUSER_INIT_TEXTS
!ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
!include nsDialogs.nsh
!include UAC.nsh

Function StartApp
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
FunctionEnd

RequestExecutionLevel user

Var HasTwoAvailableOptions ; 0 (false) or 1 (true)
Expand Down
23 changes: 23 additions & 0 deletions templates/nsis/oneClick.nsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
!ifdef RUN_AFTER_FINISH
Function StartApp
!ifdef INSTALL_MODE_PER_ALL_USERS
!include UAC.nsh
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
!else
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
!endif
FunctionEnd
!endif

SilentUnInstall silent
AutoCloseWindow true
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

!ifdef INSTALL_MODE_PER_ALL_USERS
RequestExecutionLevel admin
!else
RequestExecutionLevel user
!endif

0 comments on commit 9a3fd5e

Please sign in to comment.