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