summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-05-25 20:37:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-05-25 20:37:07 -0700
commit1112870551a886769e2e4571b0a4145958157972 (patch)
tree7feaddf502c10c7dd50e7028fb33a3f2b69e97b0
parent782e015d0f235f7e5f66d8becfb7e8361b91825d (diff)
downloadtxr-1112870551a886769e2e4571b0a4145958157972.tar.gz
txr-1112870551a886769e2e4571b0a4145958157972.tar.bz2
txr-1112870551a886769e2e4571b0a4145958157972.zip
windows: register file associations.
Add registration of .txr, .tl and .tlo suffixe. * inst.nsi: Include fassoc.nsh file. Associate .txr, .tl and .tlo with txr-win.exe * win/fassoc.nsh: New file.
-rw-r--r--inst.nsi7
-rw-r--r--win/fassoc.nsh139
2 files changed, 146 insertions, 0 deletions
diff --git a/inst.nsi b/inst.nsi
index 8ed9b8ba..7bc2e7d3 100644
--- a/inst.nsi
+++ b/inst.nsi
@@ -1,4 +1,5 @@
!include win\env.nsh
+!include win\fassoc.nsh
# name the installer
outFile "txr-installer.exe"
@@ -70,6 +71,9 @@ section "TXR"
CreateShortCut "$SMPROGRAMS\txr\install-root.lnk" "$INSTDIR\txr"
CreateShortCut "$STARTMENU\txr.lnk" "$INSTDIR\txr\bin\txr.exe"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\txr\bin"
+ ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".txr" "TXR Pattern Language"
+ ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".tl" "TXR Lisp"
+ ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".tlo" "Compiled TXR Lisp"
sectionEnd
section "Uninstall"
@@ -78,6 +82,9 @@ section "Uninstall"
# not the $INSTDIR that was used during installation!
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin"
+ ${UnregisterExtension} ".txr" "TXR Pattern Language"
+ ${UnregisterExtension} ".tl" "TXR Lisp"
+ ${UnregisterExtension} ".tlo" "Compiled TXR Lisp"
RMDir /r "$INSTDIR"
Delete "$SMPROGRAMS\txr\txr.lnk"
Delete "$STARTMENU\txr.lnk"
diff --git a/win/fassoc.nsh b/win/fassoc.nsh
new file mode 100644
index 00000000..36cdf913
--- /dev/null
+++ b/win/fassoc.nsh
@@ -0,0 +1,139 @@
+!ifndef FileAssociation_INCLUDED
+!define FileAssociation_INCLUDED
+
+!include Util.nsh
+
+!verbose push
+!verbose 3
+!ifndef _FileAssociation_VERBOSE
+ !define _FileAssociation_VERBOSE 3
+!endif
+!verbose ${_FileAssociation_VERBOSE}
+!define FileAssociation_VERBOSE `!insertmacro FileAssociation_VERBOSE`
+!verbose pop
+
+!macro FileAssociation_VERBOSE _VERBOSE
+ !verbose push
+ !verbose 3
+ !undef _FileAssociation_VERBOSE
+ !define _FileAssociation_VERBOSE ${_VERBOSE}
+ !verbose pop
+!macroend
+
+
+
+!macro RegisterExtensionCall _EXECUTABLE _EXTENSION _DESCRIPTION
+ !verbose push
+ !verbose ${_FileAssociation_VERBOSE}
+ Push `${_DESCRIPTION}`
+ Push `${_EXTENSION}`
+ Push `${_EXECUTABLE}`
+ ${CallArtificialFunction} RegisterExtension_
+ !verbose pop
+!macroend
+
+!macro UnRegisterExtensionCall _EXTENSION _DESCRIPTION
+ !verbose push
+ !verbose ${_FileAssociation_VERBOSE}
+ Push `${_EXTENSION}`
+ Push `${_DESCRIPTION}`
+ ${CallArtificialFunction} UnRegisterExtension_
+ !verbose pop
+!macroend
+
+
+
+!define RegisterExtension `!insertmacro RegisterExtensionCall`
+!define un.RegisterExtension `!insertmacro RegisterExtensionCall`
+
+!macro RegisterExtension
+!macroend
+
+!macro un.RegisterExtension
+!macroend
+
+!macro RegisterExtension_
+ !verbose push
+ !verbose ${_FileAssociation_VERBOSE}
+
+ Exch $R2 ;exe
+ Exch
+ Exch $R1 ;ext
+ Exch
+ Exch 2
+ Exch $R0 ;desc
+ Exch 2
+ Push $0
+ Push $1
+
+ ReadRegStr $1 HKCR $R1 "" ; read current file association
+ StrCmp "$1" "" NoBackup ; is it empty
+ StrCmp "$1" "$R0" NoBackup ; is it our own
+ WriteRegStr HKCR $R1 "backup_val" "$1" ; backup current value
+NoBackup:
+ WriteRegStr HKCR $R1 "" "$R0" ; set our file association
+
+ ReadRegStr $0 HKCR $R0 ""
+ StrCmp $0 "" 0 Skip
+ WriteRegStr HKCR "$R0" "" "$R0"
+ WriteRegStr HKCR "$R0\shell" "" "open"
+ WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,0"
+Skip:
+ WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1"'
+ WriteRegStr HKCR "$R0\shell\edit" "" "Edit $R0"
+ WriteRegStr HKCR "$R0\shell\edit\command" "" '"$R2" "%1"'
+
+ Pop $1
+ Pop $0
+ Pop $R2
+ Pop $R1
+ Pop $R0
+
+ !verbose pop
+!macroend
+
+
+
+!define UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
+!define un.UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
+
+!macro UnRegisterExtension
+!macroend
+
+!macro un.UnRegisterExtension
+!macroend
+
+!macro UnRegisterExtension_
+ !verbose push
+ !verbose ${_FileAssociation_VERBOSE}
+
+ Exch $R1 ;desc
+ Exch
+ Exch $R0 ;ext
+ Exch
+ Push $0
+ Push $1
+
+ ReadRegStr $1 HKCR $R0 ""
+ StrCmp $1 $R1 0 NoOwn ; only do this if we own it
+ ReadRegStr $1 HKCR $R0 "backup_val"
+ StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key
+ DeleteRegKey HKCR $R0
+ Goto NoOwn
+
+Restore:
+ WriteRegStr HKCR $R0 "" $1
+ DeleteRegValue HKCR $R0 "backup_val"
+ DeleteRegKey HKCR $R1 ;Delete key with association name settings
+
+NoOwn:
+
+ Pop $1
+ Pop $0
+ Pop $R1
+ Pop $R0
+
+ !verbose pop
+!macroend
+
+!endif # !FileAssociation_INCLUDED