Commit 4518a985 authored by Juergen Weigert's avatar Juergen Weigert

make distribute

parent 840b30c5
# a simple makefile to release packages
DEST=/usr/share/inkscape/extensions
dist:
cd distribute; sh ./distribute.sh
#install is used by dist.
install:
mkdir -p $(DEST)
install -m 755 -t $(DEST) *.py
install -m 644 -t $(DEST) *.inx
clean:
rm -f *.orig */*.orig
Package created with checkinstall 1.6.2
#! /bin/bash
# Make a debian/ubuntu distribution
name=$1
vers=$2
out=$3
test -z "$out" && out=.
[ -d tmp ] && rm -rf tmp
mkdir tmp
cd files
fakeroot checkinstall --fstrans --reset-uid --type debian --install=no -y --pkgname $name --pkgversion $vers --arch all --pkglicense LGPL --pkggroup other --pkgsource "http://github.com/fablabnbg/inkscape-chain-paths" --pkgaltsource "http://fablab-nuernberg.de" --pakdir tmp/ --maintainer "'Juergen Weigert (juewei@fabmail.org)'" --requires "bash" make install -e PREFIX=/usr > /dev/null || { echo "error"; exit 1; }
mkdir -p $out
mv tmp/*.deb $out
rm -rf tmp
#!/bin/bash
echo "Determining Version:"
VERSION=$(sed -ne 's@.*version\s\([a-z0-9\.]*\).*@\1@pi' ../centerline-trace.inx)
echo "Version is: \"$VERSION\""
name=centerline-trace
if [ -d $name ]
then
echo "Removing leftover files"
rm -rf $name
fi
echo "Copying content..."
mkdir $name
cp ../README.md $name/README
cp ../LICENSE* $name/
cp ../*.py ../*.inx ../Makefile $name/
echo "****************************************************************"
echo "Ubuntu Version: For Building you must have checkinstall and dpkg"
echo "Build Ubuntu Version (Y/n)?"
read answer
if [ "$answer" != "n" ]
then
cp -a $name/* deb/files
(cd deb && sh ./dist.sh $name $VERSION ..)
fi
/**
* EnvVarUpdate.nsh
* : Environmental Variables: append, prepend, and remove entries
*
* WARNING: If you use StrFunc.nsh header then include it before this file
* with all required definitions. This is to avoid conflicts
*
* Usage:
* ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString"
*
* Credits:
* Version 1.0
* * Cal Turney (turnec2)
* * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this
* function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar,
* WriteEnvStr, and un.DeleteEnvStr
* * Diego Pedroso (deguix) for StrTok
* * Kevin English (kenglish_hi) for StrContains
* * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry
* (dandaman32) for StrReplace
*
* Version 1.1 (compatibility with StrFunc.nsh)
* * techtonik
*
* http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries
*
*/
!ifndef ENVVARUPDATE_FUNCTION
!define ENVVARUPDATE_FUNCTION
!verbose push
!verbose 3
!include "LogicLib.nsh"
!include "WinMessages.NSH"
!include "StrFunc.nsh"
; ---- Fix for conflict if StrFunc.nsh is already includes in main file -----------------------
!macro _IncludeStrFunction StrFuncName
!ifndef ${StrFuncName}_INCLUDED
${${StrFuncName}}
!endif
!ifndef Un${StrFuncName}_INCLUDED
${Un${StrFuncName}}
!endif
!define un.${StrFuncName} "${Un${StrFuncName}}"
!macroend
!insertmacro _IncludeStrFunction StrTok
!insertmacro _IncludeStrFunction StrStr
!insertmacro _IncludeStrFunction StrRep
; ---------------------------------- Macro Definitions ----------------------------------------
!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
Push "${EnvVarName}"
Push "${Action}"
Push "${RegLoc}"
Push "${PathString}"
Call EnvVarUpdate
Pop "${ResultVar}"
!macroend
!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"'
!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
Push "${EnvVarName}"
Push "${Action}"
Push "${RegLoc}"
Push "${PathString}"
Call un.EnvVarUpdate
Pop "${ResultVar}"
!macroend
!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"'
; ---------------------------------- Macro Definitions end-------------------------------------
;----------------------------------- EnvVarUpdate start----------------------------------------
!define hklm_all_users 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define hkcu_current_user 'HKCU "Environment"'
!macro EnvVarUpdate UN
Function ${UN}EnvVarUpdate
Push $0
Exch 4
Exch $1
Exch 3
Exch $2
Exch 2
Exch $3
Exch
Exch $4
Push $5
Push $6
Push $7
Push $8
Push $9
Push $R0
/* After this point:
-------------------------
$0 = ResultVar (returned)
$1 = EnvVarName (input)
$2 = Action (input)
$3 = RegLoc (input)
$4 = PathString (input)
$5 = Orig EnvVar (read from registry)
$6 = Len of $0 (temp)
$7 = tempstr1 (temp)
$8 = Entry counter (temp)
$9 = tempstr2 (temp)
$R0 = tempChar (temp) */
; Step 1: Read contents of EnvVarName from RegLoc
;
; Check for empty EnvVarName
${If} $1 == ""
SetErrors
DetailPrint "ERROR: EnvVarName is blank"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Check for valid Action
${If} $2 != "A"
${AndIf} $2 != "P"
${AndIf} $2 != "R"
SetErrors
DetailPrint "ERROR: Invalid Action - must be A, P, or R"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
${If} $3 == HKLM
ReadRegStr $5 ${hklm_all_users} $1 ; Get EnvVarName from all users into $5
${ElseIf} $3 == HKCU
ReadRegStr $5 ${hkcu_current_user} $1 ; Read EnvVarName from current user into $5
${Else}
SetErrors
DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"'
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Check for empty PathString
${If} $4 == ""
SetErrors
DetailPrint "ERROR: PathString is blank"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Make sure we've got some work to do
${If} $5 == ""
${AndIf} $2 == "R"
SetErrors
DetailPrint "$1 is empty - Nothing to remove"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Step 2: Scrub EnvVar
;
StrCpy $0 $5 ; Copy the contents to $0
; Remove spaces around semicolons (NOTE: spaces before the 1st entry or
; after the last one are not removed here but instead in Step 3)
${If} $0 != "" ; If EnvVar is not empty ...
${Do}
${${UN}StrStr} $7 $0 " ;"
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 " ;" ";" ; Remove '<space>;'
${Loop}
${Do}
${${UN}StrStr} $7 $0 "; "
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 "; " ";" ; Remove ';<space>'
${Loop}
${Do}
${${UN}StrStr} $7 $0 ";;"
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 ";;" ";"
${Loop}
; Remove a leading or trailing semicolon from EnvVar
StrCpy $7 $0 1 0
${If} $7 == ";"
StrCpy $0 $0 "" 1 ; Change ';<EnvVar>' to '<EnvVar>'
${EndIf}
StrLen $6 $0
IntOp $6 $6 - 1
StrCpy $7 $0 1 $6
${If} $7 == ";"
StrCpy $0 $0 $6 ; Change ';<EnvVar>' to '<EnvVar>'
${EndIf}
; DetailPrint "Scrubbed $1: [$0]" ; Uncomment to debug
${EndIf}
/* Step 3. Remove all instances of the target path/string (even if "A" or "P")
$6 = bool flag (1 = found and removed PathString)
$7 = a string (e.g. path) delimited by semicolon(s)
$8 = entry counter starting at 0
$9 = copy of $0
$R0 = tempChar */
${If} $5 != "" ; If EnvVar is not empty ...
StrCpy $9 $0
StrCpy $0 ""
StrCpy $8 0
StrCpy $6 0
${Do}
${${UN}StrTok} $7 $9 ";" $8 "0" ; $7 = next entry, $8 = entry counter
${If} $7 == "" ; If we've run out of entries,
${ExitDo} ; were done
${EndIf} ;
; Remove leading and trailing spaces from this entry (critical step for Action=Remove)
${Do}
StrCpy $R0 $7 1
${If} $R0 != " "
${ExitDo}
${EndIf}
StrCpy $7 $7 "" 1 ; Remove leading space
${Loop}
${Do}
StrCpy $R0 $7 1 -1
${If} $R0 != " "
${ExitDo}
${EndIf}
StrCpy $7 $7 -1 ; Remove trailing space
${Loop}
${If} $7 == $4 ; If string matches, remove it by not appending it
StrCpy $6 1 ; Set 'found' flag
${ElseIf} $7 != $4 ; If string does NOT match
${AndIf} $0 == "" ; and the 1st string being added to $0,
StrCpy $0 $7 ; copy it to $0 without a prepended semicolon
${ElseIf} $7 != $4 ; If string does NOT match
${AndIf} $0 != "" ; and this is NOT the 1st string to be added to $0,
StrCpy $0 $0;$7 ; append path to $0 with a prepended semicolon
${EndIf} ;
IntOp $8 $8 + 1 ; Bump counter
${Loop} ; Check for duplicates until we run out of paths
${EndIf}
; Step 4: Perform the requested Action
;
${If} $2 != "R" ; If Append or Prepend
${If} $6 == 1 ; And if we found the target
DetailPrint "Target is already present in $1. It will be removed and"
${EndIf}
${If} $0 == "" ; If EnvVar is (now) empty
StrCpy $0 $4 ; just copy PathString to EnvVar
${If} $6 == 0 ; If found flag is either 0
${OrIf} $6 == "" ; or blank (if EnvVarName is empty)
DetailPrint "$1 was empty and has been updated with the target"
${EndIf}
${ElseIf} $2 == "A" ; If Append (and EnvVar is not empty),
StrCpy $0 $0;$4 ; append PathString
${If} $6 == 1
DetailPrint "appended to $1"
${Else}
DetailPrint "Target was appended to $1"
${EndIf}
${Else} ; If Prepend (and EnvVar is not empty),
StrCpy $0 $4;$0 ; prepend PathString
${If} $6 == 1
DetailPrint "prepended to $1"
${Else}
DetailPrint "Target was prepended to $1"
${EndIf}
${EndIf}
${Else} ; If Action = Remove
${If} $6 == 1 ; and we found the target
DetailPrint "Target was found and removed from $1"
${Else}
DetailPrint "Target was NOT found in $1 (nothing to remove)"
${EndIf}
${If} $0 == ""
DetailPrint "$1 is now empty"
${EndIf}
${EndIf}
; Step 5: Update the registry at RegLoc with the updated EnvVar and announce the change
;
ClearErrors
${If} $3 == HKLM
WriteRegExpandStr ${hklm_all_users} $1 $0 ; Write it in all users section
${ElseIf} $3 == HKCU
WriteRegExpandStr ${hkcu_current_user} $1 $0 ; Write it to current user section
${EndIf}
IfErrors 0 +4
MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3"
DetailPrint "Could not write updated $1 to $3"
Goto EnvVarUpdate_Restore_Vars
; "Export" our change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
EnvVarUpdate_Restore_Vars:
;
; Restore the user's variables and return ResultVar
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Push $0 ; Push my $0 (ResultVar)
Exch
Pop $0 ; Restore his $0
FunctionEnd
!macroend ; EnvVarUpdate UN
!insertmacro EnvVarUpdate ""
!insertmacro EnvVarUpdate "un."
;----------------------------------- EnvVarUpdate end----------------------------------------
!verbose pop
!endif
/*
_____________________________________________________________________________
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
#! /bin/bash
# Make a windows distribution
name=$1
vers=$2
out=$3
test -z "$out" && out=.
echo "Creating Windows installer"
[ -d tmp ] && rm -rf tmp
mkdir -p tmp/stream
cp -r files/* tmp/
sed -i -e s@VERSION@"$vers"@g tmp/installer.nsi
pushd tmp
makensis installer.nsi > /dev/null || exit 1
popd
mv tmp/setup.exe $name-$vers-Windows-Installer.exe || exit 1
zip $name-$vers-Windows-Installer.zip $name-$vers-Windows-Installer.exe # for github upload
rm -rf tmp
mkdir -p $out
mv $name-$vers-Windows-Installer.* $out
/**
* EnvVarUpdate.nsh
* : Environmental Variables: append, prepend, and remove entries
*
* WARNING: If you use StrFunc.nsh header then include it before this file
* with all required definitions. This is to avoid conflicts
*
* Usage:
* ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString"
*
* Credits:
* Version 1.0
* * Cal Turney (turnec2)
* * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this
* function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar,
* WriteEnvStr, and un.DeleteEnvStr
* * Diego Pedroso (deguix) for StrTok
* * Kevin English (kenglish_hi) for StrContains
* * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry
* (dandaman32) for StrReplace
*
* Version 1.1 (compatibility with StrFunc.nsh)
* * techtonik
*
* http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries
*
*/
!ifndef ENVVARUPDATE_FUNCTION
!define ENVVARUPDATE_FUNCTION
!verbose push
!verbose 3
!include "LogicLib.nsh"
!include "WinMessages.NSH"
!include "StrFunc.nsh"
; ---- Fix for conflict if StrFunc.nsh is already includes in main file -----------------------
!macro _IncludeStrFunction StrFuncName
!ifndef ${StrFuncName}_INCLUDED
${${StrFuncName}}
!endif
!ifndef Un${StrFuncName}_INCLUDED
${Un${StrFuncName}}
!endif
!define un.${StrFuncName} "${Un${StrFuncName}}"
!macroend
!insertmacro _IncludeStrFunction StrTok
!insertmacro _IncludeStrFunction StrStr
!insertmacro _IncludeStrFunction StrRep
; ---------------------------------- Macro Definitions ----------------------------------------
!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
Push "${EnvVarName}"
Push "${Action}"
Push "${RegLoc}"
Push "${PathString}"
Call EnvVarUpdate
Pop "${ResultVar}"
!macroend
!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"'
!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
Push "${EnvVarName}"
Push "${Action}"
Push "${RegLoc}"
Push "${PathString}"
Call un.EnvVarUpdate
Pop "${ResultVar}"
!macroend
!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"'
; ---------------------------------- Macro Definitions end-------------------------------------
;----------------------------------- EnvVarUpdate start----------------------------------------
!define hklm_all_users 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define hkcu_current_user 'HKCU "Environment"'
!macro EnvVarUpdate UN
Function ${UN}EnvVarUpdate
Push $0
Exch 4
Exch $1
Exch 3
Exch $2
Exch 2
Exch $3
Exch
Exch $4
Push $5
Push $6
Push $7
Push $8
Push $9
Push $R0
/* After this point:
-------------------------
$0 = ResultVar (returned)
$1 = EnvVarName (input)
$2 = Action (input)
$3 = RegLoc (input)
$4 = PathString (input)
$5 = Orig EnvVar (read from registry)
$6 = Len of $0 (temp)
$7 = tempstr1 (temp)
$8 = Entry counter (temp)
$9 = tempstr2 (temp)
$R0 = tempChar (temp) */
; Step 1: Read contents of EnvVarName from RegLoc
;
; Check for empty EnvVarName
${If} $1 == ""
SetErrors
DetailPrint "ERROR: EnvVarName is blank"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Check for valid Action
${If} $2 != "A"
${AndIf} $2 != "P"
${AndIf} $2 != "R"
SetErrors
DetailPrint "ERROR: Invalid Action - must be A, P, or R"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
${If} $3 == HKLM
ReadRegStr $5 ${hklm_all_users} $1 ; Get EnvVarName from all users into $5
${ElseIf} $3 == HKCU
ReadRegStr $5 ${hkcu_current_user} $1 ; Read EnvVarName from current user into $5
${Else}
SetErrors
DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"'
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Check for empty PathString
${If} $4 == ""
SetErrors
DetailPrint "ERROR: PathString is blank"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Make sure we've got some work to do
${If} $5 == ""
${AndIf} $2 == "R"
SetErrors
DetailPrint "$1 is empty - Nothing to remove"
Goto EnvVarUpdate_Restore_Vars
${EndIf}
; Step 2: Scrub EnvVar
;
StrCpy $0 $5 ; Copy the contents to $0
; Remove spaces around semicolons (NOTE: spaces before the 1st entry or
; after the last one are not removed here but instead in Step 3)
${If} $0 != "" ; If EnvVar is not empty ...
${Do}
${${UN}StrStr} $7 $0 " ;"
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 " ;" ";" ; Remove '<space>;'
${Loop}
${Do}
${${UN}StrStr} $7 $0 "; "
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 "; " ";" ; Remove ';<space>'
${Loop}
${Do}
${${UN}StrStr} $7 $0 ";;"
${If} $7 == ""
${ExitDo}
${EndIf}
${${UN}StrRep} $0 $0 ";;" ";"
${Loop}
; Remove a leading or trailing semicolon from EnvVar
StrCpy $7 $0 1 0
${If} $7 == ";"
StrCpy $0 $0 "" 1 ; Change ';<EnvVar>' to '<EnvVar>'
${EndIf}
StrLen $6 $0
IntOp $6 $6 - 1
StrCpy $7 $0 1 $6
${If} $7 == ";"
StrCpy $0 $0 $6 ; Change ';<EnvVar>' to '<EnvVar>'
${EndIf}
; DetailPrint "Scrubbed $1: [$0]" ; Uncomment to debug
${EndIf}
/* Step 3. Remove all instances of the target path/string (even if "A" or "P")
$6 = bool flag (1 = found and removed PathString)
$7 = a string (e.g. path) delimited by semicolon(s)
$8 = entry counter starting at 0
$9 = copy of $0
$R0 = tempChar */
${If} $5 != "" ; If EnvVar is not empty ...
StrCpy $9 $0
StrCpy $0 ""
StrCpy $8 0
StrCpy $6 0
${Do}
${${UN}StrTok} $7 $9 ";" $8 "0" ; $7 = next entry, $8 = entry counter
${If} $7 == "" ; If we've run out of entries,
${ExitDo} ; were done
${EndIf} ;
; Remove leading and trailing spaces from this entry (critical step for Action=Remove)
${Do}
StrCpy $R0 $7 1
${If} $R0 != " "
${ExitDo}
${EndIf}
StrCpy $7 $7 "" 1 ; Remove leading space
${Loop}
${Do}
StrCpy $R0 $7 1 -1
${If} $R0 != " "
${ExitDo}
${EndIf}
StrCpy $7 $7 -1 ; Remove trailing space
${Loop}
${If} $7 == $4 ; If string matches, remove it by not appending it
StrCpy $6 1 ; Set 'found' flag
${ElseIf} $7 != $4 ; If string does NOT match
${AndIf} $0 == "" ; and the 1st string being added to $0,
StrCpy $0 $7 ; copy it to $0 without a prepended semicolon
${ElseIf} $7 != $4 ; If string does NOT match
${AndIf} $0 != "" ; and this is NOT the 1st string to be added to $0,
StrCpy $0 $0;$7 ; append path to $0 with a prepended semicolon
${EndIf} ;
IntOp $8 $8 + 1 ; Bump counter
${Loop} ; Check for duplicates until we run out of paths
${EndIf}
; Step 4: Perform the requested Action
;
${If} $2 != "R" ; If Append or Prepend
${If} $6 == 1 ; And if we found the target
DetailPrint "Target is already present in $1. It will be removed and"
${EndIf}
${If} $0 == "" ; If EnvVar is (now) empty
StrCpy $0 $4 ; just copy PathString to EnvVar
${If} $6 == 0 ; If found flag is either 0
${OrIf} $6 == "" ; or blank (if EnvVarName is empty)
DetailPrint "$1 was empty and has been updated with the target"
${EndIf}
${ElseIf} $2 == "A" ; If Append (and EnvVar is not empty),
StrCpy $0 $0;$4 ; append PathString
${If} $6 == 1
DetailPrint "appended to $1"
${Else}
DetailPrint "Target was appended to $1"
${EndIf}
${Else} ; If Prepend (and EnvVar is not empty),
StrCpy $0 $4;$0 ; prepend PathString
${If} $6 == 1
DetailPrint "prepended to $1"
${Else}
DetailPrint "Target was prepended to $1"
${EndIf}
${EndIf}
${Else} ; If Action = Remove
${If} $6 == 1 ; and we found the target
DetailPrint "Target was found and removed from $1"
${Else}
DetailPrint "Target was NOT found in $1 (nothing to remove)"
${EndIf}
${If} $0 == ""
DetailPrint "$1 is now empty"
${EndIf}
${EndIf}
; Step 5: Update the registry at RegLoc with the updated EnvVar and announce the change
;
ClearErrors
${If} $3 == HKLM
WriteRegExpandStr ${hklm_all_users} $1 $0 ; Write it in all users section
${ElseIf} $3 == HKCU
WriteRegExpandStr ${hkcu_current_user} $1 $0 ; Write it to current user section
${EndIf}
IfErrors 0 +4
MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3"
DetailPrint "Could not write updated $1 to $3"
Goto EnvVarUpdate_Restore_Vars
; "Export" our change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
EnvVarUpdate_Restore_Vars:
;
; Restore the user's variables and return ResultVar
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Push $0 ; Push my $0 (ResultVar)
Exch
Pop $0 ; Restore his $0
FunctionEnd
!macroend ; EnvVarUpdate UN
!insertmacro EnvVarUpdate ""
!insertmacro EnvVarUpdate "un."
;----------------------------------- EnvVarUpdate end----------------------------------------
!verbose pop
!endif
/*
_____________________________________________________________________________
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
; Taken from http://nsis.sourceforge.net/Simple_installer_with_JRE_check by weebib
; Use it as you desire.
; Credit given to so many people of the NSIS forum.
!define AppName "Inkscape Extension Chain Paths"
!define AppVersion "VERSION"
!define ShortName "chain-paths"
!define Vendor "Fab Lab Region Nürnberg e.V."
!include "MUI.nsh"
!include "Sections.nsh"
!include "EnvVarUpdate.nsh"
!include "FileAssociation.nsh"
Var InstallJRE
Var JREPath
;--------------------------------
;Configuration
;General
Name "${AppName}"
OutFile "setup.exe"
;Folder selection page
InstallDir "$PROGRAMFILES\${SHORTNAME}"
;Get install folder from registry if available
InstallDirRegKey HKLM "SOFTWARE\${Vendor}\${ShortName}" ""
; Installation types
;InstType "full" ; Uncomment if you want Installation types
;--------------------------------
;Pages
; License page
; !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Contrib\Modern UI\License.txt"
; This page checks for JRE. It displays a dialog based on JRE.ini if it needs to install JRE
; Otherwise you won't see it.
Page custom CheckInstalledJRE
; Define headers for the 'Java installation successfully' page
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Java installation complete"
!define MUI_PAGE_HEADER_TEXT "Installing Java runtime"
!define MUI_PAGE_HEADER_SUBTEXT "Please wait while we install the Java runtime"
!define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT "Java runtime installed successfully."
!insertmacro MUI_PAGE_INSTFILES
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Installation complete"
!define MUI_PAGE_HEADER_TEXT "Installing"
!define MUI_PAGE_HEADER_SUBTEXT "Please wait while ${AppName} is being installed."
; Uncomment the next line if you want optional components to be selectable
; !insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE myPreInstfiles
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE RestoreSections
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Modern UI Configuration
!define MUI_ABORTWARNING
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Language Strings
;Description
LangString DESC_SecAppFiles ${LANG_ENGLISH} "Application files copy"
;Header
LangString TEXT_JRE_TITLE ${LANG_ENGLISH} "Java Runtime Environment"
LangString TEXT_JRE_SUBTITLE ${LANG_ENGLISH} "Installation"
LangString TEXT_PRODVER_TITLE ${LANG_ENGLISH} "Installed version of ${AppName}"
LangString TEXT_PRODVER_SUBTITLE ${LANG_ENGLISH} "Installation cancelled"
;--------------------------------
;Reserve Files
;Only useful for BZIP2 compression
ReserveFile "jre.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;--------------------------------
;Installer Sections
Section -installjre jre
Push $0
Push $1
; MessageBox MB_OK "Inside JRE Section"
Strcmp $InstallJRE "yes" InstallJRE JREPathStorage
DetailPrint "Starting the JRE installation"
InstallJRE:
File /oname=$TEMP\jre_setup.exe j2re-setup.exe
; MessageBox MB_OK "Installing JRE"
DetailPrint "Launching JRE setup"
; commandline switches see https://www.java.com/de/download/help/silent_install.xml
; we leave out the silent-install switch /s for now to find problems easier
; there could be problems with closing browser windows etc.
; SPONSORS=0 disables the silly "Ask toolbar" crapware bundled with Java
ExecWait '"$TEMP\jre_setup.exe" SPONSORS=0' $0
DetailPrint "Setup finished"
Delete "$TEMP\jre_setup.exe"
StrCmp $0 "0" InstallVerif 0
Push "The JRE setup has been abnormally interrupted."
Goto ExitInstallJRE
InstallVerif:
DetailPrint "Checking the JRE Setup's outcome"
; MessageBox MB_OK "Checking JRE outcome"
Push "${JRE_VERSION}"
Call DetectJRE
Pop $0 ; DetectJRE's return value
StrCmp $0 "0" ExitInstallJRE 0
StrCmp $0 "-1" ExitInstallJRE 0
Goto JavaExeVerif
Push "The JRE setup failed"
Goto ExitInstallJRE
JavaExeVerif:
IfFileExists $0 JREPathStorage 0
Push "The following file : $0, cannot be found."
Goto ExitInstallJRE
JREPathStorage:
; MessageBox MB_OK "Path Storage"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "UserDefinedSection" "JREPath" $1
StrCpy $JREPath $0
Goto End
ExitInstallJRE:
Pop $1
MessageBox MB_OK "The setup is about to be interrupted for the following reason : $1"
Pop $1 ; Restore $1
Pop $0 ; Restore $0
Abort
End:
Pop $1 ; Restore $1
Pop $0 ; Restore $0
SectionEnd
Section "Installation of ${AppName}" SecAppFiles
SectionIn 1 RO ; Full install, cannot be unselected
; If you add more sections be sure to add them here as well
SetOutPath $INSTDIR
File /r "stream\"
; If you need the path to JRE, you can either get it here for from $JREPath
; !insertmacro MUI_INSTALLOPTIONS_READ $0 "jre.ini" "UserDefinedSection" "JREPath"
; MessageBox MB_OK "JRE Read: $0"
;Store install folder
WriteRegStr HKLM "SOFTWARE\${Vendor}\${ShortName}" "" $INSTDIR
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "DisplayName" "${AppName}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "NoModify" "1"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "NoRepair" "1"
; instert visicut to path
Push $0
Push $1
; string length check taken from CMake/Modules/NSIS.template.in
; if the path is too long for a NSIS variable NSIS will return a 0
; length string. If we find that, then warn and skip any path
; modification as it will trash the existing path.
ReadEnvStr $0 PATH
StrLen $1 $0
IntCmp $1 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
CheckPathLength_ShowPathWarning:
Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long, installer unable to modify PATH!"
Goto AddToPath_done
CheckPathLength_Done:
; update path if it is safe:
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR"
AddToPath_done:
Pop $1
Pop $0
; register file extensions
${registerExtension} "$INSTDIR\VisiCut.exe" ".ls" "VisiCut LaserScript File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".plf" "VisiCut Portable Laser File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".svg" "SVG File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".dxf" "DXF File"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
Section "Start menu shortcuts" SecCreateShortcut
SectionIn 1 ; Can be unselected
CreateDirectory "$SMPROGRAMS\${AppName}"
CreateShortCut "$SMPROGRAMS\${AppName}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\${AppName}\${AppName}.lnk" "$INSTDIR\${AppName}.exe" "" "$INSTDIR\${AppName}.exe" 0
; Etc
SectionEnd
;--------------------------------
;Descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecAppFiles} $(DESC_SecAppFiles)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Installer Functions
Function .onInit
;Extract InstallOptions INI Files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "jre.ini"
Call SetupSections
FunctionEnd
Function myPreInstfiles
Call RestoreSections
SetAutoClose true
FunctionEnd
Function CheckInstalledJRE
; MessageBox MB_OK "Checking Installed JRE Version"
Push "${JRE_VERSION}"
Call DetectJRE
; Messagebox MB_OK "Done checking JRE version"
Exch $0 ; Get return value from stack
StrCmp $0 "0" NoFound
StrCmp $0 "-1" FoundOld
Goto JREAlreadyInstalled
FoundOld:
; MessageBox MB_OK "Old JRE found"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "Field 1" "Text" "${AppName} requires a more recent version of the Java Runtime Environment than the one found on your computer. The installation of JRE ${JRE_VERSION} will start."
!insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "jre.ini"
Goto MustInstallJRE
NoFound:
; MessageBox MB_OK "JRE not found"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "Field 1" "Text" "No Java Runtime Environment could be found. JRE v${JRE_VERSION} will be installed."
!insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "jre.ini"
Goto MustInstallJRE
MustInstallJRE:
Exch $0 ; $0 now has the installoptions page return value
; Do something with return value here
Pop $0 ; Restore $0
StrCpy $InstallJRE "yes"
Return
JREAlreadyInstalled:
; MessageBox MB_OK "No download: ${TEMP2}"
; MessageBox MB_OK "JRE already installed"
StrCpy $InstallJRE "no"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "UserDefinedSection" "JREPath" $JREPATH
Pop $0 ; Restore $0
Return
FunctionEnd
; Returns: 0 - JRE not found. -1 - JRE found but too old. Otherwise - Path to JAVA EXE
; DetectJRE. Version requested is on the stack.
; Returns (on stack) "0" on failure (java too old or not installed), otherwise path to java interpreter
; Stack value will be overwritten!
Function DetectJRE
Exch $0 ; Get version requested
; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0
Push $1 ; $1 = Java version string (ie 1.5.0)
Push $2 ; $2 = Javahome
Push $3 ; $3 and $4 are used for checking the major/minor version of java
Push $4
; MessageBox MB_OK "Detecting JRE"
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
; MessageBox MB_OK "Read : $1"
StrCmp $1 "" DetectTry2
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "JavaHome"
; MessageBox MB_OK "Read 3: $2"
StrCmp $2 "" DetectTry2
Goto GetJRE
DetectTry2:
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
; MessageBox MB_OK "Detect Read : $1"
StrCmp $1 "" NoFound
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome"
; MessageBox MB_OK "Detect Read 3: $2"
StrCmp $2 "" NoFound
GetJRE:
; $0 = version requested. $1 = version found. $2 = javaHome
; MessageBox MB_OK "Getting JRE"
IfFileExists "$2\bin\java.exe" 0 NoFound
StrCpy $3 $0 1 ; Get major version. Example: $1 = 1.5.0, now $3 = 1
StrCpy $4 $1 1 ; $3 = major version requested, $4 = major version found
; MessageBox MB_OK "Want $3 , found $4"
IntCmp $4 $3 0 FoundOld FoundNew
StrCpy $3 $0 1 2
StrCpy $4 $1 1 2 ; Same as above. $3 is minor version requested, $4 is minor version installed
; MessageBox MB_OK "Want $3 , found $4"
IntCmp $4 $3 FoundNew FoundOld FoundNew
NoFound:
; MessageBox MB_OK "JRE not found"
Push "0"
Goto DetectJREEnd
FoundOld:
MessageBox MB_OK "JRE too old: $3 is older than $4"
; Push ${TEMP2}
Push "-1"
Goto DetectJREEnd
FoundNew:
; MessageBox MB_OK "JRE is new: $3 is newer than $4"
Push "$2\bin\java.exe"
; Push "OK"
; Return
Goto DetectJREEnd
DetectJREEnd:
; Top of stack is return value, then r4,r3,r2,r1
Exch ; => r4,rv,r3,r2,r1,r0
Pop $4 ; => rv,r3,r2,r1r,r0
Exch ; => r3,rv,r2,r1,r0
Pop $3 ; => rv,r2,r1,r0
Exch ; => r2,rv,r1,r0
Pop $2 ; => rv,r1,r0
Exch ; => r1,rv,r0
Pop $1 ; => rv,r0
Exch ; => r0,rv
Pop $0 ; => rv
FunctionEnd
Function RestoreSections
!insertmacro UnselectSection ${jre}
!insertmacro SelectSection ${SecAppFiles}
!insertmacro SelectSection ${SecCreateShortcut}
FunctionEnd
Function SetupSections
!insertmacro SelectSection ${jre}
!insertmacro UnselectSection ${SecAppFiles}
!insertmacro UnselectSection ${SecCreateShortcut}
FunctionEnd
;--------------------------------
;Uninstaller Section
Section "Uninstall"
; remove visicut from path
Push $0
Push $1
; string length check taken from CMake/Modules/NSIS.template.in
; if the path is too long for a NSIS variable NSIS will return a 0
; length string. If we find that, then warn and skip any path
; modification as it will trash the existing path.
ReadEnvStr $0 PATH
StrLen $1 $0
IntCmp $1 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
CheckPathLength_ShowPathWarning:
Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long, installer unable to modify PATH!"
Goto AddToPath_done
CheckPathLength_Done:
; update path if it is safe:
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR"
AddToPath_done:
Pop $1
Pop $0
; remove file associations
${unregisterExtension} ".plf" "VisiCut Portable Laser File"
${unregisterExtension} ".svg" "SVG File"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}"
DeleteRegKey HKLM "SOFTWARE\${Vendor}\${AppName}"
; remove shortcuts, if any.
Delete "$SMPROGRAMS\${AppName}\*.*"
; remove files
RMDir /r "$INSTDIR"
SectionEnd
; Java Launcher
;--------------
;You want to change the next four lines
Name "VisiCut"
Caption "a userfriendly tool for Lasercutting"
Icon "VisiCut.ico"
OutFile "VisiCut.exe"
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
RequestExecutionLevel user
;You want to change the next two lines too
!define CLASSPATH ".;lib"
!define JARFILE "Visicut.jar"
!define VMARGS "-Xms256m -Xmx512m"
!define PRGARGS "--singleinstanceport 6543"
!include "FileFunc.nsh"
!insertmacro GetParameters
Section ""
Call GetJRE
Pop $R0
${GetParameters} $1
; change for your purpose (-jar etc.)
StrCpy $0 '"$R0" ${VMARGS} -classpath "${CLASSPATH}" -jar ${JARFILE} ${PRGARGS} $1'
SetOutPath $EXEDIR
ExecWait $0
SectionEnd
Function GetJRE
;
; Find JRE (javaw.exe)
; 1 - in .\jre directory (JRE Installed with application)
; 2 - in JAVA_HOME environment variable
; 3 - in the registry
; 4 - assume javaw.exe in current dir or PATH
Push $R0
Push $R1
ClearErrors
StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
IfFileExists $R0 JreFound
StrCpy $R0 ""
ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound
StrCpy $R0 "javaw.exe"
JreFound:
Pop $R1
Exch $R0
FunctionEnd
; Taken from http://nsis.sourceforge.net/Simple_installer_with_JRE_check by weebib
; Use it as you desire.
; Credit given to so many people of the NSIS forum.
!define AppName "Inkscape Extension Chain Paths"
!define AppVersion "VERSION"
!define ShortName "chain-paths"
!define Vendor "Fab Lab Region Nürnberg e.V."
!include "MUI.nsh"
!include "Sections.nsh"
!include "EnvVarUpdate.nsh"
!include "FileAssociation.nsh"
Var InstallJRE
Var JREPath
;--------------------------------
;Configuration
;General
Name "${AppName}"
OutFile "setup.exe"
;Folder selection page
InstallDir "$PROGRAMFILES\${SHORTNAME}"
;Get install folder from registry if available
InstallDirRegKey HKLM "SOFTWARE\${Vendor}\${ShortName}" ""
; Installation types
;InstType "full" ; Uncomment if you want Installation types
;--------------------------------
;Pages
; License page
; !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Contrib\Modern UI\License.txt"
; This page checks for JRE. It displays a dialog based on JRE.ini if it needs to install JRE
; Otherwise you won't see it.
Page custom CheckInstalledJRE
; Define headers for the 'Java installation successfully' page
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Java installation complete"
!define MUI_PAGE_HEADER_TEXT "Installing Java runtime"
!define MUI_PAGE_HEADER_SUBTEXT "Please wait while we install the Java runtime"
!define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT "Java runtime installed successfully."
!insertmacro MUI_PAGE_INSTFILES
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Installation complete"
!define MUI_PAGE_HEADER_TEXT "Installing"
!define MUI_PAGE_HEADER_SUBTEXT "Please wait while ${AppName} is being installed."
; Uncomment the next line if you want optional components to be selectable
; !insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE myPreInstfiles
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE RestoreSections
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Modern UI Configuration
!define MUI_ABORTWARNING
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Language Strings
;Description
LangString DESC_SecAppFiles ${LANG_ENGLISH} "Application files copy"
;Header
LangString TEXT_JRE_TITLE ${LANG_ENGLISH} "Java Runtime Environment"
LangString TEXT_JRE_SUBTITLE ${LANG_ENGLISH} "Installation"
LangString TEXT_PRODVER_TITLE ${LANG_ENGLISH} "Installed version of ${AppName}"
LangString TEXT_PRODVER_SUBTITLE ${LANG_ENGLISH} "Installation cancelled"
;--------------------------------
;Reserve Files
;Only useful for BZIP2 compression
ReserveFile "jre.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;--------------------------------
;Installer Sections
Section -installjre jre
Push $0
Push $1
; MessageBox MB_OK "Inside JRE Section"
Strcmp $InstallJRE "yes" InstallJRE JREPathStorage
DetailPrint "Starting the JRE installation"
InstallJRE:
File /oname=$TEMP\jre_setup.exe j2re-setup.exe
; MessageBox MB_OK "Installing JRE"
DetailPrint "Launching JRE setup"
; commandline switches see https://www.java.com/de/download/help/silent_install.xml
; we leave out the silent-install switch /s for now to find problems easier
; there could be problems with closing browser windows etc.
; SPONSORS=0 disables the silly "Ask toolbar" crapware bundled with Java
ExecWait '"$TEMP\jre_setup.exe" SPONSORS=0' $0
DetailPrint "Setup finished"
Delete "$TEMP\jre_setup.exe"
StrCmp $0 "0" InstallVerif 0
Push "The JRE setup has been abnormally interrupted."
Goto ExitInstallJRE
InstallVerif:
DetailPrint "Checking the JRE Setup's outcome"
; MessageBox MB_OK "Checking JRE outcome"
Push "${JRE_VERSION}"
Call DetectJRE
Pop $0 ; DetectJRE's return value
StrCmp $0 "0" ExitInstallJRE 0
StrCmp $0 "-1" ExitInstallJRE 0
Goto JavaExeVerif
Push "The JRE setup failed"
Goto ExitInstallJRE
JavaExeVerif:
IfFileExists $0 JREPathStorage 0
Push "The following file : $0, cannot be found."
Goto ExitInstallJRE
JREPathStorage:
; MessageBox MB_OK "Path Storage"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "UserDefinedSection" "JREPath" $1
StrCpy $JREPath $0
Goto End
ExitInstallJRE:
Pop $1
MessageBox MB_OK "The setup is about to be interrupted for the following reason : $1"
Pop $1 ; Restore $1
Pop $0 ; Restore $0
Abort
End:
Pop $1 ; Restore $1
Pop $0 ; Restore $0
SectionEnd
Section "Installation of ${AppName}" SecAppFiles
SectionIn 1 RO ; Full install, cannot be unselected
; If you add more sections be sure to add them here as well
SetOutPath $INSTDIR
File /r "stream\"
; If you need the path to JRE, you can either get it here for from $JREPath
; !insertmacro MUI_INSTALLOPTIONS_READ $0 "jre.ini" "UserDefinedSection" "JREPath"
; MessageBox MB_OK "JRE Read: $0"
;Store install folder
WriteRegStr HKLM "SOFTWARE\${Vendor}\${ShortName}" "" $INSTDIR
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "DisplayName" "${AppName}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "NoModify" "1"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}" "NoRepair" "1"
; instert visicut to path
Push $0
Push $1
; string length check taken from CMake/Modules/NSIS.template.in
; if the path is too long for a NSIS variable NSIS will return a 0
; length string. If we find that, then warn and skip any path
; modification as it will trash the existing path.
ReadEnvStr $0 PATH
StrLen $1 $0
IntCmp $1 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
CheckPathLength_ShowPathWarning:
Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long, installer unable to modify PATH!"
Goto AddToPath_done
CheckPathLength_Done:
; update path if it is safe:
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR"
AddToPath_done:
Pop $1
Pop $0
; register file extensions
${registerExtension} "$INSTDIR\VisiCut.exe" ".ls" "VisiCut LaserScript File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".plf" "VisiCut Portable Laser File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".svg" "SVG File"
${registerExtension} "$INSTDIR\VisiCut.exe" ".dxf" "DXF File"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
Section "Start menu shortcuts" SecCreateShortcut
SectionIn 1 ; Can be unselected
CreateDirectory "$SMPROGRAMS\${AppName}"
CreateShortCut "$SMPROGRAMS\${AppName}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\${AppName}\${AppName}.lnk" "$INSTDIR\${AppName}.exe" "" "$INSTDIR\${AppName}.exe" 0
; Etc
SectionEnd
;--------------------------------
;Descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecAppFiles} $(DESC_SecAppFiles)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Installer Functions
Function .onInit
;Extract InstallOptions INI Files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "jre.ini"
Call SetupSections
FunctionEnd
Function myPreInstfiles
Call RestoreSections
SetAutoClose true
FunctionEnd
Function CheckInstalledJRE
; MessageBox MB_OK "Checking Installed JRE Version"
Push "${JRE_VERSION}"
Call DetectJRE
; Messagebox MB_OK "Done checking JRE version"
Exch $0 ; Get return value from stack
StrCmp $0 "0" NoFound
StrCmp $0 "-1" FoundOld
Goto JREAlreadyInstalled
FoundOld:
; MessageBox MB_OK "Old JRE found"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "Field 1" "Text" "${AppName} requires a more recent version of the Java Runtime Environment than the one found on your computer. The installation of JRE ${JRE_VERSION} will start."
!insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "jre.ini"
Goto MustInstallJRE
NoFound:
; MessageBox MB_OK "JRE not found"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "Field 1" "Text" "No Java Runtime Environment could be found. JRE v${JRE_VERSION} will be installed."
!insertmacro MUI_HEADER_TEXT "$(TEXT_JRE_TITLE)" "$(TEXT_JRE_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "jre.ini"
Goto MustInstallJRE
MustInstallJRE:
Exch $0 ; $0 now has the installoptions page return value
; Do something with return value here
Pop $0 ; Restore $0
StrCpy $InstallJRE "yes"
Return
JREAlreadyInstalled:
; MessageBox MB_OK "No download: ${TEMP2}"
; MessageBox MB_OK "JRE already installed"
StrCpy $InstallJRE "no"
!insertmacro MUI_INSTALLOPTIONS_WRITE "jre.ini" "UserDefinedSection" "JREPath" $JREPATH
Pop $0 ; Restore $0
Return
FunctionEnd
; Returns: 0 - JRE not found. -1 - JRE found but too old. Otherwise - Path to JAVA EXE
; DetectJRE. Version requested is on the stack.
; Returns (on stack) "0" on failure (java too old or not installed), otherwise path to java interpreter
; Stack value will be overwritten!
Function DetectJRE
Exch $0 ; Get version requested
; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0
Push $1 ; $1 = Java version string (ie 1.5.0)
Push $2 ; $2 = Javahome
Push $3 ; $3 and $4 are used for checking the major/minor version of java
Push $4
; MessageBox MB_OK "Detecting JRE"
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
; MessageBox MB_OK "Read : $1"
StrCmp $1 "" DetectTry2
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "JavaHome"
; MessageBox MB_OK "Read 3: $2"
StrCmp $2 "" DetectTry2
Goto GetJRE
DetectTry2:
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
; MessageBox MB_OK "Detect Read : $1"
StrCmp $1 "" NoFound
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome"
; MessageBox MB_OK "Detect Read 3: $2"
StrCmp $2 "" NoFound
GetJRE:
; $0 = version requested. $1 = version found. $2 = javaHome
; MessageBox MB_OK "Getting JRE"
IfFileExists "$2\bin\java.exe" 0 NoFound
StrCpy $3 $0 1 ; Get major version. Example: $1 = 1.5.0, now $3 = 1
StrCpy $4 $1 1 ; $3 = major version requested, $4 = major version found
; MessageBox MB_OK "Want $3 , found $4"
IntCmp $4 $3 0 FoundOld FoundNew
StrCpy $3 $0 1 2
StrCpy $4 $1 1 2 ; Same as above. $3 is minor version requested, $4 is minor version installed
; MessageBox MB_OK "Want $3 , found $4"
IntCmp $4 $3 FoundNew FoundOld FoundNew
NoFound:
; MessageBox MB_OK "JRE not found"
Push "0"
Goto DetectJREEnd
FoundOld:
MessageBox MB_OK "JRE too old: $3 is older than $4"
; Push ${TEMP2}
Push "-1"
Goto DetectJREEnd
FoundNew:
; MessageBox MB_OK "JRE is new: $3 is newer than $4"
Push "$2\bin\java.exe"
; Push "OK"
; Return
Goto DetectJREEnd
DetectJREEnd:
; Top of stack is return value, then r4,r3,r2,r1
Exch ; => r4,rv,r3,r2,r1,r0
Pop $4 ; => rv,r3,r2,r1r,r0
Exch ; => r3,rv,r2,r1,r0
Pop $3 ; => rv,r2,r1,r0
Exch ; => r2,rv,r1,r0
Pop $2 ; => rv,r1,r0
Exch ; => r1,rv,r0
Pop $1 ; => rv,r0
Exch ; => r0,rv
Pop $0 ; => rv
FunctionEnd
Function RestoreSections
!insertmacro UnselectSection ${jre}
!insertmacro SelectSection ${SecAppFiles}
!insertmacro SelectSection ${SecCreateShortcut}
FunctionEnd
Function SetupSections
!insertmacro SelectSection ${jre}
!insertmacro UnselectSection ${SecAppFiles}
!insertmacro UnselectSection ${SecCreateShortcut}
FunctionEnd
;--------------------------------
;Uninstaller Section
Section "Uninstall"
; remove visicut from path
Push $0
Push $1
; string length check taken from CMake/Modules/NSIS.template.in
; if the path is too long for a NSIS variable NSIS will return a 0
; length string. If we find that, then warn and skip any path
; modification as it will trash the existing path.
ReadEnvStr $0 PATH
StrLen $1 $0
IntCmp $1 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
CheckPathLength_ShowPathWarning:
Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long, installer unable to modify PATH!"
Goto AddToPath_done
CheckPathLength_Done:
; update path if it is safe:
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR"
AddToPath_done:
Pop $1
Pop $0
; remove file associations
${unregisterExtension} ".plf" "VisiCut Portable Laser File"
${unregisterExtension} ".svg" "SVG File"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ShortName}"
DeleteRegKey HKLM "SOFTWARE\${Vendor}\${AppName}"
; remove shortcuts, if any.
Delete "$SMPROGRAMS\${AppName}\*.*"
; remove files
RMDir /r "$INSTDIR"
SectionEnd
; Java Launcher
;--------------
;You want to change the next four lines
Name "VisiCut"
Caption "a userfriendly tool for Lasercutting"
Icon "VisiCut.ico"
OutFile "VisiCut.exe"
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
RequestExecutionLevel user
;You want to change the next two lines too
!define CLASSPATH ".;lib"
!define JARFILE "Visicut.jar"
!define VMARGS "-Xms256m -Xmx512m"
!define PRGARGS "--singleinstanceport 6543"
!include "FileFunc.nsh"
!insertmacro GetParameters
Section ""
Call GetJRE
Pop $R0
${GetParameters} $1
; change for your purpose (-jar etc.)
StrCpy $0 '"$R0" ${VMARGS} -classpath "${CLASSPATH}" -jar ${JARFILE} ${PRGARGS} $1'
SetOutPath $EXEDIR
ExecWait $0
SectionEnd
Function GetJRE
;
; Find JRE (javaw.exe)
; 1 - in .\jre directory (JRE Installed with application)
; 2 - in JAVA_HOME environment variable
; 3 - in the registry
; 4 - assume javaw.exe in current dir or PATH
Push $R0
Push $R1
ClearErrors
StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
IfFileExists $R0 JreFound
StrCpy $R0 ""
ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound
StrCpy $R0 "javaw.exe"
JreFound:
Pop $R1
Exch $R0
FunctionEnd
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment