WebUI: enforce parentheses around operators
[qBittorrent.git] / dist / windows / installer.nsh
bloba6025898de21233d06742701ffcfa5d4d8d3185d
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 "${QBT_DIST_DIR}\qbittorrent.exe"
29   File "qt.conf"
30   File /nonfatal /r /x "${QBT_DIST_DIR}\qbittorrent.exe" "${QBT_DIST_DIR}\*.*"
32   ; Write the installation path into the registry
33   WriteRegStr HKLM "Software\qBittorrent" "InstallLocation" "$INSTDIR"
35   ; Register qBittorrent as possible default program for .torrent files and magnet links
36   WriteRegStr HKLM "Software\qBittorrent\Capabilities" "ApplicationDescription" "A BitTorrent client in Qt"
37   WriteRegStr HKLM "Software\qBittorrent\Capabilities" "ApplicationName" "qBittorrent"
38   WriteRegStr HKLM "Software\qBittorrent\Capabilities\FileAssociations" ".torrent" "qBittorrent.File.Torrent"
39   WriteRegStr HKLM "Software\qBittorrent\Capabilities\UrlAssociations" "magnet" "qBittorrent.Url.Magnet"
40   WriteRegStr HKLM "Software\RegisteredApplications" "qBittorrent" "Software\qBittorrent\Capabilities"
41   ; Register qBittorrent ProgIDs
42   WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent" "" "Torrent File"
43   WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
44   WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
45   WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet" "" "Magnet URI"
46   WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
47   WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
49   WriteRegStr HKLM "Software\Classes\.torrent" "Content Type" "application/x-bittorrent"
50   WriteRegStr HKLM "Software\Classes\magnet" "" "URL:Magnet URI"
51   WriteRegStr HKLM "Software\Classes\magnet" "Content Type" "application/x-magnet"
52   WriteRegStr HKLM "Software\Classes\magnet" "URL Protocol" ""
54   System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)'
56   ; Write the uninstall keys for Windows
57   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayName" "qBittorrent"
58   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "UninstallString" '"$INSTDIR\uninst.exe"'
59   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayIcon" '"$INSTDIR\qbittorrent.exe",0'
60   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "Publisher" "The qBittorrent project"
61   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "URLInfoAbout" "https://www.qbittorrent.org"
62   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayVersion" "${QBT_VERSION}"
63   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoModify" 1
64   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoRepair" 1
65   WriteUninstaller "uninst.exe"
66   ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
67   IntFmt $0 "0x%08X" $0
68   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "EstimatedSize" "$0"
70 SectionEnd
72 ; Optional section (can be disabled by the user)
73 Section /o $(inst_desktop) ;"Create Desktop Shortcut"
75   CreateShortCut "$DESKTOP\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
77 SectionEnd
79 Section $(inst_startmenu) ;"Create Start Menu Shortcut"
81   CreateDirectory "$SMPROGRAMS\qBittorrent"
82   CreateShortCut "$SMPROGRAMS\qBittorrent\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
83   CreateShortCut "$SMPROGRAMS\qBittorrent\$(inst_uninstall_link_description).lnk" "$INSTDIR\uninst.exe"
85 SectionEnd
87 Section /o $(inst_startup) ;"Start qBittorrent on Windows start up"
89   !insertmacro UAC_AsUser_Call Function inst_startup_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR}
91 SectionEnd
93 Function inst_startup_user
95   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "qBittorrent" "$INSTDIR\qbittorrent.exe"
97 FunctionEnd
99 Section $(inst_firewall)
101   DetailPrint $(inst_firewallinfo)
102   nsisFirewallW::AddAuthorizedApplication "$INSTDIR\qbittorrent.exe" "qBittorrent"
104 SectionEnd
106 Section $(inst_pathlimit) ;"Disable Windows path length limit (260 character MAX_PATH limitation, requires Windows 10 1607 or later)"
108   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
110 SectionEnd
112 ;--------------------------------
114 Function .onInit
116   !insertmacro Init "installer"
117   !insertmacro MUI_LANGDLL_DISPLAY
119   ${IfNot} ${AtLeastWaaS} 1809 ; Windows 10 (1809) / Windows Server 2019. Min supported version by Qt6
120     MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_win10) /SD IDOK
121     SetErrorLevel 1654 # WinError.h: `ERROR_INSTALL_REJECTED`
122     Abort
123   ${EndIf}
125   ${IfNot} ${RunningX64}
126     MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_64bit) /SD IDOK
127     SetErrorLevel 1654 # WinError.h: `ERROR_INSTALL_REJECTED`
128     Abort
129   ${EndIf}
131   ;Search if qBittorrent is already installed.
132   FindFirst $0 $1 "$INSTDIR\uninst.exe"
133   FindClose $0
134   StrCmp $1 "" done
136   ;Copy old value to var so we can call the correct uninstaller
137   StrCpy $uninstallerPath $INSTDIR
139   ;Inform the user
140   MessageBox MB_OKCANCEL|MB_ICONINFORMATION $(inst_uninstall_question) /SD IDOK IDOK done
141   Quit
143   done:
145 FunctionEnd
147 Function check_instance
149   check:
150   FindProcDLL::FindProc "qbittorrent.exe"
151   StrCmp $R0 "1" 0 notfound
152   MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION $(inst_warning) /SD IDCANCEL IDRETRY check IDCANCEL canceled
154   canceled:
155   SetErrorLevel 15618 # WinError.h: `ERROR_PACKAGES_IN_USE`
156   Abort
158   notfound:
160 FunctionEnd
162 Function PageFinishRun
164   !insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\qbittorrent.exe" "" "" ""
166 FunctionEnd
168 Function .onInstSuccess
169   SetErrorLevel 0
170 FunctionEnd