2 _____________________________________________________________________________
5 _____________________________________________________________________________
7 Based on code taken from http://nsis.sourceforge.net/File_Association
10 1. !include "FileAssociation.nsh"
12 ${FileAssociationFunction} "Param1" "Param2" "..." $var
13 [SectionEnd|FunctionEnd]
15 FileAssociationFunction=[RegisterExtension|UnRegisterExtension]
17 _____________________________________________________________________________
19 ${RegisterExtension} "[executable]" "[extension]" "[description]"
21 "[executable]" ; executable which opens the file format
23 "[extension]" ; extension, which represents the file format to open
25 "[description]" ; description for the extension. This will be display in Windows Explorer.
29 ${UnRegisterExtension} "[extension]" "[description]"
31 "[extension]" ; extension, which represents the file format to open
33 "[description]" ; description for the extension. This will be display in Windows Explorer.
36 _____________________________________________________________________________
39 _____________________________________________________________________________
41 Change log window verbosity (default: 3=no script)
44 !include "FileAssociation.nsh"
45 !insertmacro RegisterExtension
46 ${FileAssociation_VERBOSE} 4 # all verbosity
47 !insertmacro UnRegisterExtension
48 ${FileAssociation_VERBOSE} 3 # no script
52 !ifndef FileAssociation_INCLUDED
53 !define FileAssociation_INCLUDED
59 !ifndef _FileAssociation_VERBOSE
60 !define _FileAssociation_VERBOSE 3
62 !verbose ${_FileAssociation_VERBOSE}
63 !define FileAssociation_VERBOSE `!insertmacro FileAssociation_VERBOSE`
66 !macro FileAssociation_VERBOSE _VERBOSE
69 !undef _FileAssociation_VERBOSE
70 !define _FileAssociation_VERBOSE ${_VERBOSE}
76 !macro RegisterExtensionCall _EXECUTABLE _EXTENSION _DESCRIPTION
78 !verbose ${_FileAssociation_VERBOSE}
79 Push `${_DESCRIPTION}`
82 ${CallArtificialFunction} RegisterExtension_
86 !macro UnRegisterExtensionCall _EXTENSION _DESCRIPTION
88 !verbose ${_FileAssociation_VERBOSE}
90 Push `${_DESCRIPTION}`
91 ${CallArtificialFunction} UnRegisterExtension_
97 !define RegisterExtension `!insertmacro RegisterExtensionCall`
98 !define un.RegisterExtension `!insertmacro RegisterExtensionCall`
100 !macro RegisterExtension
103 !macro un.RegisterExtension
106 !macro RegisterExtension_
108 !verbose ${_FileAssociation_VERBOSE}
120 ReadRegStr $1 HKCR $R1 "" ; read current file association
121 StrCmp "$1" "" NoBackup ; is it empty
122 StrCmp "$1" "$R0" NoBackup ; is it our own
123 WriteRegStr HKCR $R1 "backup_val" "$1" ; backup current value
125 WriteRegStr HKCR $R1 "" "$R0" ; set our file association
127 ReadRegStr $0 HKCR $R0 ""
129 WriteRegStr HKCR "$R0" "" "$R0"
130 WriteRegStr HKCR "$R0\shell" "" "open"
131 WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,0"
133 WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1"'
134 WriteRegStr HKCR "$R0\shell\edit" "" "Edit $R0"
135 WriteRegStr HKCR "$R0\shell\edit\command" "" '"$R2" "%1"'
148 !define UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
149 !define un.UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
151 !macro UnRegisterExtension
154 !macro un.UnRegisterExtension
157 !macro UnRegisterExtension_
159 !verbose ${_FileAssociation_VERBOSE}
168 ReadRegStr $1 HKCR $R0 ""
169 StrCmp $1 $R1 0 NoOwn ; only do this if we own it
170 ReadRegStr $1 HKCR $R0 "backup_val"
171 StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key
172 DeleteRegKey HKCR $R0
176 WriteRegStr HKCR $R0 "" $1
177 DeleteRegValue HKCR $R0 "backup_val"
178 DeleteRegKey HKCR $R1 ;Delete key with association name settings
190 !endif # !FileAssociation_INCLUDED