Skip to content

Commit

Permalink
fix(nsis): install per current user even if run as administrator
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 9, 2016
1 parent a1bf645 commit a01f481
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/Multi Platform Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To build rpm: `brew install rpm`.

To build app in distributable format for Linux:
```
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils xorriso
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils
```

To build rpm: `sudo apt-get install --no-install-recommends -y rpm`.
Expand Down
12 changes: 6 additions & 6 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,12 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions {
*/
export interface NsisOptions {
/*
Mark "all users" (per-machine) as default. Not recommended. Defaults to `false`.
One-click installation. Defaults to `true`.
*/
readonly oneClick?: boolean | null

/*
Install per all users (per-machine). Defaults to `false`.
*/
readonly perMachine?: boolean | null

Expand All @@ -371,11 +376,6 @@ export interface NsisOptions {

readonly guid?: string | null

/*
One-click installation. Defaults to `true`.
*/
readonly oneClick?: boolean | null

/*
*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
*/
Expand Down
5 changes: 1 addition & 4 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ export default class NsisTarget extends Target {
}

if (this.options.perMachine === true) {
defines.MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS = null
}
else {
defines.MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER = null
defines.INSTALL_MODE_PER_ALL_USERS = null
}

if (this.options.allowElevation !== false) {
Expand Down
40 changes: 11 additions & 29 deletions templates/nsis/NsisMultiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Var RadioButtonLabel1
!define MULTIUSER_INSTALLMODE_DISPLAYNAME "${PRODUCT_NAME} ${VERSION}"
!endif

RequestExecutionLevel user ; will ask elevation only if necessary
RequestExecutionLevel user

; Sets install mode to "per-machine" (all users).
!macro MULTIUSER_INSTALLMODE_ALLUSERS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX
Expand Down Expand Up @@ -157,7 +157,6 @@ FunctionEnd
!macroend

!macro MULTIUSER_INIT_CHECKS UNINSTALLER_PREFIX UNINSTALLER_FUNCPREFIX

;Installer initialization - check privileges and set default install mode
!insertmacro MULTIUSER_INIT_TEXTS

Expand All @@ -170,10 +169,10 @@ FunctionEnd
StrCpy $IsAdmin 0
${endif}

; Checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
# checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
StrCpy $HasPerMachineInstallation 0
StrCpy $HasPerUserInstallation 0
;Set installation mode to setting from a previous installation
# set installation mode to setting from a previous installation
ReadRegStr $PerMachineInstallationFolder HKLM "${MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY2}" "${MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME}"
${if} $PerMachineInstallationFolder != ""
StrCpy $HasPerMachineInstallation 1
Expand All @@ -189,24 +188,13 @@ FunctionEnd
${elseif} $HasPerUserInstallation == "0" ; if there is only one installation... set it as default...
${andif} $HasPerMachineInstallation == "1"
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
${else} ; if there is no installation, or there is both per-user and per-machine...
${if} ${IsNT}
${if} $IsAdmin == "1" ;If running as admin, default to per-machine installation if possible (unless default is forced by MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER)
!if MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
!else
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
!endif
${else} ;If not running as admin, default to per-user installation (unless default is forced by MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS and elevation is allowed MULTIUSER_INSTALLMODE_ALLOW_ELEVATION)
!ifdef MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS & MULTIUSER_INSTALLMODE_ALLOW_ELEVATION
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
!else
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
!endif
${endif}
${else} ; Not running Windows NT, (so it's Windows XP at best), so per-user installation not supported
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
${endif}
${else}
# if there is no installation, or there is both per-user and per-machine
!ifdef INSTALL_MODE_PER_ALL_USERS
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.AllUsers
!else
Call ${UNINSTALLER_FUNCPREFIX}MultiUser.InstallMode.CurrentUser
!endif
${endif}

!macroend
Expand All @@ -215,7 +203,6 @@ FunctionEnd
!verbose push
!verbose 3

; se for inner (sub processo) e ainda assim não for admin... algo errado
${If} ${UAC_IsInnerInstance}
${AndIfNot} ${UAC_IsAdmin}
;MessageBox MB_OK "This account doesn't have admin rights"
Expand Down Expand Up @@ -353,7 +340,6 @@ FunctionEnd
${NSD_CreateRadioButton} 10u 50u 280u 20u "$9 ($0)"
Pop $MultiUser.InstallModePage.CurrentUser


nsDialogs::SetUserData $MultiUser.InstallModePage.AllUsers 1 ; Install for All Users (1, pra exibir o icone SHIELD de elevation)
nsDialogs::SetUserData $MultiUser.InstallModePage.CurrentUser 0 ; Install for Single User (0 pra não exibir)

Expand All @@ -369,8 +355,6 @@ FunctionEnd
;${NSD_CreateLabel} 0u 130u 280u 20u ""
;Pop $RadioButtonLabel3



${if} $MultiUser.InstallMode == "AllUsers" ; setting defaults
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_SETCHECK} ${BST_CHECKED} 0 ; set as default
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_CLICK} 0 0 ; trigger click event
Expand Down Expand Up @@ -473,13 +457,11 @@ FunctionEnd
${endif}
${endif}
SendMessage $RadioButtonLabel1 ${WM_SETTEXT} 0 "STR:$7"
;SendMessage $RadioButtonLabel2 ${WM_SETTEXT} 0 "STR:$8"
;SendMessage $RadioButtonLabel3 ${WM_SETTEXT} 0 "STR:$9"
FunctionEnd

!macroend

; SHCTX is the hive HKLM if SetShellVarContext all, or HKCU if SetShellVarContext user
# SHCTX is the hive HKLM if SetShellVarContext all, or HKCU if SetShellVarContext user
!macro MULTIUSER_RegistryAddInstallInfo
!verbose push
!verbose 3
Expand Down
2 changes: 1 addition & 1 deletion templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Function .onInit
Quit
${EndIf}

!insertmacro MULTIUSER_INIT
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTACE
!insertmacro MULTIUSER_INIT

InitPluginsDir

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Foo Bar <foo@example.com>",
"license": "MIT",
"build": {
"electronVersion": "1.2.3",
"electronVersion": "1.2.6",
"appId": "org.electron-builder.testApp",
"app-category-type": "your.app.category.type",
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"build": {
"electronVersion": "1.2.3",
"electronVersion": "1.2.6",
"appId": "org.electron-builder.testApp",
"app-category-type": "your.app.category.type",
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
Expand Down
2 changes: 1 addition & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test("relative index", () => assertPack("test-app", allPlatforms(false), {
}, true)
}))

const electronVersion = "1.2.3"
const electronVersion = "1.2.6"

test.ifNotWindows("electron version from electron-prebuilt dependency", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const rootDir = path.join(__dirname, "..", "..", "..")
const testPackageDir = path.join(require("os").tmpdir(), "electron_builder_published")
const testNodeModules = path.join(testPackageDir, "node_modules")

const electronVersion = "1.2.3"
const electronVersion = "1.2.6"

async function main() {
await BluebirdPromise.all([
Expand Down
14 changes: 9 additions & 5 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ test("nsis", () => assertPack("test-app-one", _signed({
}
))

test.ifDevOrLinuxCi("nsis 32", () => assertPack("test-app-one", _signed({
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
}), {
useTempDir: true,
test.ifDevOrLinuxCi("nsis 32 perMachine", () => assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
devMetadata: {
build: {
nsis: {
perMachine: true,
}
}
}
))
}))

test.ifNotCiOsx("nsis boring", () => assertPack("test-app-one", _signed({
targets: Platform.WINDOWS.createTarget(["nsis"]),
Expand Down

0 comments on commit a01f481

Please sign in to comment.