Merge tag 'upstream/2.9.1+ds' into experimental
[debian/jabref.git] / src / windows / nsis / fileassoc.nsh
1 ; fileassoc.nsh\r
2 ; File association helper macros\r
3 ; Written by Saivert\r
4 ;\r
5 ; Features automatic backup system and UPDATEFILEASSOC macro for\r
6 ; shell change notification.\r
7 ;\r
8 ; |> How to use <|\r
9 ; To associate a file with an application so you can double-click it in explorer, use\r
10 ; the APP_ASSOCIATE macro like this:\r
11 ;\r
12 ;   Example:\r
13 ;   !insertmacro APP_ASSOCIATE "txt" "myapp.textfile" "$INSTDIR\myapp.exe,0" \\r
14 ;     "Open with myapp" "$INSTDIR\myapp.exe $\"%1$\""\r
15 ;\r
16 ; Never insert the APP_ASSOCIATE macro multiple times, it is only ment\r
17 ; to associate an application with a single file and using the\r
18 ; the "open" verb as default. To add more verbs (actions) to a file\r
19 ; use the APP_ASSOCIATE_ADDVERB macro.\r
20 ;\r
21 ;   Example:\r
22 ;   !insertmacro APP_ASSOCIATE_ADDVERB "myapp.textfile" "edit" "Edit with myapp" \\r
23 ;     "$INSTDIR\myapp.exe /edit $\"%1$\""\r
24 ;\r
25 ; To have access to more options when registering the file association use the\r
26 ; APP_ASSOCIATE_EX macro. Here you can specify the verb and what verb is to be the\r
27 ; standard action (default verb).\r
28 ;\r
29 ; And finally: To remove the association from the registry use the APP_UNASSOCIATE\r
30 ; macro. Here is another example just to wrap it up:\r
31 ;   !insertmacro APP_UNASSOCIATE "txt" "myapp.textfile"\r
32 ;\r
33 ; |> Note <|\r
34 ; When defining your file class string always use the short form of your application title\r
35 ; then a period (dot) and the type of file. This keeps the file class sort of unique.\r
36 ;   Examples:\r
37 ;   Winamp.Playlist\r
38 ;   NSIS.Script\r
39 ;   Photoshop.JPEGFile\r
40 ;\r
41 ; |> Tech info <|\r
42 ; The registry key layout for a file association is:\r
43 ; HKEY_CLASSES_ROOT\r
44 ;     <applicationID> = <"description">\r
45 ;         shell\r
46 ;             <verb> = <"menu-item text">\r
47 ;                 command = <"command string">\r
48 ;\r
49  \r
50 !macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND\r
51   ; Backup the previously associated file class\r
52   ReadRegStr $R0 HKCR ".${EXT}" ""\r
53   WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0"\r
54  \r
55   WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"\r
56  \r
57   WriteRegStr HKCR "${FILECLASS}" "" `${DESCRIPTION}`\r
58   WriteRegStr HKCR "${FILECLASS}\DefaultIcon" "" `${ICON}`\r
59   WriteRegStr HKCR "${FILECLASS}\shell" "" "open"\r
60   WriteRegStr HKCR "${FILECLASS}\shell\open" "" `${COMMANDTEXT}`\r
61   WriteRegStr HKCR "${FILECLASS}\shell\open\command" "" `${COMMAND}`\r
62 !macroend\r
63  \r
64 !macro APP_ASSOCIATE_EX EXT FILECLASS DESCRIPTION ICON VERB DEFAULTVERB SHELLNEW COMMANDTEXT COMMAND\r
65   ; Backup the previously associated file class\r
66   ReadRegStr $R0 HKCR ".${EXT}" ""\r
67   WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0"\r
68  \r
69   WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"\r
70   StrCmp "${SHELLNEW}" "0" +2\r
71   WriteRegStr HKCR ".${EXT}\ShellNew" "NullFile" ""\r
72  \r
73   WriteRegStr HKCR "${FILECLASS}" "" `${DESCRIPTION}`\r
74   WriteRegStr HKCR "${FILECLASS}\DefaultIcon" "" `${ICON}`\r
75   WriteRegStr HKCR "${FILECLASS}\shell" "" `${DEFAULTVERB}`\r
76   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`\r
77   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`\r
78 !macroend\r
79  \r
80 !macro APP_ASSOCIATE_ADDVERB FILECLASS VERB COMMANDTEXT COMMAND\r
81   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`\r
82   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`\r
83 !macroend\r
84  \r
85 !macro APP_ASSOCIATE_REMOVEVERB FILECLASS VERB\r
86   DeleteRegKey HKCR `${FILECLASS}\shell\${VERB}`\r
87 !macroend\r
88  \r
89  \r
90 !macro APP_UNASSOCIATE EXT FILECLASS\r
91   ; Backup the previously associated file class\r
92   ReadRegStr $R0 HKCR ".${EXT}" `${FILECLASS}_backup`\r
93   WriteRegStr HKCR ".${EXT}" "" "$R0"\r
94  \r
95   DeleteRegKey HKCR `${FILECLASS}`\r
96 !macroend\r
97  \r
98 !macro APP_ASSOCIATE_GETFILECLASS OUTPUT EXT\r
99   ReadRegStr ${OUTPUT} HKCR ".${EXT}" ""\r
100 !macroend\r
101  \r
102  \r
103 ; !defines for use with SHChangeNotify\r
104 !ifdef SHCNE_ASSOCCHANGED\r
105 !undef SHCNE_ASSOCCHANGED\r
106 !endif\r
107 !define SHCNE_ASSOCCHANGED 0x08000000\r
108 !ifdef SHCNF_FLUSH\r
109 !undef SHCNF_FLUSH\r
110 !endif\r
111 !define SHCNF_FLUSH        0x1000\r
112  \r
113 !macro UPDATEFILEASSOC\r
114 ; Using the system.dll plugin to call the SHChangeNotify Win32 API function so we\r
115 ; can update the shell.\r
116   System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"\r
117 !macroend\r
118  \r
119 ;EOF\r