Sync translations from Transifex and run lupdate
[qBittorrent.git] / dist / windows / installer.nsi
bloba76e926094b1e6063084c040588abf784bc295dd
1 Var uninstallerPath
3 Section "-hidden"
5 ;Search if qBittorrent is already installed.
6 FindFirst $0 $1 "$uninstallerPath\uninst.exe"
7 FindClose $0
8 StrCmp $1 "" done
10 ;Run the uninstaller of the previous install.
11 DetailPrint $(inst_unist)
12 ExecWait '"$uninstallerPath\uninst.exe" /S _?=$uninstallerPath'
13 Delete "$uninstallerPath\uninst.exe"
14 RMDir "$uninstallerPath"
16 done:
18 SectionEnd
21 Section $(inst_qbt_req) ;"qBittorrent (required)"
23 SectionIn RO
25 ; Set output path to the installation directory.
26 SetOutPath $INSTDIR
27 ; Put files there
28 File "qbittorrent.exe"
29 File "qbittorrent.pdb"
30 File "qt.conf"
32 ;Create 'translations' directory
33 CreateDirectory $INSTDIR\translations
34 ; Set output path to the installation\translations directory.
35 SetOutPath "$INSTDIR\translations"
36 ; Put files there
37 File /r "translations\qt*.qm"
38 ; Restore output path because it affects `CreateShortCut`. It affects the "Start in" field.
39 SetOutPath $INSTDIR
41 ; Write the installation path into the registry
42 WriteRegStr HKLM "Software\qBittorrent" "InstallLocation" "$INSTDIR"
44 ; Write the uninstall keys for Windows
45 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayName" "qBittorrent"
46 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "UninstallString" '"$INSTDIR\uninst.exe"'
47 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayIcon" '"$INSTDIR\qbittorrent.exe",0'
48 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "Publisher" "The qBittorrent project"
49 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "URLInfoAbout" "https://www.qbittorrent.org"
50 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayVersion" "${QBT_VERSION}"
51 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoModify" 1
52 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoRepair" 1
53 WriteUninstaller "uninst.exe"
54 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
55 IntFmt $0 "0x%08X" $0
56 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "EstimatedSize" "$0"
58 ; qBittorrent ProgID
59 WriteRegStr HKLM "Software\Classes\qBittorrent" "" "qBittorrent Torrent File"
60 WriteRegStr HKLM "Software\Classes\qBittorrent" "FriendlyTypeName" "qBittorrent Torrent File"
61 WriteRegStr HKLM "Software\Classes\qBittorrent\shell" "" "open"
62 WriteRegStr HKLM "Software\Classes\qBittorrent\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
63 WriteRegStr HKLM "Software\Classes\qBittorrent\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
65 SectionEnd
67 ; Optional section (can be disabled by the user)
68 Section /o $(inst_desktop) ;"Create Desktop Shortcut"
70 CreateShortCut "$DESKTOP\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
72 SectionEnd
74 Section $(inst_startmenu) ;"Create Start Menu Shortcut"
76 CreateDirectory "$SMPROGRAMS\qBittorrent"
77 CreateShortCut "$SMPROGRAMS\qBittorrent\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
78 CreateShortCut "$SMPROGRAMS\qBittorrent\$(inst_uninstall_link_description).lnk" "$INSTDIR\uninst.exe"
80 SectionEnd
82 Section /o $(inst_startup) ;"Start qBittorrent on Windows start up"
84 !insertmacro UAC_AsUser_Call Function inst_startup_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR}
86 SectionEnd
88 Function inst_startup_user
90 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "qBittorrent" "$INSTDIR\qbittorrent.exe"
92 FunctionEnd
94 Section $(inst_torrent) ;"Open .torrent files with qBittorrent"
96 ReadRegStr $0 HKLM "Software\Classes\.torrent" ""
98 StrCmp $0 "qBittorrent" clear_errors 0
99 ;Check if empty string
100 StrCmp $0 "" clear_errors 0
101 ;Write old value to OpenWithProgIds
102 WriteRegStr HKLM "Software\Classes\.torrent\OpenWithProgIds" $0 ""
104 clear_errors:
105 ClearErrors
107 WriteRegStr HKLM "Software\Classes\.torrent" "" "qBittorrent"
108 WriteRegStr HKLM "Software\Classes\.torrent" "Content Type" "application/x-bittorrent"
110 !insertmacro UAC_AsUser_Call Function inst_torrent_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR}
112 System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)'
114 SectionEnd
116 Function inst_torrent_user
118 ReadRegStr $0 HKCU "Software\Classes\.torrent" ""
120 StrCmp $0 "qBittorrent" clear_errors 0
121 ;Check if empty string
122 StrCmp $0 "" clear_errors 0
123 ;Write old value to OpenWithProgIds
124 WriteRegStr HKCU "Software\Classes\.torrent\OpenWithProgIds" $0 ""
126 clear_errors:
127 ClearErrors
129 WriteRegStr HKCU "Software\Classes\.torrent" "" "qBittorrent"
130 WriteRegStr HKCU "Software\Classes\.torrent" "Content Type" "application/x-bittorrent"
132 FunctionEnd
134 Section $(inst_magnet) ;"Open magnet links with qBittorrent"
136 WriteRegStr HKLM "Software\Classes\magnet" "" "URL:Magnet link"
137 WriteRegStr HKLM "Software\Classes\magnet" "Content Type" "application/x-magnet"
138 WriteRegStr HKLM "Software\Classes\magnet" "URL Protocol" ""
139 WriteRegStr HKLM "Software\Classes\magnet\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
140 WriteRegStr HKLM "Software\Classes\magnet\shell" "" "open"
141 WriteRegStr HKLM "Software\Classes\magnet\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
143 !insertmacro UAC_AsUser_Call Function inst_magnet_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR}
145 System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)'
147 SectionEnd
149 Function inst_magnet_user
151 WriteRegStr HKCU "Software\Classes\magnet" "" "URL:Magnet link"
152 WriteRegStr HKCU "Software\Classes\magnet" "Content Type" "application/x-magnet"
153 WriteRegStr HKCU "Software\Classes\magnet" "URL Protocol" ""
154 WriteRegStr HKCU "Software\Classes\magnet\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
155 WriteRegStr HKCU "Software\Classes\magnet\shell" "" "open"
156 WriteRegStr HKCU "Software\Classes\magnet\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
158 FunctionEnd
160 Section $(inst_firewall)
162 DetailPrint $(inst_firewallinfo)
163 nsisFirewallW::AddAuthorizedApplication "$INSTDIR\qbittorrent.exe" "qBittorrent"
165 SectionEnd
167 Section $(inst_pathlimit) ;"Disable Windows path length limit (260 character MAX_PATH limitation, requires Windows 10 1607 or later)"
169 WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
171 SectionEnd
173 ;--------------------------------
175 Function .onInit
177 !insertmacro Init "installer"
178 !insertmacro MUI_LANGDLL_DISPLAY
180 !ifndef QBT_USES_QT6
181 ${IfNot} ${AtLeastWin7}
182 MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_win7)
183 Abort
184 ${EndIf}
185 !else
186 ${IfNot} ${AtLeastWaaS} 1809 ; Windows 10 1809. Min supported version by Qt6
187 MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_win10)
188 Abort
189 ${EndIf}
190 !endif
192 !ifdef QBT_IS_X64
193 ${IfNot} ${RunningX64}
194 MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_64bit)
195 Abort
196 ${EndIf}
197 !endif
199 ;Search if qBittorrent is already installed.
200 FindFirst $0 $1 "$INSTDIR\uninst.exe"
201 FindClose $0
202 StrCmp $1 "" done
204 ;Copy old value to var so we can call the correct uninstaller
205 StrCpy $uninstallerPath $INSTDIR
207 ;Inform the user
208 MessageBox MB_OKCANCEL|MB_ICONINFORMATION $(inst_uninstall_question) /SD IDOK IDOK done
209 Quit
211 done:
213 FunctionEnd
215 Function check_instance
217 check:
218 FindProcDLL::FindProc "qbittorrent.exe"
219 StrCmp $R0 "1" 0 notfound
220 MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION $(inst_warning) IDRETRY check IDCANCEL done
222 done:
223 Abort
225 notfound:
227 FunctionEnd
229 Function PageFinishRun
231 !insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\qbittorrent.exe" "" "" ""
233 FunctionEnd
235 Function .onInstSuccess
236 SetErrorLevel 0
237 FunctionEnd