-
Notifications
You must be signed in to change notification settings - Fork 13
/
RegisterExtension.nsh
163 lines (132 loc) · 3.89 KB
/
RegisterExtension.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
!ifndef ASSOCIATE_FILE_NSH
!define ASSOCIATE_FILE_NSH
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; AssociateFile
;;
;; Associate a filetype with a certain program
;;
;; Written by Tobbe for the Litestep OpenSource Installer (LOSI)
;; Based on the code found at http://nsis.sourceforge.net/File_Association
;;
;; Usage (to add an association):
;; Push ".ext"
;; Push "Program.ext"
;; Push "File Opened with program.exe"
;; Push "$INSTDIR\program.exe" OR Push "$INSTDIR\viewer.exe"
;; Push "$INSTDIR\program.exe" OR Push "$INSTDIR\editor.exe"
;; Push "program.exe,1" OR Push "$INSTDIR\file.ico"
;; Call AssociateFile
;;
;; Usage (to remove an association that has previously been added)
;; Push ".ext"
;; Push "Program.ext"
;; Call un.DeAssociateFile
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function AssociateFile
; Set up important variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Push "#"
; The file extension
Exch 6
Exch $2
; General Description, use something unique!
; (ApplicationName.FileType, CompanyName-ApplicationName.FileType,
; or FileType-file might be good choises)
Exch 5
Exch $3
; File Description as seen for example when rightclicking on
; the file and selecting Properties
Exch 4
Exch $4
; Program used to open the file, use a full pathname
Exch 3
Exch $5
StrCpy $R0 $5 1
StrCmp $R0 '"' +2
StrCpy $5 '"$5"'
; Program used to edit the file, often the same as used
; when opening it
Exch 2
Exch $6
StrCpy $R0 $6 1
StrCmp $R0 '"' +2
StrCpy $6 '"$6"'
; File icon
Exch
Exch $7
; The actual script, should be no need to edit it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Push $0
Push $1
; back up old value
!define Index "Line${__LINE__}" ;${__LINE__} resolves to the current linenumber
ReadRegStr $1 HKCR $2 ""
StrCmp $1 "" "${Index}-NoBackup"
StrCmp $1 $3 "${Index}-NoBackup"
WriteRegStr HKCR $2 "backup_val" $1
"${Index}-NoBackup:"
WriteRegStr HKCR $2 "" $3
ReadRegStr $0 HKCR $3 ""
StrCmp $0 "" 0 "${Index}-Skip"
WriteRegStr HKCR $3 "" $4
WriteRegStr HKCR "$3\shell" "" "open"
StrCmp $7 "" "${Index}-Skip" ; Only define an icon if we have a value for it
WriteRegStr HKCR "$3\DefaultIcon" "" $7
"${Index}-Skip:"
WriteRegExpandStr HKCR "$3\shell\open\command" "" '$5 "%1"'
WriteRegStr HKCR "$3\shell\edit" "" '"$4"'
WriteRegExpandStr HKCR "$3\shell\edit\command" "" '$6 "%1"'
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
!undef Index
; Restore the variables
Pop $1
Pop $0
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
FunctionEnd
Function un.DeAssociateFile
; Set up important variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Push "#"
; The file extension
Exch 2
Exch $2
; General Description, use something unique!
; (ApplicationName.FileType, CompanyName-ApplicationName.FileType,
; or FileType-file might be good choises)
Exch
Exch $3
; The actual script, should be no need to edit it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Push $0
Push $1
;start of restore script
!define Index "Line${__LINE__}"
ReadRegStr $1 HKCR $2 ""
StrCmp $1 $3 0 "${Index}-NoOwn" ; only do this if we own it
ReadRegStr $1 HKCR $2 "backup_val"
StrCmp $1 "" 0 "${Index}-Restore" ; if backup="" then delete the whole key
DeleteRegKey HKCR $2
DeleteRegKey HKCR $3 ; DUNNO IF I REALLY SHOULD DO THIS!! ;Delete key with association settings
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
Goto "${Index}-NoOwn"
"${Index}-Restore:"
WriteRegStr HKCR $2 "" $1
DeleteRegValue HKCR $2 "backup_val"
DeleteRegKey HKCR $3 ;Delete key with association settings
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
"${Index}-NoOwn:"
!undef Index
; Restore the variables
Pop $1
Pop $0
Pop $3
Pop $2
FunctionEnd
!endif