]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/LyXWinInstaller/abi_util_fileassoc.nsh
Change windows installer comments from ; to #
[lyx.git] / development / Win32 / packaging / installer / LyXWinInstaller / abi_util_fileassoc.nsh
1 #Title          AbiWord for Windows, NSIS v2 series installer script
2 #FileDesc       Utility functions to set and save/restore file extension to application associations
3
4
5 !ifndef _ABI_UTIL_FILEASSOC_NSH_
6 !define _ABI_UTIL_FILEASSOC_NSH_
7
8
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
14
15 !define SHCNE_ASSOCCHANGED 0x08000000
16 !define SHCNF_IDLIST 0
17
18 Function RefreshShellIcons
19   System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v \
20   (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
21 FunctionEnd
22
23 !define RefreshShellIcons "call RefreshShellIcons"
24 !else
25 !define RefreshShellIcons
26 !endif ; HAVE_SYSTEM_PLUGIN
27
28
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.
36
37 !macro CreateFileAssociation extension appType contentType
38   !define skipBackupLbl "skipBackup_${__LINE__}"
39   push $0
40
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
46
47   "${skipBackupLbl}:"
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)
52     ${RefreshShellIcons}
53
54   pop $0
55   !undef skipBackupLbl
56 !macroend
57 !define CreateFileAssociation "!insertmacro CreateFileAssociation"
58
59
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}"
64
65   # Basic command to open the file (pass filename as argv[1] to program executable)
66   WriteRegStr HKCR "${appType}\shell\open\command" "" '"${exeCmd}" "%1"'
67
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"
76
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"'
80
81 !macroend
82 !define CreateApplicationAssociation "!insertmacro CreateApplicationAssociation"
83
84
85 # check if a file extension is associated with us and if so delete it
86 !macro RemoveFileAssociation extension appType
87         push $0
88         push $1
89
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
101
102         Skip_Del_File_Assoc.${extension}:
103         pop $1
104         pop $0
105 !macroend
106 !define RemoveFileAssociation "!insertmacro RemoveFileAssociation"
107
108
109 !endif ; _ABI_UTIL_FILEASSOC_NSH_