The usual windows packaging stuff
[tabakrolletjie.git] / packaging / tabakrolletjie.nsi
1 ; Compile with ./scripts/makensis ./scripts/tabakrolletjie.nsi .
2 ; You'll need to have previously run wine-py2exe
3
4   !include "MUI.nsh"
5
6 ; Application Details
7
8   !define WS_VERSION "0.0.0" ; set by makensis scripts
9   !define WS_UNPACK "tabakrolletjie-${WS_VERSION}"
10   !define DIST_FOLDER "../dist"
11
12   Name "Attack of the Giant Space Mould"
13   OutFile "${DIST_FOLDER}\tabakrolletjie-${WS_VERSION}.exe"
14   InstallDir "$PROGRAMFILES\Attack_of_the_Giant_Space_Mould-${WS_VERSION}"
15
16 ; Interface Settings
17
18   !define MUI_ABORTWARNING
19
20   !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\arrow-install.ico"
21   !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\arrow-uninstall.ico"
22
23   !define MUI_HEADERIMAGE
24   !define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
25   !define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-uninstall.bmp"
26
27 ; Dependencies
28
29   !define COMBINED_LICENSE "../LICENSE.txt"
30   !define WS_PY2EXE_ZIP "tabakrolletjie-${WS_VERSION}.zip"
31   !define WS_ICON "../data/images/icons/tabakrolletjie_icon.ico"
32   !define WS_WINDOWS_ICON "data\images\icons\tabakrolletjie_icon.ico"
33   !define VCREDIST "vcredist_x86.exe"
34   !define VCREDIST_KEY "{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}"
35   !define UNINSTALLER "Uninstaller.exe"
36
37 ; Pages
38
39   !insertmacro MUI_PAGE_LICENSE "${COMBINED_LICENSE}"
40   !insertmacro MUI_PAGE_DIRECTORY
41   !insertmacro MUI_PAGE_INSTFILES
42
43   !insertmacro MUI_UNPAGE_CONFIRM
44   !insertmacro MUI_UNPAGE_INSTFILES
45
46 ; Languages
47
48   !insertmacro MUI_LANGUAGE "English"
49
50 ; Other Stuff
51
52   Icon "${WS_ICON}"
53   SetCompress off ; all the big stuff is already compressed
54
55 ; Installer Sections
56
57 Section "vcredist"
58
59   SetOutPath "$INSTDIR"
60   File "${DIST_FOLDER}\${VCREDIST}"
61    ; Check if it's already installed by checking for the uninstall key
62    ; Idea and key value to check taken post and comments at:
63    ; http://blogs.msdn.com/b/astebner/archive/2009/01/29/9384143.aspx
64
65    ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VCREDIST_KEY}" UninstallString
66    ; NSIS docs say if the key doesn't exist, we get an error and an empty string
67    IfErrors install done
68
69 install:
70    ; Runs install with progress bar and no cancel button
71    ; Details taken from
72    ; http://blogs.msdn.com/b/astebner/archive/2010/10/18/9513328.aspx
73
74    DetailPrint "Installing required MS runtime libraries"
75    ExecWait "$INSTDIR/${VCREDIST} /qb!"
76
77 done:
78
79    DetailPrint "MS runtime libraries already installed, skipping"
80
81 SectionEnd
82
83 Section "Attack of the Giant Space Mould"
84   SetOutPath "$INSTDIR"
85
86   WriteUninstaller "$INSTDIR\${UNINSTALLER}"
87
88   File "${DIST_FOLDER}\${WS_PY2EXE_ZIP}"
89   File "${WS_ICON}"
90
91   ZipDLL::extractall "$INSTDIR\${WS_PY2EXE_ZIP}" "$INSTDIR"
92   Delete "$INSTDIR\${WS_PY2EXE_ZIP}"
93
94   CreateDirectory "$SMPROGRAMS\Attack of the Giant Space Mould"
95
96   # link.lnk target.exe
97   #   parameters icon.file icon_index_number start_options
98   #   keyboard_shortcut description
99
100   CreateShortCut "$SMPROGRAMS\Attack of the Giant Space Mould\Attack of the Giant Space Mould ${WS_VERSION}.lnk" "$INSTDIR\${WS_UNPACK}\tabakrolletjie.exe" \
101      "" "$INSTDIR\${WS_UNPACK}\${WS_WINDOWS_ICON}" "" SW_SHOWNORMAL \
102      "" "Attack of the Giant Space Mould"
103
104   CreateShortCut "$SMPROGRAMS\Attack of the Giant Space Mould\Uninstall Attack of the Giant Space Mould ${WS_VERSION}.lnk" "$INSTDIR\${UNINSTALLER}" \
105      "" "" "" SW_SHOWNORMAL \
106      "" "Uninstall Attack of the Giant Space Mould"
107
108 SectionEnd
109
110 UninstallText "This will uninstall Attack of the Giant Space Mould ${WS_VERSION}."
111 UninstallIcon "${WS_ICON}"
112
113 Section "Uninstall"
114   ; Delete files not deleted during install
115
116   Delete "$INSTDIR\${WS_ICON}"
117
118   ; Remove py2exe folder
119   RMDir /r /REBOOTOK "$INSTDIR\${WS_UNPACK}"
120
121   ; Remove shortcut links
122   Delete "$SMPROGRAMS\Attack of the Giant Space Mould\Attack of the Giant Space Mould ${WS_VERSION}.lnk"
123   Delete "$SMPROGRAMS\Attack of the Giant Space Mould\Uninstall Attack of the Giant Space Mould ${WS_VERSION}.lnk"
124
125   ; Remove shortcut folder if no links left
126   IfFileExists "$SMPROGRAMS\Attack of the Giant Space Mould\*.lnk" shortcuts_exist 0
127     RMDir /REBOOTOK "$SMPROGRAMS\Attack of the Giant Space Mould"
128   shortcuts_exist:
129
130   ; Final Clean up (no point doing this while the uninstall is incomplete)
131   RMDir /r /REBOOTOK $INSTDIR
132
133   ; Offer to reboot if needed
134   IfRebootFlag 0 noreboot
135     MessageBox MB_YESNO "A reboot is required to finish the uninstallation. Do you wish to reboot now?" IDNO noreboot
136     Reboot
137   noreboot:
138
139   ; TODO: We don't touch the vcredist stuff, since we can't tell a) if we were
140   ; the ones who installed it and b) if anything else needs it. This may cause
141   ; cruft on the users system, so should we tell the user?
142
143 SectionEnd