Skip to content

Commit

Permalink
Merge pull request #2499 from getlantern/issue2477
Browse files Browse the repository at this point in the history
uninstall previous version before install new one
  • Loading branch information
myleshorton committed May 12, 2015
2 parents 1ded811 + 5b89546 commit cdc1f62
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions installer-resources/windows/lantern.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,28 @@ Name "Lantern"

# define name of installer
OutFile "lantern-installer-unsigned.exe"

# define installation directory
InstallDir $APPDATA\Lantern

# Request user permissions so that auto-updates will work with no prompt
RequestExecutionLevel user

# start default section
Section
# Uninstall the previous version. This will also kill the process.
Call UninstallPrevious
ClearErrors
# Stop existing Lantern if necessary
${nsProcess::KillProcess} "lantern.exe" $R0
# Sleep for 1 second to process a chance to die and file to become writable
Sleep 1000

${nsProcess::Unload}
IfErrors 0 +2
Abort "Error stopping previous Lantern version. Please stop it from the system tray and install again."

DetailPrint "Killing process returned $R0"

# Remove anything that may currently be installed
RMDir /r "$SMPROGRAMS\Lantern"
RMDir /r "$INSTDIR"

# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
SetOverwrite on

File lantern.exe
File lantern.ico

# Store installation folder
WriteRegStr HKCU "Software\Lantern" "" $INSTDIR

Expand All @@ -71,20 +61,20 @@ Section
"DisplayName" "Lantern"

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"DisplayIcon" "$INSTDIR\lantern.ico"
"DisplayIcon" "$INSTDIR\lantern.ico"

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"Publisher" "Brave New Software Project, Inc."

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"URLInfoAbout" "http://www.getlantern.org"

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"DisplayVersion" "${VERSION}"

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"UninstallString" "$\"$INSTDIR\uninstall.exe$\""

CreateDirectory "$SMPROGRAMS\Lantern"
CreateShortCut "$SMPROGRAMS\Lantern\Lantern.lnk" "$INSTDIR\lantern.exe" "" "$INSTDIR\lantern.ico" 0
CreateShortCut "$SMPROGRAMS\Lantern\Uninstall Lantern.lnk" "$INSTDIR\uninstall.exe"
Expand All @@ -96,7 +86,30 @@ Section

SectionEnd
# end default section


# Uninstall previous versions before installing the new one
Function UninstallPrevious
DetailPrint "Uninstalling previous version"
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern" \
"UninstallString"
StrCmp $R0 "" noprevious

DetailPrint "Uninstalling $R0"
ClearErrors
ExecWait '$R0 /S _?=$INSTDIR' ;Do not copy the uninstaller to a temp file

IfErrors erroruninstalling done
noprevious:
DetailPrint "No previous version to uninstall"
Goto end
erroruninstalling:
DetailPrint "Error uninstalling previous at $R0"
Goto end
done:
DetailPrint "Successfully uninstalled $R0"
end:
FunctionEnd

# start uninstaller section
Section "uninstall"
# Stop Lantern if necessary
Expand All @@ -105,7 +118,7 @@ Section "uninstall"
Sleep 1000

RMDir /r "$SMPROGRAMS\Lantern"
RMDir /r "$INSTDIR"
RMDir /r "$INSTDIR"

# Remove uninstaller from Add/Remove programs
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Lantern"
Expand Down

0 comments on commit cdc1f62

Please sign in to comment.