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