2 _____________________________________________________________________________
\r
5 _____________________________________________________________________________
\r
7 Based on code taken from http://nsis.sourceforge.net/File_Association
\r
10 1. !include "FileAssociation.nsh"
\r
11 2. [Section|Function]
\r
12 ${FileAssociationFunction} "Param1" "Param2" "..." $var
\r
13 [SectionEnd|FunctionEnd]
\r
15 FileAssociationFunction=[RegisterExtension|UnRegisterExtension]
\r
17 _____________________________________________________________________________
\r
19 ${RegisterExtension} "[executable]" "[extension]" "[description]"
\r
21 "[executable]" ; executable which opens the file format
\r
23 "[extension]" ; extension, which represents the file format to open
\r
25 "[description]" ; description for the extension. This will be display in Windows Explorer.
\r
29 ${UnRegisterExtension} "[extension]" "[description]"
\r
31 "[extension]" ; extension, which represents the file format to open
\r
33 "[description]" ; description for the extension. This will be display in Windows Explorer.
\r
36 _____________________________________________________________________________
\r
39 _____________________________________________________________________________
\r
41 Change log window verbosity (default: 3=no script)
\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
52 !ifndef FileAssociation_INCLUDED
\r
53 !define FileAssociation_INCLUDED
\r
59 !ifndef _FileAssociation_VERBOSE
\r
60 !define _FileAssociation_VERBOSE 3
\r
62 !verbose ${_FileAssociation_VERBOSE}
\r
63 !define FileAssociation_VERBOSE `!insertmacro FileAssociation_VERBOSE`
\r
66 !macro FileAssociation_VERBOSE _VERBOSE
\r
69 !undef _FileAssociation_VERBOSE
\r
70 !define _FileAssociation_VERBOSE ${_VERBOSE}
\r
76 !macro RegisterExtensionCall _EXECUTABLE _EXTENSION _DESCRIPTION
\r
78 !verbose ${_FileAssociation_VERBOSE}
\r
79 Push `${_DESCRIPTION}`
\r
80 Push `${_EXTENSION}`
\r
81 Push `${_EXECUTABLE}`
\r
82 ${CallArtificialFunction} RegisterExtension_
\r
86 !macro UnRegisterExtensionCall _EXTENSION _DESCRIPTION
\r
88 !verbose ${_FileAssociation_VERBOSE}
\r
89 Push `${_EXTENSION}`
\r
90 Push `${_DESCRIPTION}`
\r
91 ${CallArtificialFunction} UnRegisterExtension_
\r
97 !define RegisterExtension `!insertmacro RegisterExtensionCall`
\r
98 !define un.RegisterExtension `!insertmacro RegisterExtensionCall`
\r
100 !macro RegisterExtension
\r
103 !macro un.RegisterExtension
\r
106 !macro RegisterExtension_
\r
108 !verbose ${_FileAssociation_VERBOSE}
\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
125 WriteRegStr HKCR $R1 "" "$R0" ; set our file association
\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
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
148 !define UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
\r
149 !define un.UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
\r
151 !macro UnRegisterExtension
\r
154 !macro un.UnRegisterExtension
\r
157 !macro UnRegisterExtension_
\r
159 !verbose ${_FileAssociation_VERBOSE}
\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
176 WriteRegStr HKCR $R0 "" $1
\r
177 DeleteRegValue HKCR $R0 "backup_val"
\r
178 DeleteRegKey HKCR $R1 ;Delete key with association name settings
\r
190 !endif # !FileAssociation_INCLUDED
\r