Move wrapper script in source package to debian/jabref-wrapper and
[debian/jabref.git] / src / windows / nsis / fileassoc.nsh
1 ; fileassoc.nsh
2 ; File association helper macros
3 ; Written by Saivert
4 ;
5 ; Features automatic backup system and UPDATEFILEASSOC macro for
6 ; shell change notification.
7 ;
8 ; |> How to use <|
9 ; To associate a file with an application so you can double-click it in explorer, use
10 ; the APP_ASSOCIATE macro like this:
11 ;
12 ;   Example:
13 ;   !insertmacro APP_ASSOCIATE "txt" "myapp.textfile" "$INSTDIR\myapp.exe,0" \
14 ;     "Open with myapp" "$INSTDIR\myapp.exe $\"%1$\""
15 ;
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.
20 ;
21 ;   Example:
22 ;   !insertmacro APP_ASSOCIATE_ADDVERB "myapp.textfile" "edit" "Edit with myapp" \
23 ;     "$INSTDIR\myapp.exe /edit $\"%1$\""
24 ;
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).
28 ;
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"
32 ;
33 ; |> Note <|
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.
36 ;   Examples:
37 ;   Winamp.Playlist
38 ;   NSIS.Script
39 ;   Photoshop.JPEGFile
40 ;
41 ; |> Tech info <|
42 ; The registry key layout for a file association is:
43 ; HKEY_CLASSES_ROOT
44 ;     <applicationID> = <"description">
45 ;         shell
46 ;             <verb> = <"menu-item text">
47 ;                 command = <"command string">
48 ;
49  
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"
54  
55   WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"
56  
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}`
62 !macroend
63  
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"
68  
69   WriteRegStr HKCR ".${EXT}" "" "${FILECLASS}"
70   StrCmp "${SHELLNEW}" "0" +2
71   WriteRegStr HKCR ".${EXT}\ShellNew" "NullFile" ""
72  
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}`
78 !macroend
79  
80 !macro APP_ASSOCIATE_ADDVERB FILECLASS VERB COMMANDTEXT COMMAND
81   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`
82   WriteRegStr HKCR "${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`
83 !macroend
84  
85 !macro APP_ASSOCIATE_REMOVEVERB FILECLASS VERB
86   DeleteRegKey HKCR `${FILECLASS}\shell\${VERB}`
87 !macroend
88  
89  
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"
94  
95   DeleteRegKey HKCR `${FILECLASS}`
96 !macroend
97  
98 !macro APP_ASSOCIATE_GETFILECLASS OUTPUT EXT
99   ReadRegStr ${OUTPUT} HKCR ".${EXT}" ""
100 !macroend
101  
102  
103 ; !defines for use with SHChangeNotify
104 !ifdef SHCNE_ASSOCCHANGED
105 !undef SHCNE_ASSOCCHANGED
106 !endif
107 !define SHCNE_ASSOCCHANGED 0x08000000
108 !ifdef SHCNF_FLUSH
109 !undef SHCNF_FLUSH
110 !endif
111 !define SHCNF_FLUSH        0x1000
112  
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)"
117 !macroend
118  
119 ;EOF