Merge branch 'master' of git://git.gpleda.org/pcb
[geda-pcb/see.git] / win32 / registerExtension.nsh
blob46e8779276f8fa5fcbc5547cf4fe53f16b371cf3
1 ;; From http://nsis.sourceforge.net/How_can_I_associate_a_file_extension_with_my_application
4 !define registerExtension "!insertmacro registerExtension"
5 !define unregisterExtension "!insertmacro unregisterExtension"
6  
7 !macro registerExtension executable flags extension description
8        Push "${executable}"  ; "full path to my.exe"
9        Push "${flags}"  ; "options to pass to my.exe"
10        Push "${extension}"   ;  ".mkv"
11        Push "${description}" ;  "MKV File"
12        Call registerExtension
13 !macroend
15 ; back up old value of .opt
16 Function registerExtension
17 !define Index "Line${__LINE__}"
18   pop $R0 ; description
19   pop $R1 ; extension
20   pop $R3 ; flags
21   pop $R2 ; binary
22   push $1
23   push $0
24   ReadRegStr $1 HKCR $R1 ""
25   StrCmp $1 "" "${Index}-NoBackup"
26     StrCmp $1 "OptionsFile" "${Index}-NoBackup"
27     WriteRegStr HKCR $R1 "backup_val" $1
28 "${Index}-NoBackup:"
29   WriteRegStr HKCR $R1 "" $R0
30   ReadRegStr $0 HKCR $R0 ""
31   StrCmp $0 "" 0 "${Index}-Skip"
32         WriteRegStr HKCR $R0 "" $R0
33         WriteRegStr HKCR "$R0\shell" "" "open"
34         WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,0"
35 "${Index}-Skip:"
36   WriteRegStr HKCR "$R0\shell\open\command" "" '$R2 $R3 "%1"'
37   WriteRegStr HKCR "$R0\shell\edit" "" "Edit $R0"
38   WriteRegStr HKCR "$R0\shell\edit\command" "" '$R2 $R3 "%1"'
39   pop $0
40   pop $1
41 !undef Index
42 FunctionEnd
44 !macro unregisterExtension extension description
45        Push "${extension}"   ;  ".mkv"
46        Push "${description}"   ;  "MKV File"
47        Call un.unregisterExtension
48 !macroend
50 Function un.unregisterExtension
51   pop $R1 ; description
52   pop $R0 ; extension
53 !define Index "Line${__LINE__}"
54   push $1
55   ReadRegStr $1 HKCR $R0 ""
56   StrCmp $1 $R1 0 "${Index}-NoOwn" ; only do this if we own it
57   ReadRegStr $1 HKCR $R0 "backup_val"
58   StrCmp $1 "" 0 "${Index}-Restore" ; if backup="" then delete the whole key
59   DeleteRegKey HKCR $R0
60   Goto "${Index}-NoOwn"
61 "${Index}-Restore:"
62   WriteRegStr HKCR $R0 "" $1
63   DeleteRegValue HKCR $R0 "backup_val"
64   DeleteRegKey HKCR $R1 ;Delete key with association name settings
65 "${Index}-NoOwn:"
66   pop $1
67 !undef Index
68 FunctionEnd