chiark / gitweb /
Add option to install all other Cura versions.
authordaid <daid303@gmail.com>
Thu, 19 Jun 2014 07:45:15 +0000 (09:45 +0200)
committerdaid <daid303@gmail.com>
Thu, 19 Jun 2014 07:45:15 +0000 (09:45 +0200)
scripts/win32/installer.nsi

index 5a66217cdddbc3b0029f5bc75a21608ef5adf1fb..06dd0c6eebefcbce665868e253c0088d162b2c53 100644 (file)
@@ -24,7 +24,59 @@ SetCompressor /SOLID lzma
 ;--------------------------------
 
 !include "MUI2.nsh"
-!include Library.nsh
+!include "Library.nsh"
+
+;--------------------------------
+
+; 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"'
+;--------------------------------
 
 !define MUI_ICON "dist/resources/cura.ico"
 !define MUI_BGCOLOR FFFFFF
@@ -144,6 +196,21 @@ Section /o "Open AMF files with Cura"
        WriteRegStr HKCR "Cura AMF model file\shell\open\command" "" '"$INSTDIR\python\pythonw.exe" -c "import os; os.chdir(\"$INSTDIR\"); import Cura.cura; Cura.cura.main()" "%1"'
 SectionEnd
 
+Section /o "Uninstall other Cura versions"
+       StrCpy $0 0
+       loop:
+               EnumRegKey $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" $0
+               StrCmp $1 "" done
+               IntOp $0 $0 + 1
+               StrCmp $1 "Cura_${VERSION}" loop
+               ${StrContains} $2 "Cura_" $1
+               StrCmp $2 "" loop
+               
+               ReadRegStr $3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$1" "UninstallString"
+               ExecWait '"$3" /S _?=$INSTDIR'
+       done:
+SectionEnd
+
 ;--------------------------------
 
 ; Uninstaller
@@ -161,4 +228,3 @@ Section "Uninstall"
   RMDir /r "$INSTDIR"
 
 SectionEnd
-