chiark / gitweb /
Merge tag '15.01-RC8' into upstream
[cura.git] / scripts / win32 / installer.nsi
1 !ifndef VERSION
2   !define VERSION 'DEV'
3 !endif
4 !addplugindir "nsisPlugins"
5
6 ; The name of the installer
7 Name "Cura ${VERSION}"
8
9 ; The file to write
10 OutFile "Cura_${VERSION}.exe"
11
12 ; The default installation directory
13 InstallDir $PROGRAMFILES\Cura_${VERSION}
14
15 ; Registry key to check for directory (so if you install again, it will 
16 ; overwrite the old one automatically)
17 InstallDirRegKey HKLM "Software\Cura_${VERSION}" "Install_Dir"
18
19 ; Request application privileges for Windows Vista
20 RequestExecutionLevel admin
21
22 ; Set the LZMA compressor to reduce size.
23 SetCompressor /SOLID lzma
24 ;--------------------------------
25
26 !include "MUI2.nsh"
27 !include "Library.nsh"
28
29 !system "check_drivers.bat"
30
31 ;--------------------------------
32
33 ; StrContains
34 ; This function does a case sensitive searches for an occurrence of a substring in a string. 
35 ; It returns the substring if it is found. 
36 ; Otherwise it returns null(""). 
37 ; Written by kenglish_hi
38 ; Adapted from StrReplace written by dandaman32
39  
40  
41 Var STR_HAYSTACK
42 Var STR_NEEDLE
43 Var STR_CONTAINS_VAR_1
44 Var STR_CONTAINS_VAR_2
45 Var STR_CONTAINS_VAR_3
46 Var STR_CONTAINS_VAR_4
47 Var STR_RETURN_VAR
48  
49 Function StrContains
50   Exch $STR_NEEDLE
51   Exch 1
52   Exch $STR_HAYSTACK
53   ; Uncomment to debug
54   ;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
55     StrCpy $STR_RETURN_VAR ""
56     StrCpy $STR_CONTAINS_VAR_1 -1
57     StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
58     StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
59     loop:
60       IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
61       StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
62       StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
63       StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
64       Goto loop
65     found:
66       StrCpy $STR_RETURN_VAR $STR_NEEDLE
67       Goto done
68     done:
69    Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
70    Exch $STR_RETURN_VAR  
71 FunctionEnd
72  
73 !macro _StrContainsConstructor OUT NEEDLE HAYSTACK
74   Push `${HAYSTACK}`
75   Push `${NEEDLE}`
76   Call StrContains
77   Pop `${OUT}`
78 !macroend
79  
80 !define StrContains '!insertmacro "_StrContainsConstructor"'
81 ;--------------------------------
82
83 !define MUI_ICON "dist/resources/cura.ico"
84 !define MUI_BGCOLOR FFFFFF
85
86 ; Directory page defines
87 !define MUI_DIRECTORYPAGE_VERIFYONLEAVE
88
89 ; Header
90 !define MUI_HEADERIMAGE
91 !define MUI_HEADERIMAGE_RIGHT
92 !define MUI_HEADERIMAGE_BITMAP "header.bmp"
93 !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH 
94 ; Don't show the component description box
95 !define MUI_COMPONENTSPAGE_NODESC
96
97 ;Do not leave (Un)Installer page automaticly
98 !define MUI_FINISHPAGE_NOAUTOCLOSE
99 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
100
101 ;Run Cura after installing
102 !define MUI_FINISHPAGE_RUN
103 !define MUI_FINISHPAGE_RUN_TEXT "Start Cura ${VERSION}"
104 !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
105
106 ; Pages
107 ;!insertmacro MUI_PAGE_WELCOME
108 !insertmacro MUI_PAGE_DIRECTORY
109 !insertmacro MUI_PAGE_COMPONENTS
110 !insertmacro MUI_PAGE_INSTFILES
111 !insertmacro MUI_PAGE_FINISH
112 !insertmacro MUI_UNPAGE_CONFIRM
113 !insertmacro MUI_UNPAGE_INSTFILES
114 !insertmacro MUI_UNPAGE_FINISH
115
116 ; Languages
117 !insertmacro MUI_LANGUAGE "English"
118
119 ; Reserve Files
120 !insertmacro MUI_RESERVEFILE_LANGDLL
121 ReserveFile '${NSISDIR}\Plugins\InstallOptions.dll'
122 ReserveFile "header.bmp"
123
124 ;--------------------------------
125
126 ; The stuff to install
127 Section "Cura ${VERSION}"
128
129   SectionIn RO
130   
131   ; Set output path to the installation directory.
132   SetOutPath $INSTDIR
133   
134   ; Put file there
135   File /r "dist\"
136   
137   ; Write the installation path into the registry
138   WriteRegStr HKLM "SOFTWARE\Cura_${VERSION}" "Install_Dir" "$INSTDIR"
139   
140   ; Write the uninstall keys for Windows
141   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cura_${VERSION}" "DisplayName" "Cura ${VERSION}"
142   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cura_${VERSION}" "UninstallString" '"$INSTDIR\uninstall.exe"'
143   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cura_${VERSION}" "NoModify" 1
144   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cura_${VERSION}" "NoRepair" 1
145   WriteUninstaller "uninstall.exe"
146
147   ; Write start menu entries for all users
148   SetShellVarContext all
149   
150   CreateDirectory "$SMPROGRAMS\Cura ${VERSION}"
151   CreateShortCut "$SMPROGRAMS\Cura ${VERSION}\Uninstall Cura ${VERSION}.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
152   CreateShortCut "$SMPROGRAMS\Cura ${VERSION}\Cura ${VERSION}.lnk" "$INSTDIR\python\pythonw.exe" '-m "Cura.cura"' "$INSTDIR\resources\cura.ico" 0
153   
154 SectionEnd
155
156 Function LaunchLink
157   ; Write start menu entries for all users
158   SetShellVarContext all
159   Exec '"$WINDIR\explorer.exe" "$SMPROGRAMS\Cura ${VERSION}\Cura ${VERSION}.lnk"'
160 FunctionEnd
161
162 Section "Install Arduino Drivers"
163   ; Set output path to the driver directory.
164   SetOutPath "$INSTDIR\drivers\"
165   File /r "drivers\"
166   
167   ${If} ${RunningX64}
168     IfSilent +2
169       ExecWait '"$INSTDIR\drivers\dpinst64.exe" /lm'
170   ${Else}
171     IfSilent +2
172       ExecWait '"$INSTDIR\drivers\dpinst32.exe" /lm'
173   ${EndIf}
174 SectionEnd
175
176 Section "Open STL files with Cura"
177         WriteRegStr HKCR .stl "" "Cura STL model file"
178         DeleteRegValue HKCR .stl "Content Type"
179         WriteRegStr HKCR "Cura STL model file\DefaultIcon" "" "$INSTDIR\resources\stl.ico,0"
180         WriteRegStr HKCR "Cura STL model file\shell" "" "open"
181         WriteRegStr HKCR "Cura STL model file\shell\open\command" "" '"$INSTDIR\python\pythonw.exe" -c "import os; os.chdir(\"$INSTDIR\"); import Cura.cura; Cura.cura.main()" "%1"'
182 SectionEnd
183
184 Section /o "Open OBJ files with Cura"
185         WriteRegStr HKCR .obj "" "Cura OBJ model file"
186         DeleteRegValue HKCR .obj "Content Type"
187         WriteRegStr HKCR "Cura OBJ model file\DefaultIcon" "" "$INSTDIR\resources\stl.ico,0"
188         WriteRegStr HKCR "Cura OBJ model file\shell" "" "open"
189         WriteRegStr HKCR "Cura OBJ model file\shell\open\command" "" '"$INSTDIR\python\pythonw.exe" -c "import os; os.chdir(\"$INSTDIR\"); import Cura.cura; Cura.cura.main()" "%1"'
190 SectionEnd
191
192 Section /o "Open AMF files with Cura"
193         WriteRegStr HKCR .amf "" "Cura AMF model file"
194         DeleteRegValue HKCR .amf "Content Type"
195         WriteRegStr HKCR "Cura AMF model file\DefaultIcon" "" "$INSTDIR\resources\stl.ico,0"
196         WriteRegStr HKCR "Cura AMF model file\shell" "" "open"
197         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"'
198 SectionEnd
199
200 ;--------------------------------
201
202 ; Uninstaller
203
204 Section "Uninstall"
205   
206   ; Remove registry keys
207   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cura_${VERSION}"
208   DeleteRegKey HKLM "SOFTWARE\Cura_${VERSION}"
209
210   ; Write start menu entries for all users
211   SetShellVarContext all
212   ; Remove directories used
213   RMDir /r "$SMPROGRAMS\Cura ${VERSION}"
214   RMDir /r "$INSTDIR"
215
216 SectionEnd