Issue #117. Finished file association for NSIS script.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-24 14:11:41 +03:00
parent 8d665417b5
commit d3626a5b61
2 changed files with 247 additions and 1 deletions

190
dist/FileAssociation.nsh vendored Normal file
View File

@ -0,0 +1,190 @@
/*
_____________________________________________________________________________
File Association
_____________________________________________________________________________
Based on code taken from http://nsis.sourceforge.net/File_Association
Usage in script:
1. !include "FileAssociation.nsh"
2. [Section|Function]
${FileAssociationFunction} "Param1" "Param2" "..." $var
[SectionEnd|FunctionEnd]
FileAssociationFunction=[RegisterExtension|UnRegisterExtension]
_____________________________________________________________________________
${RegisterExtension} "[executable]" "[extension]" "[description]"
"[executable]" ; executable which opens the file format
;
"[extension]" ; extension, which represents the file format to open
;
"[description]" ; description for the extension. This will be display in Windows Explorer.
;
${UnRegisterExtension} "[extension]" "[description]"
"[extension]" ; extension, which represents the file format to open
;
"[description]" ; description for the extension. This will be display in Windows Explorer.
;
_____________________________________________________________________________
Macros
_____________________________________________________________________________
Change log window verbosity (default: 3=no script)
Example:
!include "FileAssociation.nsh"
!insertmacro RegisterExtension
${FileAssociation_VERBOSE} 4 # all verbosity
!insertmacro UnRegisterExtension
${FileAssociation_VERBOSE} 3 # no script
*/
!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

58
dist/valentina.nsi vendored
View File

@ -6,12 +6,13 @@
!define MUI_VERSION "0.2.2" !define MUI_VERSION "0.2.2"
!define MUI_BRANDINGTEXT "Valentina ${MUI_VERSION}" !define MUI_BRANDINGTEXT "Valentina ${MUI_VERSION}"
!define WEBSITE_LINK "https://bitbucket.org/dismine/valentina" !define WEBSITE_LINK "https://bitbucket.org/dismine/valentina"
!define PUBLISHER "Roman Telezhinsky" !define PUBLISHER "Roman Telezhynskyi"
CRCCheck On CRCCheck On
; Bij deze moeten we waarschijnlijk een absoluut pad gaan gebruiken ; Bij deze moeten we waarschijnlijk een absoluut pad gaan gebruiken
; dit moet effe uitgetest worden. ; dit moet effe uitgetest worden.
!include "${NSISDIR}\Contrib\Modern UI\System.nsh" !include "${NSISDIR}\Contrib\Modern UI\System.nsh"
!include "FileAssociation.nsh"
;-------------------------------- ;--------------------------------
;General ;General
@ -89,6 +90,57 @@
!insertmacro MUI_LANGUAGE "Ukrainian" !insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Czech" !insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Hebrew" !insertmacro MUI_LANGUAGE "Hebrew"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
; !insertmacro MUI_LANGUAGE "Spanish"
; !insertmacro MUI_LANGUAGE "SpanishInternational"
; !insertmacro MUI_LANGUAGE "SimpChinese"
; !insertmacro MUI_LANGUAGE "TradChinese"
; !insertmacro MUI_LANGUAGE "Japanese"
; !insertmacro MUI_LANGUAGE "Korean"
; !insertmacro MUI_LANGUAGE "Danish"
; !insertmacro MUI_LANGUAGE "Swedish"
; !insertmacro MUI_LANGUAGE "Norwegian"
; !insertmacro MUI_LANGUAGE "NorwegianNynorsk"
; !insertmacro MUI_LANGUAGE "Finnish"
; !insertmacro MUI_LANGUAGE "Greek"
; !insertmacro MUI_LANGUAGE "Portuguese"
; !insertmacro MUI_LANGUAGE "PortugueseBR"
; !insertmacro MUI_LANGUAGE "Polish"
; !insertmacro MUI_LANGUAGE "Slovak"
; !insertmacro MUI_LANGUAGE "Croatian"
; !insertmacro MUI_LANGUAGE "Bulgarian"
; !insertmacro MUI_LANGUAGE "Hungarian"
; !insertmacro MUI_LANGUAGE "Thai"
; !insertmacro MUI_LANGUAGE "Romanian"
; !insertmacro MUI_LANGUAGE "Latvian"
; !insertmacro MUI_LANGUAGE "Macedonian"
; !insertmacro MUI_LANGUAGE "Estonian"
; !insertmacro MUI_LANGUAGE "Turkish"
; !insertmacro MUI_LANGUAGE "Lithuanian"
; !insertmacro MUI_LANGUAGE "Slovenian"
; !insertmacro MUI_LANGUAGE "Serbian"
; !insertmacro MUI_LANGUAGE "SerbianLatin"
; !insertmacro MUI_LANGUAGE "Arabic"
; !insertmacro MUI_LANGUAGE "Farsi"
; !insertmacro MUI_LANGUAGE "Indonesian"
; !insertmacro MUI_LANGUAGE "Mongolian"
; !insertmacro MUI_LANGUAGE "Luxembourgish"
; !insertmacro MUI_LANGUAGE "Albanian"
; !insertmacro MUI_LANGUAGE "Breton"
; !insertmacro MUI_LANGUAGE "Belarusian"
; !insertmacro MUI_LANGUAGE "Icelandic"
; !insertmacro MUI_LANGUAGE "Malay"
; !insertmacro MUI_LANGUAGE "Bosnian"
; !insertmacro MUI_LANGUAGE "Kurdish"
; !insertmacro MUI_LANGUAGE "Irish"
; !insertmacro MUI_LANGUAGE "Uzbek"
; !insertmacro MUI_LANGUAGE "Galician"
; !insertmacro MUI_LANGUAGE "Afrikaans"
; !insertmacro MUI_LANGUAGE "Catalan"
; !insertmacro MUI_LANGUAGE "Esperanto"
; !insertmacro MUI_LANGUAGE "Asturian"
!insertmacro MUI_RESERVEFILE_LANGDLL !insertmacro MUI_RESERVEFILE_LANGDLL
Function .onInit Function .onInit
@ -156,6 +208,8 @@ Section "Valentina (required)"
WriteRegStr HKCU "${REG_UNINSTALL}" "Comments" "Uninstalls ${MUI_PRODUCT}." WriteRegStr HKCU "${REG_UNINSTALL}" "Comments" "Uninstalls ${MUI_PRODUCT}."
WriteUninstaller "$INSTDIR\${UNINSTALLER_NAME}" WriteUninstaller "$INSTDIR\${UNINSTALLER_NAME}"
${registerExtension} "$INSTDIR\${MUI_FILE}.exe" ".val" "Valentina_File"
SectionEnd SectionEnd
@ -179,6 +233,8 @@ Section "Uninstall"
;Delete Uninstaller And Unistall Registry Entries ;Delete Uninstaller And Unistall Registry Entries
DeleteRegKey HKCU "SOFTWARE\${MUI_PRODUCT}" DeleteRegKey HKCU "SOFTWARE\${MUI_PRODUCT}"
DeleteRegKey HKCU "${REG_UNINSTALL}" DeleteRegKey HKCU "${REG_UNINSTALL}"
${unregisterExtension} ".val" "Valentina_File"
SectionEnd SectionEnd