-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.nsh
167 lines (115 loc) · 5.94 KB
/
installer.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Var uninstallerPath
Section "-hidden"
;Search if qBittorrent is already installed.
FindFirst $0 $1 "$uninstallerPath\uninst.exe"
FindClose $0
StrCmp $1 "" done
;Run the uninstaller of the previous install.
DetailPrint $(inst_unist)
ExecWait '"$uninstallerPath\uninst.exe" /S _?=$uninstallerPath'
Delete "$uninstallerPath\uninst.exe"
RMDir "$uninstallerPath"
done:
SectionEnd
Section $(inst_qbt_req) ;"qBittorrent (required)"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put files there
File "${QBT_DIST_DIR}\qbittorrent.exe"
File "qt.conf"
File /nonfatal /r /x "${QBT_DIST_DIR}\qbittorrent.exe" "${QBT_DIST_DIR}\*.*"
; Write the installation path into the registry
WriteRegStr HKLM "Software\qBittorrent" "InstallLocation" "$INSTDIR"
; Register qBittorrent as possible default program for .torrent files and magnet links
WriteRegStr HKLM "Software\qBittorrent\Capabilities" "ApplicationDescription" "A BitTorrent client in Qt"
WriteRegStr HKLM "Software\qBittorrent\Capabilities" "ApplicationName" "qBittorrent"
WriteRegStr HKLM "Software\qBittorrent\Capabilities\FileAssociations" ".torrent" "qBittorrent.File.Torrent"
WriteRegStr HKLM "Software\qBittorrent\Capabilities\UrlAssociations" "magnet" "qBittorrent.Url.Magnet"
WriteRegStr HKLM "Software\RegisteredApplications" "qBittorrent" "Software\qBittorrent\Capabilities"
; Register qBittorrent ProgIDs
WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent" "" "Torrent File"
WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
WriteRegStr HKLM "Software\Classes\qBittorrent.File.Torrent\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet" "" "Magnet URI"
WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet\DefaultIcon" "" '"$INSTDIR\qbittorrent.exe",1'
WriteRegStr HKLM "Software\Classes\qBittorrent.Url.Magnet\shell\open\command" "" '"$INSTDIR\qbittorrent.exe" "%1"'
WriteRegStr HKLM "Software\Classes\.torrent" "Content Type" "application/x-bittorrent"
WriteRegStr HKLM "Software\Classes\magnet" "" "URL:Magnet URI"
WriteRegStr HKLM "Software\Classes\magnet" "Content Type" "application/x-magnet"
WriteRegStr HKLM "Software\Classes\magnet" "URL Protocol" ""
System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)'
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayName" "qBittorrent"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "UninstallString" '"$INSTDIR\uninst.exe"'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayIcon" '"$INSTDIR\qbittorrent.exe",0'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "Publisher" "The qBittorrent project"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "URLInfoAbout" "https://www.qbittorrent.org"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "DisplayVersion" "${QBT_VERSION}"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "NoRepair" 1
WriteUninstaller "uninst.exe"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\qBittorrent" "EstimatedSize" "$0"
SectionEnd
; Optional section (can be disabled by the user)
Section /o $(inst_desktop) ;"Create Desktop Shortcut"
CreateShortCut "$DESKTOP\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
SectionEnd
Section $(inst_startmenu) ;"Create Start Menu Shortcut"
CreateDirectory "$SMPROGRAMS\qBittorrent"
CreateShortCut "$SMPROGRAMS\qBittorrent\qBittorrent.lnk" "$INSTDIR\qbittorrent.exe"
CreateShortCut "$SMPROGRAMS\qBittorrent\$(inst_uninstall_link_description).lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section /o $(inst_startup) ;"Start qBittorrent on Windows start up"
!insertmacro UAC_AsUser_Call Function inst_startup_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR}
SectionEnd
Function inst_startup_user
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "qBittorrent" "$INSTDIR\qbittorrent.exe"
FunctionEnd
Section $(inst_firewall)
DetailPrint $(inst_firewallinfo)
nsisFirewallW::AddAuthorizedApplication "$INSTDIR\qbittorrent.exe" "qBittorrent"
SectionEnd
Section $(inst_pathlimit) ;"Disable Windows path length limit (260 character MAX_PATH limitation, requires Windows 10 1607 or later)"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
SectionEnd
;--------------------------------
Function .onInit
!insertmacro Init "installer"
!insertmacro MUI_LANGDLL_DISPLAY
${IfNot} ${AtLeastWaaS} 1809 ; Windows 10 1809. Min supported version by Qt6
MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_win10)
Abort
${EndIf}
${IfNot} ${RunningX64}
MessageBox MB_OK|MB_ICONEXCLAMATION $(inst_requires_64bit)
Abort
${EndIf}
;Search if qBittorrent is already installed.
FindFirst $0 $1 "$INSTDIR\uninst.exe"
FindClose $0
StrCmp $1 "" done
;Copy old value to var so we can call the correct uninstaller
StrCpy $uninstallerPath $INSTDIR
;Inform the user
MessageBox MB_OKCANCEL|MB_ICONINFORMATION $(inst_uninstall_question) /SD IDOK IDOK done
Quit
done:
FunctionEnd
Function check_instance
check:
FindProcDLL::FindProc "qbittorrent.exe"
StrCmp $R0 "1" 0 notfound
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION $(inst_warning) IDRETRY check IDCANCEL done
done:
Abort
notfound:
FunctionEnd
Function PageFinishRun
!insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\qbittorrent.exe" "" "" ""
FunctionEnd
Function .onInstSuccess
SetErrorLevel 0
FunctionEnd