Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_05 / synfig-studio / win32inst.nsi.in
1 ; example2.nsi
2 ;
3 ; This script is based on example1.nsi, but it remember the directory, 
4 ; has uninstall support and (optionally) installs start menu shortcuts.
5 ;
6 ; It will install makensisw.exe into a directory that the user selects,
7
8 !include "MUI.nsh"
9
10 ;--------------------------------
11
12 ; The name of the installer
13 Name "@PACKAGE_NAME@ @PACKAGE_VERSION@"
14
15 ; The file to write
16 OutFile "@PACKAGE_TARNAME@-@PACKAGE_VERSION@.exe"
17
18 ; The default installation directory
19 InstallDir $PROGRAMFILES\Synfig
20
21 ; Registry key to check for directory (so if you install again, it will 
22 ; overwrite the old one automatically)
23 InstallDirRegKey HKLM "Software\Voria_@PACKAGE_TARNAME@" "Install_Dir"
24
25 !define MUI_ABORTWARNING
26
27 !define SHCNE_ASSOCCHANGED 0x8000000
28 !define SHCNF_IDLIST 0
29
30 !define PRODUCT_REG_KEY "Software\@PACKAGE_TARNAME@\@API_VERSION@"
31 !define PRODUCT_UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PACKAGE_TARNAME@"
32 !define PRODUCT_UNINSTALL_EXE "uninstall-@PACKAGE_TARNAME@.exe"
33
34 ;--------------------------------
35
36 !define MUI_WELCOMEFINISHPAGE_BITMAP ".\images\installer_logo.bmp"
37
38 ; Pages
39
40 !insertmacro MUI_PAGE_WELCOME
41 ;!insertmacro MUI_PAGE_LICENSE "@srcdir@\alphalicense.txt"
42 !insertmacro MUI_PAGE_LICENSE "@srcdir@\COPYING"
43 !insertmacro MUI_PAGE_COMPONENTS
44 !insertmacro MUI_PAGE_DIRECTORY
45 !insertmacro MUI_PAGE_INSTFILES
46
47 !insertmacro MUI_UNPAGE_CONFIRM
48 !insertmacro MUI_UNPAGE_INSTFILES
49
50 !insertmacro MUI_LANGUAGE "English"
51
52 ;--------------------------------
53
54 ; The stuff to install
55 Section "Synfig Studio"
56
57   SectionIn RO
58   
59   SetOutPath "$INSTDIR\share\pixmaps"
60   File "images\*.png"
61   
62   SetOutPath "$INSTDIR\share"
63   File "images\*.ico"
64
65   SetOutPath "$INSTDIR\bin"
66   File "src\synfigapp\.libs\libsynfigapp-0.dll"
67   File "src\gtkmm\.libs\synfigstudio.exe"
68
69         FileOpen $0 $PROFILE\.gtkrc-2.0 a
70         FileSeek $0 0 END
71         FileWrite $0 "gtk-toolbar-style = 0"
72         FileWriteByte $0 "13"
73         FileWriteByte $0 "10"
74         FileWrite $0 'gtk-theme-name = "Default"'
75         FileWriteByte $0 "13"
76         FileWriteByte $0 "10"   
77         FileClose $0
78
79   WriteRegStr HKLM "${PRODUCT_REG_KEY}" "Path" "$INSTDIR"
80   WriteRegStr HKLM "${PRODUCT_REG_KEY}" "Version" "@PRODUCT_VERSION@"
81   
82   ; Write the uninstall keys for Windows
83   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayName" "@PACKAGE_NAME@"
84   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion" "@PACKAGE_VERSION@"
85   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\${PRODUCT_UNINSTALL_EXE}"'
86   WriteRegDWORD HKLM "${PRODUCT_UNINSTALL_KEY}" "NoModify" 1
87   WriteRegDWORD HKLM "${PRODUCT_UNINSTALL_KEY}" "NoRepair" 1
88
89
90         WriteRegStr HKCR ".sif" "" "Synfig.Composition"
91         WriteRegStr HKCR ".sif" "Content Type" "image/x-sif"
92         WriteRegStr HKCR ".sif" "PerceivedType" "image"
93
94         WriteRegStr HKCR ".sif.gz" "" "Synfig.Composition"
95         WriteRegStr HKCR ".sif.gz" "Content Type" "image/x-sifz"
96         WriteRegStr HKCR ".sif.gz" "PerceivedType" "image"
97
98         WriteRegStr HKCR "Synfig.Composition" "" "Synfig Composition File"
99         WriteRegStr HKCR "Synfig.Composition\DefaultIcon" "" "$INSTDIR\bin\synfigstudio.exe;1"
100         WriteRegStr HKCR "Synfig.Composition\shell" "" "open"
101         WriteRegStr HKCR "Synfig.Composition\shell\open\command" "" '$INSTDIR\bin\synfigstudio.exe "%1"'
102         
103         System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
104   WriteUninstaller "${PRODUCT_UNINSTALL_EXE}"
105 SectionEnd
106
107
108 ; Optional section (can be disabled by the user)
109 Section "Start Menu Shortcuts"
110
111   CreateDirectory "$SMPROGRAMS\Voria"
112   CreateShortCut "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" "" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" 0
113   CreateShortCut "$SMPROGRAMS\Voria\Synfig Studio.lnk" "$INSTDIR\bin\synfigstudio.exe" "" "$INSTDIR\bin\synfigstudio.exe" 0
114   
115 SectionEnd
116
117 ;--------------------------------
118
119 ; Uninstaller
120
121 Section "Uninstall"
122   
123         DeleteRegKey HKCR "Synfig.Composition\shell\open\command" 
124         DeleteRegKey HKCR "Synfig.Composition\DefaultIcon" 
125         DeleteRegKey HKCR "Synfig.Composition\shell"
126         DeleteRegKey HKCR "Synfig.Composition" 
127         DeleteRegKey HKCR ".sif"
128         DeleteRegKey HKCR ".sif.gz"
129   
130   ; Remove registry keys
131   DeleteRegKey HKLM "${PRODUCT_REG_KEY}"
132   DeleteRegKey HKLM "${PRODUCT_UNINSTALL_KEY}"
133
134   ; Remove files and uninstaller
135         Delete "$INSTDIR\${PRODUCT_UNINSTALL_EXE}"
136   Delete $INSTDIR\bin\synfigstudio.exe
137   Delete $INSTDIR\bin\libsynfigapp-0.dll
138   RMDir $INSTDIR\bin
139
140   ; Remove shortcuts, if any
141   Delete "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk"
142   Delete "$SMPROGRAMS\Voria\Synfig Studio.lnk"
143
144   ; Remove directories used
145   RMDir "$SMPROGRAMS\Voria"
146   RMDir "$INSTDIR"
147
148         System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
149 SectionEnd
150
151 Function .onInit
152         ; Get installer location
153         ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
154 ;       IfErrors 0 +2
155 ;       ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
156         
157         StrCmp $R0 "" done
158
159         ; Get current installed version
160         ReadRegStr $R1 HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
161 ;       IfErrors 0 +2
162 ;       ReadRegStr $R1 HKCU "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
163
164 ;  StrCmp $R1 ${PRODUCT_VERSION} done
165
166         MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "A previous version of @PACKAGE_NAME@ appears to be installed. Would you like to uninstall it first?" IDNO done IDCANCEL abortInstall
167
168         ; Run the uninstaller
169         
170         ClearErrors
171         ; CopyFiles "$R0" $TEMP
172         ExecWait '$R0 _?=$INSTDIR'
173         IfErrors no_remove_uninstaller
174         Delete $R0
175         RMDir $INSTDIR
176
177 no_remove_uninstaller:
178 ;    Delete "$TEMP\$R0"
179         
180     ; Check that the user completed the uninstallation by examining the registry
181     ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
182         StrCmp $R0 "" done abortInstall
183         ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
184         StrCmp $R0 "" done abortInstall
185
186 abortInstall:
187     MessageBox MB_OK|MB_ICONEXCLAMATION "Unable to uninstall previous version of @PACKAGE_NAME@"
188     Abort
189
190 done:
191     BringToFront
192
193 FunctionEnd