Skip to content

Commit

Permalink
fix: NSIS Installer Not Working on Second Invocation #722
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Sep 4, 2016
1 parent 0f1869b commit 1b90ec6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ export default class NsisTarget extends Target {
const extensions = asArray(item.ext).map(normalizeExt)
for (let ext of extensions) {
const customIcon = await packager.getResource(item.icon, `${extensions[0]}.ico`)
let installedIconPath = "${APP_EXECUTABLE_FILENAME},0"
let installedIconPath = "$appExe,0"
if (customIcon != null) {
installedIconPath = `resources\\${path.basename(customIcon)}`
installedIconPath = `$INSTDIR\\resources\\${path.basename(customIcon)}`
//noinspection SpellCheckingInspection
registerFileAssociationsScript += ` File "/oname=${installedIconPath}" "${customIcon}"\n`
}

const icon = `"$INSTDIR\\${installedIconPath}"`
const icon = `"${installedIconPath}"`
const commandText = `"Open with ${packager.appInfo.productName}"`
const command = '"$INSTDIR\\${APP_EXECUTABLE_FILENAME} $\\"%1$\\""'
const command = '"$appExe $\\"%1$\\""'
registerFileAssociationsScript += ` !insertmacro APP_ASSOCIATE "${ext}" "${item.name}" "${item.description || ""}" ${icon} ${commandText} ${command}\n`
}
}
Expand Down
12 changes: 6 additions & 6 deletions templates/nsis/install.nsh → templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ${if} $installMode == "all"
${endif}
${endif}

RMDir /r $INSTDIR
SetOutPath $INSTDIR

SetCompress off
Expand All @@ -51,12 +50,12 @@ SetCompress "${COMPRESS}"

!ifdef APP_64
${If} ${RunningX64}
Nsis7z::Extract "$PLUGINSDIR\app-64.7z"
Nsis7z::ExtractWithDetails "$PLUGINSDIR\app-64.7z" "Installing %s..."
${Else}
Nsis7z::Extract "$PLUGINSDIR\app-32.7z"
Nsis7z::ExtractWithDetails "$PLUGINSDIR\app-32.7z" "Installing %s..."
${endif}
!else
Nsis7z::Extract "$PLUGINSDIR\app-32.7z"
Nsis7z::ExtractWithDetails "$PLUGINSDIR\app-32.7z" "Installing %s..."
!endif

File "/oname=${UNINSTALL_FILENAME}" "${UNINSTALLER_OUT_FILE}"
Expand All @@ -65,11 +64,12 @@ File "/oname=${UNINSTALL_FILENAME}" "${UNINSTALLER_OUT_FILE}"

StrCpy $startMenuLink "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"
StrCpy $desktopLink "$DESKTOP\${PRODUCT_FILENAME}.lnk"
StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"

# create shortcuts in the start menu and on the desktop
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
CreateShortCut "$startMenuLink" "$INSTDIR\${APP_EXECUTABLE_FILENAME}" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME}" 0 "" "" "${APP_DESCRIPTION}"
CreateShortCut "$desktopLink" "$INSTDIR\${APP_EXECUTABLE_FILENAME}" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME}" 0 "" "" "${APP_DESCRIPTION}"
CreateShortCut "$startMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
CreateShortCut "$desktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"

WinShell::SetLnkAUMI "$startMenuLink" "${APP_ID}"
WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
Expand Down
4 changes: 3 additions & 1 deletion templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Var desktopLink

!ifdef BUILD_UNINSTALLER
SilentInstall silent
!else
Var appExe
!endif

Function .onInit
Expand Down Expand Up @@ -56,7 +58,7 @@ FunctionEnd

Section "install"
!ifndef BUILD_UNINSTALLER
!include "install.nsh"
!include "installSection.nsh"
!endif
SectionEnd

Expand Down
6 changes: 3 additions & 3 deletions templates/nsis/multiUser.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Var installMode
StrCpy $0 $1
System::Call 'Ole32::CoTaskMemFree(ir2)'
${endif}
StrCpy $INSTDIR "$0\${PRODUCT_FILENAME}"
StrCpy $INSTDIR "$0\${PRODUCT_FILENAME}\${VERSION}"
!endif

# сhecks registry for previous installation path (both for upgrading, reinstall, or uninstall)
Expand All @@ -47,7 +47,7 @@ Var installMode
StrCpy $installMode all
SetShellVarContext all

StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}"
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCT_FILENAME}\${VERSION}"

# checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
ReadRegStr $perMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation
Expand All @@ -72,7 +72,7 @@ Var installMode
${endif}

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$INSTDIR\${APP_EXECUTABLE_FILENAME},0"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoRepair 1
Expand Down

0 comments on commit 1b90ec6

Please sign in to comment.