1 #Title AbiWord for Windows, NSIS v2 series installer script
2 #FileDesc Utility functions to set and save/restore file extension to application associations
5 !ifndef _ABI_UTIL_FILEASSOC_NSH_
6 !define _ABI_UTIL_FILEASSOC_NSH_
9 !ifdef HAVE_SYSTEM_PLUGIN
10 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 #; RefreshShellIcons based on
12 #; http://nsis.sourceforge.net/archive/nsisweb.php?page=236&instances=0
13 #; by jerome tremblay - april 2003
15 !define SHCNE_ASSOCCHANGED 0x08000000
16 !define SHCNF_IDLIST 0
18 Function RefreshShellIcons
19 System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v \
20 (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
23 !define RefreshShellIcons "call RefreshShellIcons"
25 !define RefreshShellIcons
26 !endif ; HAVE_SYSTEM_PLUGIN
29 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 #; parts from http://nsis.sourceforge.net/archive/viewpage.php?pageid=282 by Vytautas
31 #; Will add the registry entries to associate the given file extension with the
32 #; previously set (see CreateApplicationAssociation) appType. I.e. indicate to
33 #; open documents with this extension using the application specified by appType
34 #; registry entry. If the extension is currently associated with a different
35 #; appType, it will store the current association in the "prior_appType" key.
37 !macro CreateFileAssociation extension appType contentType
38 !define skipBackupLbl "skipBackup_${__LINE__}"
41 # back up old value of extension (.ext) if it exists
42 ReadRegStr $0 HKCR "${extension}" "" ; read current value
43 StrCmp $0 "" "${skipBackupLbl}" ; nothing, then skip storing old value
44 StrCmp $0 "${appType}" "${skipBackupLbl}" ; only store if old is different than current
45 WriteRegStr HKCR "${extension}" "prior_value" "$0" ; actually store the old association
48 # Write File Associations
49 WriteRegStr HKCR "${extension}" "" "${appType}"
50 WriteRegStr HKCR "${extension}" "Content Type" "${contentType}"
51 # Force shell refresh (so icons updated as needed)
57 !define CreateFileAssociation "!insertmacro CreateFileAssociation"
60 !macro CreateApplicationAssociation appType appName appDesc defIcon exeCmd
61 WriteRegStr HKCR "${appType}" "" "${appDesc}"
62 WriteRegStr HKCR "${appType}\shell" "" "open"
63 WriteRegStr HKCR "${appType}\DefaultIcon" "" "${defIcon}"
65 # Basic command to open the file (pass filename as argv[1] to program executable)
66 WriteRegStr HKCR "${appType}\shell\open\command" "" '"${exeCmd}" "%1"'
68 # To open file via DDE (OLE, ie via already active instance) instead of in a new process
69 # Here for those who want to locally enable, not normally used as having each document
70 # open in a new process while more resource intensive means a crash with one document
71 # won't cause loss of work with other open documents.
72 # WriteRegStr HKCR "${appType}\shell\open\command" "" "${exeCmd}"
73 # WriteRegStr HKCR "${appType}\shell\open\ddeexec" "" '[Open("%1")]'
74 # WriteRegStr HKCR "${appType}\shell\open\ddeexec\application" "" "${appName}"
75 # WriteRegStr HKCR "${appType}\shell\open\ddeexec\topic" "" "System"
77 # If editing file is a different action than simply opening file
78 # WriteRegStr HKCR "${appType}\shell\edit" "" "Edit Options File"
79 # WriteRegStr HKCR "${appType}\shell\edit\command" "" '"${exeCmd}" "%1"'
82 !define CreateApplicationAssociation "!insertmacro CreateApplicationAssociation"
85 # check if a file extension is associated with us and if so delete it
86 !macro RemoveFileAssociation extension appType
90 ReadRegStr $0 HKCR "${extension}" ""
91 StrCmp "$0" "${appType}" 0 Skip_Del_File_Assoc.${extension}
92 ReadRegStr $0 HKCR "${extension}" "prior_value"
93 StrCmp "$0" "" "DeleteFA.${extension}" 0 ; if "prior_value" is not empty
94 ReadRegStr $1 HKCR "$0" "" ; restore previous association
95 StrCmp "$1" "" DeleteFA.${extension} ; only if it is still valid (has something defined)
96 WriteRegStr HKCR "${extension}" "" $0 ; actually restore prior association
97 DeleteRegValue HKCR "${extension}" "prior_value" ; and remove stored value
98 Goto Skip_Del_File_Assoc.${extension}
99 DeleteFA.${extension}: ; else delete file association key
100 DeleteRegKey HKCR "${extension}" ; actually remove file assoications
102 Skip_Del_File_Assoc.${extension}:
106 !define RemoveFileAssociation "!insertmacro RemoveFileAssociation"
109 !endif ; _ABI_UTIL_FILEASSOC_NSH_