-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtocolAssociation.nsh
192 lines (145 loc) · 4.85 KB
/
ProtocolAssociation.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
_____________________________________________________________________________
Protocol Association
(c) 2009 JDownloader
_____________________________________________________________________________
Based on code taken from http://nsis.sourceforge.net/File_Association
Usage in script:
1. !include "ProtocolAssociation.nsh"
2. [Section|Function]
${ProtocolAssociationFunction} "Param1" "Param2" "..." $var
[SectionEnd|FunctionEnd]
ProtocolAssociationFunction=[RegisterProtocol|UnRegisterProtocol]
_____________________________________________________________________________
${RegisterProtocol} "[executable]" "[protocol]" "[description]"
"[executable]" ; executable which opens the protocol format
;
"[protocol]" ; protocol, which represents the protocol to open
;
"[description]" ; description for the protocol. This will be display in Windows Explorer.
;
${UnRegisterProtocol} "[protocol]" "[description]"
"[protocol]" ; protocol, which represents the protocol format to open
;
"[description]" ; description for the protocol. This will be display in Windows Explorer.
;
_____________________________________________________________________________
Macros
_____________________________________________________________________________
Change log window verbosity (default: 3=no script)
Example:
!include "ProtocolAssociation.nsh"
!insertmacro RegisterProtocol
${ProtocolAssociation_VERBOSE} 4 # all verbosity
!insertmacro UnRegisterProtocol
${ProtocolAssociation_VERBOSE} 3 # no script
*/
!ifndef ProtocolAssociation_INCLUDED
!define ProtocolAssociation_INCLUDED
!include Util.nsh
!verbose push
!verbose 3
!ifndef _ProtocolAssociation_VERBOSE
!define _ProtocolAssociation_VERBOSE 3
!endif
!verbose ${_ProtocolAssociation_VERBOSE}
!define ProtocolAssociation_VERBOSE `!insertmacro ProtocolAssociation_VERBOSE`
!verbose pop
!macro ProtocolAssociation_VERBOSE _VERBOSE
!verbose push
!verbose 3
!undef _ProtocolAssociation_VERBOSE
!define _ProtocolAssociation_VERBOSE ${_VERBOSE}
!verbose pop
!macroend
!macro RegisterProtocolCall _EXECUTABLE _PROTOCOL _DESCRIPTION
!verbose push
!verbose ${_ProtocolAssociation_VERBOSE}
Push `${_DESCRIPTION}`
Push `${_PROTOCOL}`
Push `${_EXECUTABLE}`
${CallArtificialFunction} RegisterProtocol_
!verbose pop
!macroend
!macro UnRegisterProtocolCall _PROTOCOL _DESCRIPTION
!verbose push
!verbose ${_ProtocolAssociation_VERBOSE}
Push `${_PROTOCOL}`
Push `${_DESCRIPTION}`
${CallArtificialFunction} UnRegisterProtocol_
!verbose pop
!macroend
!define RegisterProtocol `!insertmacro RegisterProtocolCall`
!define un.RegisterProtocol `!insertmacro RegisterProtocolCall`
!macro RegisterProtocol
!macroend
!macro un.RegisterProtocol
!macroend
!macro RegisterProtocol_
!verbose push
!verbose ${_ProtocolAssociation_VERBOSE}
Exch $R2 ;exe
Exch
Exch $R1 ;protocol
Exch
Exch 2
Exch $R0 ;desc
Exch 2
Push $0
Push $1
ReadRegStr $1 HKCR $R1 "" ; read current protocol association
StrCmp "$1" "" NoProtocolBackup ; is it empty
StrCmp "$1" $R0 NoProtocolBackup ; is it our own
WriteRegStr HKCR $R1 "backup_val" "$1" ; backup current value
ReadRegStr $1 HKCR "$R1\shell\open\command" "" ; backup assoc. exe
WriteRegStr HKCR "$R1\shell\open\command" "backup_val" "$1"
NoProtocolBackup:
WriteRegStr HKCR $R1 "" $R0 ; set our protocol association
WriteRegStr HKCR $R1 "URL Protocol" "" ; set it as protocol
ReadRegStr $0 HKCR "$R1\DefaultIcon" ""
StrCmp $0 "" 0 ProtocolSkip
WriteRegStr HKCR "$R1\DefaultIcon" "" "$R2,0"
ProtocolSkip:
WriteRegStr HKCR "$R1\shell\open\command" "" '"$R2" "%1"'
Pop $1
Pop $0
Pop $R2
Pop $R1
Pop $R0
!verbose pop
!macroend
!define UnRegisterProtocol `!insertmacro UnRegisterProtocolCall`
!define un.UnRegisterProtocol `!insertmacro UnRegisterProtocolCall`
!macro UnRegisterProtocol
!macroend
!macro un.UnRegisterProtocol
!macroend
!macro UnRegisterProtocol_
!verbose push
!verbose ${_ProtocolAssociation_VERBOSE}
Exch $R1 ;desc
Exch
Exch $R0 ;protocol
Exch
Push $0
Push $1
ReadRegStr $1 HKCR $R0 ""
StrCmp $1 $R1 0 NoOwnProtocol ; only do this if we own it
ReadRegStr $1 HKCR $R0 "backup_val"
StrCmp $1 "" 0 ProtocolRestore ; if backup="" then delete the whole key
DeleteRegKey HKCR $R0
Goto NoOwnProtocol
ProtocolRestore:
WriteRegStr HKCR $R0 "" $1
DeleteRegValue HKCR $R0 "backup_val"
ReadRegStr $1 HKCR "$R0\shell\open\command" "backup_val"
WriteRegStr HKCR "$R0\shell\open\command" "" $1
DeleteRegValue HKCR "$R0\shell\open\command" "backup_val"
NoOwnProtocol:
Pop $1
Pop $0
Pop $R1
Pop $R0
!verbose pop
!macroend
!endif # !ProtocolAssociation_INCLUDED