]> git.street.me.uk Git - andy/viking.git/blob - win32/installer/FileAssociation.nsh
Remove OSM web link layer options so you now get what ever is the OSM default.
[andy/viking.git] / win32 / installer / FileAssociation.nsh
1 /*\r
2 _____________________________________________________________________________\r
3  \r
4                        File Association\r
5 _____________________________________________________________________________\r
6  \r
7  Based on code taken from http://nsis.sourceforge.net/File_Association \r
8  \r
9  Usage in script:\r
10  1. !include "FileAssociation.nsh"\r
11  2. [Section|Function]\r
12       ${FileAssociationFunction} "Param1" "Param2" "..." $var\r
13     [SectionEnd|FunctionEnd]\r
14  \r
15  FileAssociationFunction=[RegisterExtension|UnRegisterExtension]\r
16  \r
17 _____________________________________________________________________________\r
18  \r
19  ${RegisterExtension} "[executable]" "[extension]" "[description]"\r
20  \r
21 "[executable]"     ; executable which opens the file format\r
22                    ;\r
23 "[extension]"      ; extension, which represents the file format to open\r
24                    ;\r
25 "[description]"    ; description for the extension. This will be display in Windows Explorer.\r
26                    ;\r
27  \r
28  \r
29  ${UnRegisterExtension} "[extension]" "[description]"\r
30  \r
31 "[extension]"      ; extension, which represents the file format to open\r
32                    ;\r
33 "[description]"    ; description for the extension. This will be display in Windows Explorer.\r
34                    ;\r
35  \r
36 _____________________________________________________________________________\r
37  \r
38                          Macros\r
39 _____________________________________________________________________________\r
40  \r
41  Change log window verbosity (default: 3=no script)\r
42  \r
43  Example:\r
44  !include "FileAssociation.nsh"\r
45  !insertmacro RegisterExtension\r
46  ${FileAssociation_VERBOSE} 4   # all verbosity\r
47  !insertmacro UnRegisterExtension\r
48  ${FileAssociation_VERBOSE} 3   # no script\r
49 */\r
50  \r
51  \r
52 !ifndef FileAssociation_INCLUDED\r
53 !define FileAssociation_INCLUDED\r
54  \r
55 !include Util.nsh\r
56  \r
57 !verbose push\r
58 !verbose 3\r
59 !ifndef _FileAssociation_VERBOSE\r
60   !define _FileAssociation_VERBOSE 3\r
61 !endif\r
62 !verbose ${_FileAssociation_VERBOSE}\r
63 !define FileAssociation_VERBOSE `!insertmacro FileAssociation_VERBOSE`\r
64 !verbose pop\r
65  \r
66 !macro FileAssociation_VERBOSE _VERBOSE\r
67   !verbose push\r
68   !verbose 3\r
69   !undef _FileAssociation_VERBOSE\r
70   !define _FileAssociation_VERBOSE ${_VERBOSE}\r
71   !verbose pop\r
72 !macroend\r
73  \r
74  \r
75  \r
76 !macro RegisterExtensionCall _EXECUTABLE _EXTENSION _DESCRIPTION\r
77   !verbose push\r
78   !verbose ${_FileAssociation_VERBOSE}\r
79   Push `${_DESCRIPTION}`\r
80   Push `${_EXTENSION}`\r
81   Push `${_EXECUTABLE}`\r
82   ${CallArtificialFunction} RegisterExtension_\r
83   !verbose pop\r
84 !macroend\r
85  \r
86 !macro UnRegisterExtensionCall _EXTENSION _DESCRIPTION\r
87   !verbose push\r
88   !verbose ${_FileAssociation_VERBOSE}\r
89   Push `${_EXTENSION}`\r
90   Push `${_DESCRIPTION}`\r
91   ${CallArtificialFunction} UnRegisterExtension_\r
92   !verbose pop\r
93 !macroend\r
94  \r
95  \r
96  \r
97 !define RegisterExtension `!insertmacro RegisterExtensionCall`\r
98 !define un.RegisterExtension `!insertmacro RegisterExtensionCall`\r
99  \r
100 !macro RegisterExtension\r
101 !macroend\r
102  \r
103 !macro un.RegisterExtension\r
104 !macroend\r
105  \r
106 !macro RegisterExtension_\r
107   !verbose push\r
108   !verbose ${_FileAssociation_VERBOSE}\r
109  \r
110   Exch $R2 ;exe\r
111   Exch\r
112   Exch $R1 ;ext\r
113   Exch\r
114   Exch 2\r
115   Exch $R0 ;desc\r
116   Exch 2\r
117   Push $0\r
118   Push $1\r
119  \r
120   ReadRegStr $1 HKCR $R1 ""  ; read current file association\r
121   StrCmp "$1" "" NoBackup  ; is it empty\r
122   StrCmp "$1" "$R0" NoBackup  ; is it our own\r
123     WriteRegStr HKCR $R1 "backup_val" "$1"  ; backup current value\r
124 NoBackup:\r
125   WriteRegStr HKCR $R1 "" "$R0"  ; set our file association\r
126  \r
127   ReadRegStr $0 HKCR $R0 ""\r
128   StrCmp $0 "" 0 Skip\r
129     WriteRegStr HKCR "$R0" "" "$R0"\r
130     WriteRegStr HKCR "$R0\shell" "" "open"\r
131     WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,0"\r
132 Skip:\r
133   WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1"'\r
134   WriteRegStr HKCR "$R0\shell\edit" "" "Edit $R0"\r
135   WriteRegStr HKCR "$R0\shell\edit\command" "" '"$R2" "%1"'\r
136  \r
137   Pop $1\r
138   Pop $0\r
139   Pop $R2\r
140   Pop $R1\r
141   Pop $R0\r
142  \r
143   !verbose pop\r
144 !macroend\r
145  \r
146  \r
147  \r
148 !define UnRegisterExtension `!insertmacro UnRegisterExtensionCall`\r
149 !define un.UnRegisterExtension `!insertmacro UnRegisterExtensionCall`\r
150  \r
151 !macro UnRegisterExtension\r
152 !macroend\r
153  \r
154 !macro un.UnRegisterExtension\r
155 !macroend\r
156  \r
157 !macro UnRegisterExtension_\r
158   !verbose push\r
159   !verbose ${_FileAssociation_VERBOSE}\r
160  \r
161   Exch $R1 ;desc\r
162   Exch\r
163   Exch $R0 ;ext\r
164   Exch\r
165   Push $0\r
166   Push $1\r
167  \r
168   ReadRegStr $1 HKCR $R0 ""\r
169   StrCmp $1 $R1 0 NoOwn ; only do this if we own it\r
170   ReadRegStr $1 HKCR $R0 "backup_val"\r
171   StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key\r
172   DeleteRegKey HKCR $R0\r
173   Goto NoOwn\r
174  \r
175 Restore:\r
176   WriteRegStr HKCR $R0 "" $1\r
177   DeleteRegValue HKCR $R0 "backup_val"\r
178   DeleteRegKey HKCR $R1 ;Delete key with association name settings\r
179  \r
180 NoOwn:\r
181  \r
182   Pop $1\r
183   Pop $0\r
184   Pop $R1\r
185   Pop $R0\r
186  \r
187   !verbose pop\r
188 !macroend\r
189  \r
190 !endif # !FileAssociation_INCLUDED\r