Skip to content

Commit

Permalink
fix(nsis): correct fix of #722 (NSIS Installer Not Working on Second …
Browse files Browse the repository at this point in the history
…Invocation)
  • Loading branch information
develar committed Sep 11, 2016
1 parent 29f6436 commit e35933d
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 145 deletions.
2 changes: 1 addition & 1 deletion src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecOp
resolve(stdout)
}
else {
let message = red(removePassword(error.message))
let message = red(removePassword(`Exit code: ${(<any>error).code}. ${error.message}`))
if (stdout.length !== 0) {
message += `\n${yellow(stdout)}`
}
Expand Down
44 changes: 43 additions & 1 deletion templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,46 @@ Unicode true
!endif
${EndIf}
!endif
!macroend
!macroend

# avoid exit code 2
!macro quitSuccess
SetErrorLevel 0
Quit
!macroend

!ifndef BUILD_UNINSTALLER
Function GetInQuotes
Exch $R0
Push $R1
Push $R2
Push $R3

StrCpy $R2 -1
IntOp $R2 $R2 + 1
StrCpy $R3 $R0 1 $R2
StrCmp $R3 "" 0 +3
StrCpy $R0 ""
Goto Done
StrCmp $R3 '"' 0 -5

IntOp $R2 $R2 + 1
StrCpy $R0 $R0 "" $R2

StrCpy $R2 0
IntOp $R2 $R2 + 1
StrCpy $R3 $R0 1 $R2
StrCmp $R3 "" 0 +3
StrCpy $R0 ""
Goto Done
StrCmp $R3 '"' 0 -5

StrCpy $R0 $R0 $R2
Done:

Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!endif
90 changes: 31 additions & 59 deletions templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# http://stackoverflow.com/questions/24595887/waiting-for-nsis-uninstaller-to-finish-in-nsis-installer-either-fails-or-the-uni
!macro uninstallOldVersion ROOT_KEY
ReadRegStr $R0 ${ROOT_KEY} "${UNINSTALL_REGISTRY_KEY}" UninstallString
${if} $R0 != ""
Push $R0
Call GetInQuotes
Pop $R0

ReadRegStr $R1 ${ROOT_KEY} "${INSTALL_REGISTRY_KEY}" InstallLocation
${if} $R1 != ""
${AndIf} $R0 != ""
CopyFiles /SILENT /FILESONLY "$R0" "$PLUGINSDIR\old-uninstaller.exe"

${if} $installMode == "CurrentUser"
${OrIf} ${ROOT_KEY} == "HKEY_CURRENT_USER"
StrCpy $0 "/currentuser"
${else}
StrCpy $0 "/allusers"
${endif}
# MessageBox MB_OK|MB_ICONEXCLAMATION '"$PLUGINSDIR\old-uninstaller.exe" "_?=$R1" /S /KEEP_APP_DATA $0'
ExecWait '"$PLUGINSDIR\old-uninstaller.exe" "_?=$R1" /S /KEEP_APP_DATA $0'
${endif}
${endif}
!macroend

InitPluginsDir

!ifdef HEADER_ICO
Expand All @@ -24,62 +49,9 @@ ${endif}
${endif}
!endif

### remove old < 6.4.1 versions

ReadRegStr $R0 SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallString
${if} $R0 != ""
ReadRegStr $R2 SHCTX "${INSTALL_REGISTRY_KEY}" UninstallerPath
${if} $R2 == ""
ReadRegStr $R1 SHCTX "${INSTALL_REGISTRY_KEY}" InstallLocation
ExecWait "$R0 _?=$R1 /S /KEEP_APP_DATA"
Delete "$R1\Uninstall *.exe"
ClearErrors
${endif}
${endif}

# remove per-user installation
${if} $installMode == "all"
ReadRegStr $R0 HKEY_CURRENT_USER "${UNINSTALL_REGISTRY_KEY}" UninstallString
${if} $R0 != ""
ReadRegStr $R2 HKEY_CURRENT_USER "${INSTALL_REGISTRY_KEY}" UninstallerPath
${if} $R2 == ""
ReadRegStr $R1 HKEY_CURRENT_USER "${INSTALL_REGISTRY_KEY}" InstallLocation
ExecWait "$R0 _?=$R1 /S /KEEP_APP_DATA"
Delete "$R1\Uninstall *.exe"
ClearErrors
${endif}
${endif}
${endif}

###


# http://stackoverflow.com/questions/24595887/waiting-for-nsis-uninstaller-to-finish-in-nsis-installer-either-fails-or-the-uni

ReadRegStr $R0 SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallerPath
${if} $R0 != ""
ReadRegStr $R1 SHCTX "${INSTALL_REGISTRY_KEY}" InstallLocation
${if} $R1 != ""
CopyFiles /SILENT /FILESONLY "$R0" "$PLUGINSDIR\old-uninstaller.exe"

${if} $installMode == "all"
ExecWait "$PLUGINSDIR\old-uninstaller.exe _?=$R1 /S /KEEP_APP_DATA /allusers"
${Else}
ExecWait "$PLUGINSDIR\old-uninstaller.exe _?=$R1 /S /KEEP_APP_DATA /currentuser"
${endif}
${endif}
${endif}

# remove per-user installation
!insertmacro uninstallOldVersion SHELL_CONTEXT
${if} $installMode == "all"
ReadRegStr $R0 HKEY_CURRENT_USER "${UNINSTALL_REGISTRY_KEY}" UninstallerPath
${if} $R0 != ""
ReadRegStr $R1 HKEY_CURRENT_USER "${INSTALL_REGISTRY_KEY}" InstallLocation
${if} $R1 != ""
CopyFiles /SILENT /FILESONLY "$R0" "$PLUGINSDIR\old-uninstaller.exe"
ExecWait "$PLUGINSDIR\old-uninstaller.exe _?=$R1 /S /KEEP_APP_DATA /currentuser"
${endif}
${endif}
!insertmacro uninstallOldVersion HKEY_CURRENT_USER
${endif}

SetOutPath $INSTDIR
Expand All @@ -94,9 +66,9 @@ SetCompress off
SetCompress "${COMPRESS}"

!ifdef APP_64
${If} ${RunningX64}
${if} ${RunningX64}
Nsis7z::Extract "$PLUGINSDIR\app-64.7z"
${Else}
${else}
Nsis7z::Extract "$PLUGINSDIR\app-32.7z"
${endif}
!else
Expand Down Expand Up @@ -135,5 +107,5 @@ WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
Call StartApp
${EndIf}
!endif
Quit
!endif
!insertmacro quitSuccess
!endif
4 changes: 1 addition & 3 deletions templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ Var desktopLink
Function .onInit
!ifdef BUILD_UNINSTALLER
WriteUninstaller "${UNINSTALLER_OUT_FILE}"
# avoid exit code 2
SetErrorLevel 0
Quit
!insertmacro quitSuccess
!else
!insertmacro check64BitAndSetRegView
!insertmacro initMultiUser
Expand Down
1 change: 0 additions & 1 deletion templates/nsis/multiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Var installMode
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" DisplayName "${UNINSTALL_DISPLAY_NAME} (only current user)"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallString '"$INSTDIR\${UNINSTALL_FILENAME}" /currentuser'
${endif}
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallerPath "$INSTDIR\${UNINSTALL_FILENAME}"

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
Expand Down
2 changes: 1 addition & 1 deletion templates/nsis/uninstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ Section "un.install"
!insertmacro customUnInstall
!endif

Quit
!insertmacro quitSuccess
SectionEnd
155 changes: 78 additions & 77 deletions test/src/helpers/expectedContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,83 +87,84 @@ export const expectedWinContents = [

export const nsisPerMachineInstall = pathSorter([
"Program Files/TestApp",
"Program Files/TestApp/blink_image_resources_200_percent.pak",
"Program Files/TestApp/content_resources_200_percent.pak",
"Program Files/TestApp/content_shell.pak",
"Program Files/TestApp/d3dcompiler_47.dll",
"Program Files/TestApp/ffmpeg.dll",
"Program Files/TestApp/icudtl.dat",
"Program Files/TestApp/libEGL.dll",
"Program Files/TestApp/libGLESv2.dll",
"Program Files/TestApp/LICENSE",
"Program Files/TestApp/LICENSES.chromium.html",
"Program Files/TestApp/natives_blob.bin",
"Program Files/TestApp/node.dll",
"Program Files/TestApp/snapshot_blob.bin",
"Program Files/TestApp/TestApp.exe",
"Program Files/TestApp/ui_resources_200_percent.pak",
"Program Files/TestApp/Uninstall TestApp.exe",
"Program Files/TestApp/views_resources_200_percent.pak",
"Program Files/TestApp/xinput1_3.dll",
"Program Files/TestApp/resources",
"Program Files/TestApp/resources/app.asar",
"Program Files/TestApp/resources/electron.asar",
"Program Files/TestApp/resources/foo.ico",
"Program Files/TestApp/locales",
"Program Files/TestApp/locales/am.pak",
"Program Files/TestApp/locales/ar.pak",
"Program Files/TestApp/locales/bg.pak",
"Program Files/TestApp/locales/bn.pak",
"Program Files/TestApp/locales/ca.pak",
"Program Files/TestApp/locales/cs.pak",
"Program Files/TestApp/locales/da.pak",
"Program Files/TestApp/locales/de.pak",
"Program Files/TestApp/locales/el.pak",
"Program Files/TestApp/locales/en-GB.pak",
"Program Files/TestApp/locales/en-US.pak",
"Program Files/TestApp/locales/es-419.pak",
"Program Files/TestApp/locales/es.pak",
"Program Files/TestApp/locales/et.pak",
"Program Files/TestApp/locales/fa.pak",
"Program Files/TestApp/locales/fake-bidi.pak",
"Program Files/TestApp/locales/fi.pak",
"Program Files/TestApp/locales/fil.pak",
"Program Files/TestApp/locales/fr.pak",
"Program Files/TestApp/locales/gu.pak",
"Program Files/TestApp/locales/he.pak",
"Program Files/TestApp/locales/hi.pak",
"Program Files/TestApp/locales/hr.pak",
"Program Files/TestApp/locales/hu.pak",
"Program Files/TestApp/locales/id.pak",
"Program Files/TestApp/locales/it.pak",
"Program Files/TestApp/locales/ja.pak",
"Program Files/TestApp/locales/kn.pak",
"Program Files/TestApp/locales/ko.pak",
"Program Files/TestApp/locales/lt.pak",
"Program Files/TestApp/locales/lv.pak",
"Program Files/TestApp/locales/ml.pak",
"Program Files/TestApp/locales/mr.pak",
"Program Files/TestApp/locales/ms.pak",
"Program Files/TestApp/locales/nb.pak",
"Program Files/TestApp/locales/nl.pak",
"Program Files/TestApp/locales/pl.pak",
"Program Files/TestApp/locales/pt-BR.pak",
"Program Files/TestApp/locales/pt-PT.pak",
"Program Files/TestApp/locales/ro.pak",
"Program Files/TestApp/locales/ru.pak",
"Program Files/TestApp/locales/sk.pak",
"Program Files/TestApp/locales/sl.pak",
"Program Files/TestApp/locales/sr.pak",
"Program Files/TestApp/locales/sv.pak",
"Program Files/TestApp/locales/sw.pak",
"Program Files/TestApp/locales/ta.pak",
"Program Files/TestApp/locales/te.pak",
"Program Files/TestApp/locales/th.pak",
"Program Files/TestApp/locales/tr.pak",
"Program Files/TestApp/locales/uk.pak",
"Program Files/TestApp/locales/vi.pak",
"Program Files/TestApp/locales/zh-CN.pak",
"Program Files/TestApp/locales/zh-TW.pak",
"Program Files/TestApp/1.1.0",
"Program Files/TestApp/1.1.0/blink_image_resources_200_percent.pak",
"Program Files/TestApp/1.1.0/content_resources_200_percent.pak",
"Program Files/TestApp/1.1.0/content_shell.pak",
"Program Files/TestApp/1.1.0/d3dcompiler_47.dll",
"Program Files/TestApp/1.1.0/ffmpeg.dll",
"Program Files/TestApp/1.1.0/icudtl.dat",
"Program Files/TestApp/1.1.0/libEGL.dll",
"Program Files/TestApp/1.1.0/libGLESv2.dll",
"Program Files/TestApp/1.1.0/LICENSE",
"Program Files/TestApp/1.1.0/LICENSES.chromium.html",
"Program Files/TestApp/1.1.0/locales",
"Program Files/TestApp/1.1.0/natives_blob.bin",
"Program Files/TestApp/1.1.0/node.dll",
"Program Files/TestApp/1.1.0/resources",
"Program Files/TestApp/1.1.0/snapshot_blob.bin",
"Program Files/TestApp/1.1.0/TestApp.exe",
"Program Files/TestApp/1.1.0/ui_resources_200_percent.pak",
"Program Files/TestApp/1.1.0/Uninstall TestApp.exe",
"Program Files/TestApp/1.1.0/views_resources_200_percent.pak",
"Program Files/TestApp/1.1.0/xinput1_3.dll",
"Program Files/TestApp/1.1.0/locales/am.pak",
"Program Files/TestApp/1.1.0/locales/ar.pak",
"Program Files/TestApp/1.1.0/locales/bg.pak",
"Program Files/TestApp/1.1.0/locales/bn.pak",
"Program Files/TestApp/1.1.0/locales/ca.pak",
"Program Files/TestApp/1.1.0/locales/cs.pak",
"Program Files/TestApp/1.1.0/locales/da.pak",
"Program Files/TestApp/1.1.0/locales/de.pak",
"Program Files/TestApp/1.1.0/locales/el.pak",
"Program Files/TestApp/1.1.0/locales/en-GB.pak",
"Program Files/TestApp/1.1.0/locales/en-US.pak",
"Program Files/TestApp/1.1.0/locales/es-419.pak",
"Program Files/TestApp/1.1.0/locales/es.pak",
"Program Files/TestApp/1.1.0/locales/et.pak",
"Program Files/TestApp/1.1.0/locales/fa.pak",
"Program Files/TestApp/1.1.0/locales/fake-bidi.pak",
"Program Files/TestApp/1.1.0/locales/fi.pak",
"Program Files/TestApp/1.1.0/locales/fil.pak",
"Program Files/TestApp/1.1.0/locales/fr.pak",
"Program Files/TestApp/1.1.0/locales/gu.pak",
"Program Files/TestApp/1.1.0/locales/he.pak",
"Program Files/TestApp/1.1.0/locales/hi.pak",
"Program Files/TestApp/1.1.0/locales/hr.pak",
"Program Files/TestApp/1.1.0/locales/hu.pak",
"Program Files/TestApp/1.1.0/locales/id.pak",
"Program Files/TestApp/1.1.0/locales/it.pak",
"Program Files/TestApp/1.1.0/locales/ja.pak",
"Program Files/TestApp/1.1.0/locales/kn.pak",
"Program Files/TestApp/1.1.0/locales/ko.pak",
"Program Files/TestApp/1.1.0/locales/lt.pak",
"Program Files/TestApp/1.1.0/locales/lv.pak",
"Program Files/TestApp/1.1.0/locales/ml.pak",
"Program Files/TestApp/1.1.0/locales/mr.pak",
"Program Files/TestApp/1.1.0/locales/ms.pak",
"Program Files/TestApp/1.1.0/locales/nb.pak",
"Program Files/TestApp/1.1.0/locales/nl.pak",
"Program Files/TestApp/1.1.0/locales/pl.pak",
"Program Files/TestApp/1.1.0/locales/pt-BR.pak",
"Program Files/TestApp/1.1.0/locales/pt-PT.pak",
"Program Files/TestApp/1.1.0/locales/ro.pak",
"Program Files/TestApp/1.1.0/locales/ru.pak",
"Program Files/TestApp/1.1.0/locales/sk.pak",
"Program Files/TestApp/1.1.0/locales/sl.pak",
"Program Files/TestApp/1.1.0/locales/sr.pak",
"Program Files/TestApp/1.1.0/locales/sv.pak",
"Program Files/TestApp/1.1.0/locales/sw.pak",
"Program Files/TestApp/1.1.0/locales/ta.pak",
"Program Files/TestApp/1.1.0/locales/te.pak",
"Program Files/TestApp/1.1.0/locales/th.pak",
"Program Files/TestApp/1.1.0/locales/tr.pak",
"Program Files/TestApp/1.1.0/locales/uk.pak",
"Program Files/TestApp/1.1.0/locales/vi.pak",
"Program Files/TestApp/1.1.0/locales/zh-CN.pak",
"Program Files/TestApp/1.1.0/locales/zh-TW.pak",
"Program Files/TestApp/1.1.0/resources/app.asar",
"Program Files/TestApp/1.1.0/resources/electron.asar",
"Program Files/TestApp/1.1.0/resources/foo.ico",
"users/Public/Desktop/TestApp.lnk",
"users/Public/Start Menu/Programs/TestApp.lnk"
])
4 changes: 2 additions & 2 deletions test/src/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function doTest(outDir: string, perUser: boolean) {
await wine.exec(path.join(outDir, "TestApp Setup 1.1.0.exe"), "/S")

const instDir = perUser ? path.join(wine.userDir, "Local Settings", "Application Data", "Programs") : path.join(driveC, "Program Files")
const appAsar = path.join(instDir, "TestApp", "resources", "app.asar")
const appAsar = path.join(instDir, "TestApp", "1.1.0", "resources", "app.asar")
assertThat(JSON.parse(extractFile(appAsar, "package.json").toString())).hasProperties({
name: "TestApp"
})
Expand All @@ -97,7 +97,7 @@ async function doTest(outDir: string, perUser: boolean) {
const appDataFile = path.join(wine.userDir, "Application Data", "TestApp", "doNotDeleteMe")
await outputFile(appDataFile, "app data must be not removed")
fsBefore = await listFiles()
await wine.exec(path.join(outDir, "TestApp Setup 1.1.0.exe", "/S"))
await wine.exec(path.join(outDir, "TestApp Setup 1.1.0.exe"), "/S")
fsAfter = await listFiles()

fsChanges = diff(fsBefore, fsAfter, driveC)
Expand Down

0 comments on commit e35933d

Please sign in to comment.