Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 27ee6b5

Browse files
committed
Uninstall previous version before installing
1 parent 9117b94 commit 27ee6b5

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

build/windows/uget-chrome-wrapper.nsi

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
; along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

1919
;--------------------------------
20-
; StrRep function
21-
22-
!define StrRep "!insertmacro StrRep"
2320
!macro StrRep output string old new
2421
Push `${string}`
2522
Push `${old}`
@@ -83,9 +80,9 @@
8380
Exch $R1
8481
FunctionEnd
8582
!macroend
86-
!insertmacro Func_StrRep ""
87-
; !insertmacro Func_StrRep "un."
8883

84+
!define StrRep "!insertmacro StrRep"
85+
!insertmacro Func_StrRep ""
8986

9087
;--------------------------------
9188
;Include Modern UI
@@ -95,16 +92,17 @@
9592
;--------------------------------
9693
;General
9794
!define _VERSION "2.0.7.0"
95+
!define _PROGRAM_NAME "uget-chrome-wrapper"
9896

9997
;Name and file
10098
Name "uGet Chrome Wrapper"
101-
OutFile "uget-chrome-wrapper_${_VERSION}.exe"
99+
OutFile "${_PROGRAM_NAME}_${_VERSION}.exe"
102100

103101
;Default installation folder
104-
InstallDir $PROGRAMFILES\uget-chrome-wrapper
102+
InstallDir $PROGRAMFILES\${_PROGRAM_NAME}
105103

106104
;Get installation folder from registry if available
107-
InstallDirRegKey HKLM "Software\uget-chrome-wrapper" "Install_Dir"
105+
InstallDirRegKey HKLM "Software\${_PROGRAM_NAME}" "Install_Dir"
108106

109107
;Request application privileges for Windows Vista
110108
RequestExecutionLevel admin
@@ -141,56 +139,56 @@
141139

142140
;--------------------------------
143141
; The stuff to install
144-
Section "uget-chrome-wrapper (required)"
142+
Section "${_PROGRAM_NAME} (required)"
145143

146144
SectionIn RO
147145

148146
; Set output path to the installation directory.
149147
SetOutPath $INSTDIR
150148

151149
; Put the script
152-
File "..\..\uget-chrome-wrapper\bin\uget-chrome-wrapper"
150+
File "..\..\${_PROGRAM_NAME}\bin\${_PROGRAM_NAME}"
153151

154-
Rename $INSTDIR\uget-chrome-wrapper $INSTDIR\uget-chrome-wrapper.py
152+
Rename $INSTDIR\${_PROGRAM_NAME} $INSTDIR\${_PROGRAM_NAME}.py
155153

156154
; Replace \ by \\ in the installation path
157155
${StrRep} $0 "$INSTDIR" "\" "\\"
158156

159-
; Put the uget-chrome-wrapper.bat file
160-
File "..\..\uget-chrome-wrapper\windows\uget-chrome-wrapper.bat"
157+
; Put the ${_PROGRAM_NAME}.bat file
158+
File "..\..\${_PROGRAM_NAME}\windows\${_PROGRAM_NAME}.bat"
161159

162160
; Update the com.javahelps.ugetchromewrapper.json file
163161
FileOpen $9 $INSTDIR\com.javahelps.ugetchromewrapper.json w ;Opens a Empty File an fills it
164-
FileWrite $9 '{"name":"com.javahelps.ugetchromewrapper","description":"Integrate uGet with Google Chrome","path":"$0\\uget-chrome-wrapper.bat","type":"stdio","allowed_origins":["chrome-extension://efjgjleilhflffpbnkaofpmdnajdpepi/","chrome-extension://akcbnhoidebjpiefdkmaaicfgdpbnoac/"]}$\r$\n'
162+
FileWrite $9 '{"name":"com.javahelps.ugetchromewrapper","description":"Integrate uGet with Google Chrome","path":"$0\\${_PROGRAM_NAME}.bat","type":"stdio","allowed_origins":["chrome-extension://efjgjleilhflffpbnkaofpmdnajdpepi/","chrome-extension://akcbnhoidebjpiefdkmaaicfgdpbnoac/"]}$\r$\n'
165163
FileClose $9 ;Closes the filled file
166164

167165
; Update the com.javahelps.ugetfirefoxwrapper.json file
168166
FileOpen $9 $INSTDIR\com.javahelps.ugetfirefoxwrapper.json w ;Opens a Empty File an fills it
169-
FileWrite $9 '{"name":"com.javahelps.ugetfirefoxwrapper","description":"Integrate uGet with Mozilla Firefox","path":"$0\\uget-chrome-wrapper.bat","type":"stdio","allowed_extensions":["uget-integration@slgobinath"]}$\r$\n'
167+
FileWrite $9 '{"name":"com.javahelps.ugetfirefoxwrapper","description":"Integrate uGet with Mozilla Firefox","path":"$0\\${_PROGRAM_NAME}.bat","type":"stdio","allowed_extensions":["uget-integration@slgobinath"]}$\r$\n'
170168
FileClose $9 ;Closes the filled file
171169

