[win32] installer: move addon copy
[vuplus_xbmc] / project / Win32BuildSetup / XBMC for Windows.nsi
1 ;XBMC for Windows install script
2 ;Copyright (C) 2005-2013 Team XBMC
3 ;http://xbmc.org
4
5 ;Script by chadoe
6
7 ;--------------------------------
8 ;Include Modern UI
9
10   !include "MUI2.nsh"
11   !include "nsDialogs.nsh"
12   !include "LogicLib.nsh"
13   !include "WinVer.nsh"
14   
15 ;--------------------------------
16 ;define global used name
17   !define APP_NAME "XBMC"
18
19 ;--------------------------------
20 ;General
21
22   ;Name and file
23   Name "${APP_NAME}"
24   OutFile "${APP_NAME}Setup-${xbmc_revision}-${xbmc_branch}.exe"
25
26   XPStyle on
27   
28   ;Default installation folder
29   InstallDir "$PROGRAMFILES\${APP_NAME}"
30
31   ;Get installation folder from registry if available
32   InstallDirRegKey HKCU "Software\${APP_NAME}" ""
33
34   ;Request application privileges for Windows Vista
35   RequestExecutionLevel admin
36
37 ;--------------------------------
38 ;Variables
39
40   Var StartMenuFolder
41   Var PageProfileState
42   Var DirectXSetupError
43   Var VSRedistSetupError
44   
45 ;--------------------------------
46 ;Interface Settings
47
48   !define MUI_HEADERIMAGE
49   !define MUI_ICON "..\..\xbmc\win32\xbmc.ico"
50   !define MUI_WELCOMEFINISHPAGE_BITMAP "xbmc-left.bmp"
51   !define MUI_COMPONENTSPAGE_SMALLDESC
52   !define MUI_FINISHPAGE_LINK "Please visit http://xbmc.org for more information."
53   !define MUI_FINISHPAGE_LINK_LOCATION "http://xbmc.org"
54   !define MUI_FINISHPAGE_RUN "$INSTDIR\${APP_NAME}.exe"
55   !define MUI_FINISHPAGE_RUN_NOTCHECKED
56   !define MUI_ABORTWARNING  
57 ;--------------------------------
58 ;Pages
59
60   !insertmacro MUI_PAGE_WELCOME
61   !insertmacro MUI_PAGE_LICENSE "..\..\LICENSE.GPL"
62   !insertmacro MUI_PAGE_COMPONENTS
63   !insertmacro MUI_PAGE_DIRECTORY
64   
65   ;Start Menu Folder Page Configuration
66   !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
67   !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${APP_NAME}" 
68   !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
69   !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder  
70
71   !insertmacro MUI_PAGE_INSTFILES
72   !insertmacro MUI_PAGE_FINISH
73
74   !insertmacro MUI_UNPAGE_WELCOME
75   !insertmacro MUI_UNPAGE_CONFIRM
76   UninstPage custom un.UnPageProfile un.UnPageProfileLeave
77   !insertmacro MUI_UNPAGE_INSTFILES
78   !insertmacro MUI_UNPAGE_FINISH
79
80 ;--------------------------------
81 ;Languages
82
83   !insertmacro MUI_LANGUAGE "English"
84
85 ;--------------------------------
86 ;Install levels
87
88 InstType "Full"    ; 1.
89 InstType "Normal"  ; 2.
90 InstType "Minimal" ; 3.
91
92 ;--------------------------------
93 ;Installer Sections
94
95 Section "XBMC" SecXBMC
96   SetShellVarContext current
97   SectionIn RO
98   SectionIn 1 2 3 #section is in install type Normal/Full/Minimal
99   ;ADD YOUR OWN FILES HERE...
100   SetOutPath "$INSTDIR"
101   File "${xbmc_root}\Xbmc\XBMC.exe"
102   File "${xbmc_root}\Xbmc\copying.txt"
103   File "${xbmc_root}\Xbmc\LICENSE.GPL"
104   File "${xbmc_root}\Xbmc\*.dll"
105   SetOutPath "$INSTDIR\language"
106   File /r /x *.so "${xbmc_root}\Xbmc\language\*.*"
107   SetOutPath "$INSTDIR\media"
108   File /r /x *.so "${xbmc_root}\Xbmc\media\*.*"
109   SetOutPath "$INSTDIR\sounds"
110   File /r /x *.so "${xbmc_root}\Xbmc\sounds\*.*"
111   SetOutPath "$INSTDIR\system"
112
113   RMDir /r $INSTDIR\addons
114   SetOutPath "$INSTDIR\addons"
115   File /r /x skin.touched ${xbmc_root}\Xbmc\addons\*.*
116
117   ; delete system/python if its there
118   IfFileExists $INSTDIR\system\python 0 +2
119     RMDir /r $INSTDIR\system\python
120   
121   File /r /x *.so /x mplayer /x *_d.* /x tcl85g.dll /x tclpip85g.dll /x tk85g.dll "${xbmc_root}\Xbmc\system\*.*"
122   
123   ; delete  msvc?90.dll's in INSTDIR, we use the vcredist installer later
124   Delete "$INSTDIR\msvcr90.dll"
125   Delete "$INSTDIR\msvcp90.dll"
126   
127   ;Turn off overwrite to prevent files in xbmc\userdata\ from being overwritten
128   SetOverwrite off
129   
130   SetOutPath "$INSTDIR\userdata"
131   File /r /x *.so  "${xbmc_root}\Xbmc\userdata\*.*"
132   
133   ;Turn on overwrite for rest of install
134   SetOverwrite on
135
136   ;Store installation folder
137   WriteRegStr HKCU "Software\${APP_NAME}" "" $INSTDIR
138
139   ;Create uninstaller
140   WriteUninstaller "$INSTDIR\Uninstall.exe"
141   
142   !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
143   ;Create shortcuts
144   SetOutPath "$INSTDIR"
145   
146   ; delete old windowed link
147   Delete "$SMPROGRAMS\$StartMenuFolder\XBMC (Windowed).lnk"
148   
149   CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
150   CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" \
151     "" "$INSTDIR\${APP_NAME}.exe" 0 SW_SHOWNORMAL \
152     "" "Start ${APP_NAME}."
153   CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\Uninstall.exe" \
154     "" "$INSTDIR\Uninstall.exe" 0 SW_SHOWNORMAL \
155     "" "Uninstall ${APP_NAME}."
156   
157   WriteINIStr "$SMPROGRAMS\$StartMenuFolder\Visit ${APP_NAME} Online.url" "InternetShortcut" "URL" "http://xbmc.org"
158   !insertmacro MUI_STARTMENU_WRITE_END  
159   
160   ;add entry to add/remove programs
161   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
162                  "DisplayName" "${APP_NAME}"
163   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
164                  "UninstallString" "$INSTDIR\uninstall.exe"
165   WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
166                  "NoModify" 1
167   WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
168                  "NoRepair" 1
169   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
170                  "InstallLocation" "$INSTDIR"
171   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
172                  "DisplayIcon" "$INSTDIR\${APP_NAME}.exe,0"
173   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
174                  "Publisher" "Team XBMC"
175   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
176                  "HelpLink" "http://xbmc.org/support"
177   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
178                  "URLInfoAbout" "http://xbmc.org"
179                  
180 SectionEnd
181
182 SectionGroup "Skins" SecSkins
183 Section "Confluence" SecSkinConfluence
184   SectionIn 1 2 3 #section is in install type Full/Normal/Minimal
185   SectionIn RO
186   SetOutPath "$INSTDIR\addons\skin.confluence\"
187   File /r "${xbmc_root}\Xbmc\addons\skin.confluence\*.*"
188 SectionEnd
189 ;skins.nsi is generated by genNsisIncludes.bat
190 !include /nonfatal "skins.nsi"
191 SectionGroupEnd
192
193 SectionGroup "PVR Addons" SecPvrAddons
194 ;xbmc-pvr-addons.nsi is generated by genNsisIncludes.bat
195 !include /nonfatal "xbmc-pvr-addons.nsi"
196 SectionGroupEnd
197
198 ;--------------------------------
199 ;Descriptions
200
201   ;Language strings
202   LangString DESC_SecXBMC ${LANG_ENGLISH} "${APP_NAME}"
203
204   ;Assign language strings to sections
205   !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
206   !insertmacro MUI_DESCRIPTION_TEXT ${SecXBMC} $(DESC_SecXBMC)
207   !insertmacro MUI_FUNCTION_DESCRIPTION_END
208
209 ;--------------------------------
210 ;Uninstaller Section
211
212 Var UnPageProfileDialog
213 Var UnPageProfileCheckbox
214 Var UnPageProfileCheckbox_State
215 Var UnPageProfileEditBox
216
217 Function un.UnPageProfile
218     !insertmacro MUI_HEADER_TEXT "Uninstall ${APP_NAME}" "Remove ${APP_NAME}'s profile folder from your computer."
219   nsDialogs::Create /NOUNLOAD 1018
220   Pop $UnPageProfileDialog
221
222   ${If} $UnPageProfileDialog == error
223     Abort
224   ${EndIf}
225
226   ${NSD_CreateLabel} 0 0 100% 12u "Do you want to delete the profile folder?"
227   Pop $0
228
229   ${NSD_CreateText} 0 13u 100% 12u "$APPDATA\${APP_NAME}\"
230   Pop $UnPageProfileEditBox
231     SendMessage $UnPageProfileEditBox ${EM_SETREADONLY} 1 0
232
233   ${NSD_CreateLabel} 0 46u 100% 24u "Leave unchecked to keep the profile folder for later use or check to delete the profile folder."
234   Pop $0
235
236   ${NSD_CreateCheckbox} 0 71u 100% 8u "Yes, also delete the profile folder."
237   Pop $UnPageProfileCheckbox
238   
239
240   nsDialogs::Show
241 FunctionEnd
242
243 Function un.UnPageProfileLeave
244 ${NSD_GetState} $UnPageProfileCheckbox $UnPageProfileCheckbox_State
245 FunctionEnd
246
247 Section "Uninstall"
248
249   SetShellVarContext current
250
251   ;ADD YOUR OWN FILES HERE...
252   Delete "$INSTDIR\${APP_NAME}.exe"
253   Delete "$INSTDIR\copying.txt"
254   Delete "$INSTDIR\known_issues.txt"
255   Delete "$INSTDIR\LICENSE.GPL"
256   Delete "$INSTDIR\glew32.dll"
257   Delete "$INSTDIR\SDL.dll"
258   Delete "$INSTDIR\zlib1.dll"
259   Delete "$INSTDIR\xbmc.log"
260   Delete "$INSTDIR\xbmc.old.log"
261   Delete "$INSTDIR\python26.dll"
262   Delete "$INSTDIR\libcdio-*.dll"
263   Delete "$INSTDIR\libiconv-2.dll"
264   RMDir /r "$INSTDIR\language"
265   RMDir /r "$INSTDIR\media"
266   RMDir /r "$INSTDIR\plugins"
267   RMDir /r "$INSTDIR\scripts"
268   RMDir /r "$INSTDIR\skin"
269   RMDir /r "$INSTDIR\sounds"
270   RMDir /r "$INSTDIR\system"
271   RMDir /r "$INSTDIR\visualisations"
272   RMDir /r "$INSTDIR\addons"
273   RMDir /r "$INSTDIR\web"
274   RMDir /r "$INSTDIR\cache"
275
276   Delete "$INSTDIR\Uninstall.exe"
277   
278 ;Uninstall User Data if option is checked, otherwise skip
279   ${If} $UnPageProfileCheckbox_State == ${BST_CHECKED}
280     RMDir /r "$INSTDIR\userdata"  
281     RMDir "$INSTDIR"
282     RMDir /r "$APPDATA\${APP_NAME}\"
283   ${Else}
284 ;Even if userdata is kept in %appdata%\xbmc\userdata, the $INSTDIR\userdata should be cleaned up on uninstall if not used
285 ;If guisettings.xml exists in the XBMC\userdata directory, do not delete XBMC\userdata directory
286 ;If that file does not exists, then delete that folder and $INSTDIR
287     IfFileExists $INSTDIR\userdata\guisettings.xml +3
288       RMDir /r "$INSTDIR\userdata"  
289       RMDir "$INSTDIR"
290   ${EndIf}
291
292   
293   !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
294   Delete "$SMPROGRAMS\$StartMenuFolder\${APP_NAME}.lnk"
295   Delete "$SMPROGRAMS\$StartMenuFolder\XBMC (Portable).lnk"
296   Delete "$SMPROGRAMS\$StartMenuFolder\XBMC (Windowed).lnk"
297   Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall ${APP_NAME}.lnk"
298   Delete "$SMPROGRAMS\$StartMenuFolder\Visit ${APP_NAME} Online.url"
299   RMDir "$SMPROGRAMS\$StartMenuFolder"  
300   DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
301
302   DeleteRegKey /ifempty HKCU "Software\${APP_NAME}"
303
304 SectionEnd
305
306 ;--------------------------------
307 ;vs redist installer Section
308
309 Section "Microsoft Visual C++ 2008/2010 Redistributable Package (x86)" SEC_VCREDIST
310
311   SectionIn 1 2 #section is in install type Full/Normal and when not installed
312   
313   DetailPrint "Running VS Redist Setup..."
314
315   ;vc90 for python
316   SetOutPath "$TEMP\vc2008"
317   File "${xbmc_root}\..\dependencies\vcredist\2008\vcredist_x86.exe"
318   ExecWait '"$TEMP\vc2008\vcredist_x86.exe" /q' $VSRedistSetupError
319   RMDir /r "$TEMP\vc2008"
320   
321   ;vc100
322   SetOutPath "$TEMP\vc2010"
323   File "${xbmc_root}\..\dependencies\vcredist\2010\vcredist_x86.exe"
324   DetailPrint "Running VS Redist Setup..."
325   ExecWait '"$TEMP\vc2010\vcredist_x86.exe" /q' $VSRedistSetupError
326   RMDir /r "$TEMP\vc2010"
327  
328   DetailPrint "Finished VS Redist Setup"
329   SetOutPath "$INSTDIR"
330 SectionEnd
331
332 ;--------------------------------
333 ;DirectX webinstaller Section
334
335 !if "${xbmc_target}" == "dx"
336 !define DXVERSIONDLL "$SYSDIR\D3DX9_43.dll"
337
338 Section "DirectX Install" SEC_DIRECTX
339  
340   SectionIn 1 2 #section is in install type Full/Normal and when not installed
341
342   DetailPrint "Running DirectX Setup..."
343
344   SetOutPath "$TEMP\dxsetup"
345   File "${xbmc_root}\..\dependencies\dxsetup\dsetup32.dll"
346   File "${xbmc_root}\..\dependencies\dxsetup\DSETUP.dll"
347   File "${xbmc_root}\..\dependencies\dxsetup\dxdllreg_x86.cab"
348   File "${xbmc_root}\..\dependencies\dxsetup\DXSETUP.exe"
349   File "${xbmc_root}\..\dependencies\dxsetup\dxupdate.cab"
350   File "${xbmc_root}\..\dependencies\dxsetup\Jun2010_D3DCompiler_43_x86.cab"
351   File "${xbmc_root}\..\dependencies\dxsetup\Jun2010_d3dx9_43_x86.cab"
352   ExecWait '"$TEMP\dxsetup\dxsetup.exe" /silent' $DirectXSetupError
353   RMDir /r "$TEMP\dxsetup"
354   SetOutPath "$INSTDIR"
355
356   DetailPrint "Finished DirectX Setup"
357   
358 SectionEnd
359
360 Section "-Check DirectX installation" SEC_DIRECTXCHECK
361
362   IfFileExists ${DXVERSIONDLL} +2 0
363     MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND "DirectX9 wasn't installed properly.$\nPlease download the DirectX End-User Runtime from Microsoft and install it again."
364
365 SectionEnd
366
367 Function .onInit
368   ${IfNot} ${AtLeastWinVista}
369     MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND "Windows Vista or above required.$\nThis program can not be run on Windows XP"
370     Quit
371   ${EndIf}
372   # set section 'SEC_DIRECTX' as selected and read-only if required dx version not found
373   IfFileExists ${DXVERSIONDLL} +3 0
374   IntOp $0 ${SF_SELECTED} | ${SF_RO}
375   SectionSetFlags ${SEC_DIRECTX} $0
376 FunctionEnd
377 !endif