2 ; File association helper macros
5 ; Features automatic backup system and UPDATEFILEASSOC macro for
6 ; shell change notification.
9 ; To associate a file with an application so you can double-click it in explorer, use
10 ; the APP_ASSOCIATE macro like this:
13 ; !insertmacro APP_ASSOCIATE "txt" "myapp.textfile" "$INSTDIR\myapp.exe,0" \
14 ; "Open with myapp" "$INSTDIR\myapp.exe $\"%1$\""
16 ; Never insert the APP_ASSOCIATE macro multiple times, it is only ment
17 ; to associate an application with a single file and using the
18 ; the "open" verb as default. To add more verbs (actions) to a file
19 ; use the APP_ASSOCIATE_ADDVERB macro.
22 ; !insertmacro APP_ASSOCIATE_ADDVERB "myapp.textfile" "edit" "Edit with myapp" \
23 ; "$INSTDIR\myapp.exe /edit $\"%1$\""
25 ; To have access to more options when registering the file association use the
26 ; APP_ASSOCIATE_EX macro. Here you can specify the verb and what verb is to be the
27 ; standard action (default verb).
29 ; And finally: To remove the association from the registry use the APP_UNASSOCIATE
30 ; macro. Here is another example just to wrap it up:
31 ; !insertmacro APP_UNASSOCIATE "txt" "myapp.textfile"
34 ; When defining your file class string always use the short form of your application title
35 ; then a period (dot) and the type of file. This keeps the file class sort of unique.
42 ; The registry key layout for a file association is:
44 ; <applicationID> = <"description">
46 ; <verb> = <"menu-item text">
47 ; command = <"command string">
50 !macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
51 ; Backup the previously associated file class
52 ReadRegStr $R0 HKCR ".${EXT}" ""
53 WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0"
55 WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"
57 WriteRegStr HKCR "${FILECLASS}" "" `${DESCRIPTION}`
58 WriteRegStr HKCR "${FILECLASS}\DefaultIcon" "" `${ICON}`
59 WriteRegStr HKCR "${FILECLASS}\shell" "" "open"
60 WriteRegStr HKCR "${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
61 WriteRegStr HKCR "${FILECLASS}\shell\open\command" "" `${COMMAND}`
64 !macro APP_ASSOCIATE_EX EXT FILECLASS DESCRIPTION ICON VERB DEFAULTVERB SHELLNEW COMMANDTEXT COMMAND
65 ; Backup the previously associated file class
66 ReadRegStr $R0 HKCR ".${EXT}" ""
67 WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0"
69 WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"
70 StrCmp "${SHELLNEW}" "0" +2
71 WriteRegStr HKCR ".${EXT}\ShellNew" "NullFile" ""
73 WriteRegStr HKCR "${FILECLASS}" "" `${DESCRIPTION}`
74 WriteRegStr HKCR "${FILECLASS}\DefaultIcon" "" `${ICON}`
75 WriteRegStr HKCR "${FILECLASS}\shell" "" `${DEFAULTVERB}`
76 WriteRegStr HKCR "${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`
77 WriteRegStr HKCR "${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`
80 !macro APP_ASSOCIATE_ADDVERB FILECLASS VERB COMMANDTEXT COMMAND
81 WriteRegStr HKCR "${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`
82 WriteRegStr HKCR "${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`
85 !macro APP_ASSOCIATE_REMOVEVERB FILECLASS VERB
86 DeleteRegKey HKCR `${FILECLASS}\shell\${VERB}`
90 !macro APP_UNASSOCIATE EXT FILECLASS
91 ; Backup the previously associated file class
92 ReadRegStr $R0 HKCR ".${EXT}" `${FILECLASS}_backup`
93 WriteRegStr HKCR ".${EXT}" "" "$R0"
95 DeleteRegKey HKCR `${FILECLASS}`
98 !macro APP_ASSOCIATE_GETFILECLASS OUTPUT EXT
99 ReadRegStr ${OUTPUT} HKCR ".${EXT}" ""
103 ; !defines for use with SHChangeNotify
104 !ifdef SHCNE_ASSOCCHANGED
105 !undef SHCNE_ASSOCCHANGED
107 !define SHCNE_ASSOCCHANGED 0x08000000
111 !define SHCNF_FLUSH 0x1000
113 !macro UPDATEFILEASSOC
114 ; Using the system.dll plugin to call the SHChangeNotify Win32 API function so we
115 ; can update the shell.
116 System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"