172170
; Put the icon
173171
File "uget-icon.ico"
174172

175173
; Write the installation path into the registry
176-
WriteRegStr HKLM SOFTWARE\uget-chrome-wrapper "Install_Dir" "$INSTDIR"
174+
WriteRegStr HKLM SOFTWARE\${_PROGRAM_NAME} "Install_Dir" "$INSTDIR"
177175
WriteRegStr HKCU "SOFTWARE\Google\Chrome\NativeMessagingHosts\com.javahelps.ugetchromewrapper" "" "$INSTDIR\com.javahelps.ugetchromewrapper.json"
178176
WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\com.javahelps.ugetchromewrapper" "" "$INSTDIR\com.javahelps.ugetchromewrapper.json"
179177
WriteRegStr HKCU "SOFTWARE\Mozilla\NativeMessagingHosts\com.javahelps.ugetfirefoxwrapper" "" "$INSTDIR\com.javahelps.ugetfirefoxwrapper.json"
180178
WriteRegStr HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\com.javahelps.ugetfirefoxwrapper" "" "$INSTDIR\com.javahelps.ugetfirefoxwrapper.json"
181179

182180

183181
; Write the uninstall keys for Windows
184-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "DisplayName" "uGet Chrome Wrapper"
185-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "Publisher" "Gobinath"
186-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "HelpLink" "https://github.com/slgobinath/uget-chrome-wrapper/issues"
187-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "URLUpdateInfo" "https://github.com/slgobinath/uget-chrome-wrapper/releases"
188-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "URLInfoAbout" "https://slgobinath.github.io/uget-chrome-wrapper/"
189-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "DisplayVersion" "${_VERSION}"
190-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "UninstallString" '"$INSTDIR\uninstall.exe"'
191-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "DisplayIcon" "$INSTDIR\uget-icon.ico,0"
192-
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "NoModify" 1
193-
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper" "NoRepair" 1
182+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "DisplayName" "uGet Chrome Wrapper"
183+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "Publisher" "Gobinath"
184+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "HelpLink" "https://github.com/slgobinath/${_PROGRAM_NAME}/issues"
185+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "URLUpdateInfo" "https://github.com/slgobinath/${_PROGRAM_NAME}/releases"
186+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "URLInfoAbout" "https://slgobinath.github.io/${_PROGRAM_NAME}/"
187+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "DisplayVersion" "${_VERSION}"
188+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
189+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "DisplayIcon" "$INSTDIR\uget-icon.ico,0"
190+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "NoModify" 1
191+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" "NoRepair" 1
194192
WriteUninstaller "uninstall.exe"
195193

196194
SectionEnd
@@ -206,12 +204,12 @@ Section "Uninstall"
206204
DeleteRegKey HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\com.javahelps.ugetchromewrapper"
207205
DeleteRegKey HKCU "SOFTWARE\Mozilla\NativeMessagingHosts\com.javahelps.ugetfirefoxwrapper"
208206
DeleteRegKey HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\com.javahelps.ugetfirefoxwrapper"
209-
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\uget-chrome-wrapper"
210-
DeleteRegKey HKLM SOFTWARE\uget-chrome-wrapper
207+
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}"
208+
DeleteRegKey HKLM SOFTWARE\${_PROGRAM_NAME}
211209

212210
; Remove files and uninstaller
213-
Delete $INSTDIR\uget-chrome-wrapper.py
214-
Delete $INSTDIR\uget-chrome-wrapper.bat
211+
Delete $INSTDIR\${_PROGRAM_NAME}.py
212+
Delete $INSTDIR\${_PROGRAM_NAME}.bat
215213
Delete $INSTDIR\com.javahelps.ugetchromewrapper.json
216214
Delete $INSTDIR\com.javahelps.ugetfirefoxwrapper.json
217215
Delete $INSTDIR\uget-icon.ico
@@ -221,3 +219,26 @@ Section "Uninstall"
221219
RMDir "$INSTDIR"
222220

223221
SectionEnd
222+
223+
;--------------------------------
224+
; uninstall the previous version
225+
Function .onInit
226+
227+
ReadRegStr $R0 HKLM \
228+
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${_PROGRAM_NAME}" \
229+
"UninstallString"
230+
StrCmp $R0 "" done
231+
232+
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
233+
"${_PROGRAM_NAME} is already installed. $\n$\nClick `OK` to remove the \
234+
previous version or `Cancel` to cancel this upgrade." \
235+
IDOK uninst
236+
Abort
237+
238+
;Run the uninstaller
239+
uninst:
240+
ClearErrors
241+
Exec $R0
242+
done:
243+
244+
FunctionEnd

0 commit comments

Comments
 (0)