mirror of https://github.com/keeweb/keeweb.git
check if the app is running
This commit is contained in:
parent
a03f6a4459
commit
8049b888d6
|
@ -24,3 +24,6 @@ indent_size = 4
|
||||||
|
|
||||||
[*.scss]
|
[*.scss]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.nsh]
|
||||||
|
indent_size = 2
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
!macro EnsureAppIsNotRunning
|
||||||
|
${Do}
|
||||||
|
nsExec::ExecToStack /OEM 'tasklist /NH /FI "IMAGENAME eq ${PRODUCT_EXE}"'
|
||||||
|
Pop $0
|
||||||
|
${If} $0 != 0
|
||||||
|
DetailPrint "Error checking ${PRODUCT_EXE}: $0"
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "Failed to check whether process is running"
|
||||||
|
Quit
|
||||||
|
${EndIf}
|
||||||
|
Pop $1
|
||||||
|
${StrContains} $0 "${PRODUCT_EXE}" $1
|
||||||
|
${If} $0 == ""
|
||||||
|
DetailPrint "${PRODUCT_EXE} is not running"
|
||||||
|
${ExitDo}
|
||||||
|
${Else}
|
||||||
|
MessageBox MB_ICONQUESTION|MB_OKCANCEL|MB_DEFBUTTON1 "To proceed, please close ${PRODUCT_NAME} and click OK" /SD IDCANCEL IDOK ok
|
||||||
|
Quit
|
||||||
|
ok:
|
||||||
|
${EndIf}
|
||||||
|
${Loop}
|
||||||
|
!macroend
|
|
@ -1,8 +1,10 @@
|
||||||
!include MultiUser.nsh
|
!include MultiUser.nsh
|
||||||
!include MUI2.nsh
|
!include MUI2.nsh
|
||||||
|
!include Util.nsh
|
||||||
!include x64.nsh
|
!include x64.nsh
|
||||||
!include nsDialogs.nsh
|
!include nsDialogs.nsh
|
||||||
!include LogicLib.nsh
|
!include LogicLib.nsh
|
||||||
!include WinVer.nsh
|
!include WinVer.nsh
|
||||||
|
|
||||||
!include package\nsis\lib\FileAssoc.nsh
|
!include package\nsis\lib\FileAssoc.nsh
|
||||||
|
!include package\nsis\lib\StrContains.nsh
|
||||||
|
|
|
@ -15,7 +15,7 @@ Function .onInit
|
||||||
${EndIf}
|
${EndIf}
|
||||||
|
|
||||||
${IfNot} ${AtLeastWin7}
|
${IfNot} ${AtLeastWin7}
|
||||||
MessageBox MB_OK "Windows 7 and above required"
|
MessageBox MB_ICONSTOP|MB_OK "Windows 7 and above required"
|
||||||
Quit
|
Quit
|
||||||
${EndIf}
|
${EndIf}
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ Function .onInit
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
|
||||||
Section "MainSection" SEC01
|
Section "MainSection" SEC01
|
||||||
|
!insertmacro EnsureAppIsNotRunning
|
||||||
|
|
||||||
ReadRegStr $R0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
|
ReadRegStr $R0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
|
||||||
${If} $R0 != ""
|
${If} $R0 != ""
|
||||||
ExecWait '$R0 /S _?=$INSTDIR'
|
ExecWait '$R0 /S _?=$INSTDIR'
|
||||||
|
|
|
@ -118,4 +118,4 @@
|
||||||
System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"
|
System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"
|
||||||
!macroend
|
!macroend
|
||||||
|
|
||||||
;EOF
|
;EOF
|
||||||
|
|
|
@ -1,190 +0,0 @@
|
||||||
/*
|
|
||||||
_____________________________________________________________________________
|
|
||||||
|
|
||||||
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
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
# http://nsis.sourceforge.net/StrContains
|
||||||
|
|
||||||
|
; StrContains
|
||||||
|
; This function does a case sensitive searches for an occurrence of a substring in a string.
|
||||||
|
; It returns the substring if it is found.
|
||||||
|
; Otherwise it returns null("").
|
||||||
|
; Written by kenglish_hi
|
||||||
|
; Adapted from StrReplace written by dandaman32
|
||||||
|
|
||||||
|
|
||||||
|
Var STR_HAYSTACK
|
||||||
|
Var STR_NEEDLE
|
||||||
|
Var STR_CONTAINS_VAR_1
|
||||||
|
Var STR_CONTAINS_VAR_2
|
||||||
|
Var STR_CONTAINS_VAR_3
|
||||||
|
Var STR_CONTAINS_VAR_4
|
||||||
|
Var STR_RETURN_VAR
|
||||||
|
|
||||||
|
Function StrContains
|
||||||
|
Exch $STR_NEEDLE
|
||||||
|
Exch 1
|
||||||
|
Exch $STR_HAYSTACK
|
||||||
|
; Uncomment to debug
|
||||||
|
;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
|
||||||
|
StrCpy $STR_RETURN_VAR ""
|
||||||
|
StrCpy $STR_CONTAINS_VAR_1 -1
|
||||||
|
StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
|
||||||
|
StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
|
||||||
|
loop:
|
||||||
|
IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
|
||||||
|
StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
|
||||||
|
StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
|
||||||
|
StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
|
||||||
|
Goto loop
|
||||||
|
found:
|
||||||
|
StrCpy $STR_RETURN_VAR $STR_NEEDLE
|
||||||
|
Goto done
|
||||||
|
done:
|
||||||
|
Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
|
||||||
|
Exch $STR_RETURN_VAR
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
|
||||||
|
Push `${HAYSTACK}`
|
||||||
|
Push `${NEEDLE}`
|
||||||
|
Call StrContains
|
||||||
|
Pop `${OUT}`
|
||||||
|
!macroend
|
||||||
|
|
||||||
|
!define StrContains '!insertmacro "_StrContainsConstructor"'
|
|
@ -2,5 +2,6 @@
|
||||||
!include package\nsis\includes.nsh
|
!include package\nsis\includes.nsh
|
||||||
!include package\nsis\mui.nsh
|
!include package\nsis\mui.nsh
|
||||||
!include package\nsis\config.nsh
|
!include package\nsis\config.nsh
|
||||||
|
!include package\nsis\check-running.nsh
|
||||||
!include package\nsis\install.nsh
|
!include package\nsis\install.nsh
|
||||||
!include package\nsis\uninstall.nsh
|
!include package\nsis\uninstall.nsh
|
||||||
|
|
Loading…
Reference in New Issue