Use #defined constants for converting between different units.
[synfig.git] / synfig-studio / trunk / 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 !define MUI_ABORTWARNING
22
23 !define SHCNE_ASSOCCHANGED 0x8000000
24 !define SHCNF_IDLIST 0
25
26 !define PRODUCT_REG_KEY "Software\@PACKAGE_TARNAME@\@API_VERSION@"
27 !define PRODUCT_UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PACKAGE_TARNAME@"
28 !define PRODUCT_UNINSTALL_EXE "uninstall-@PACKAGE_TARNAME@.exe"
29
30 ;--------------------------------
31
32 !define MUI_WELCOMEFINISHPAGE_BITMAP ".\images\installer_logo.bmp"
33
34 ; Pages
35
36 !insertmacro MUI_PAGE_WELCOME
37 ;!insertmacro MUI_PAGE_LICENSE "@srcdir@\alphalicense.txt"
38 !insertmacro MUI_PAGE_LICENSE "@srcdir@\COPYING"
39 !insertmacro MUI_PAGE_COMPONENTS
40 !insertmacro MUI_PAGE_DIRECTORY
41 !insertmacro MUI_PAGE_INSTFILES
42
43 !insertmacro MUI_UNPAGE_CONFIRM
44 !insertmacro MUI_UNPAGE_INSTFILES
45
46 !insertmacro MUI_LANGUAGE "English"
47
48 ;--------------------------------
49
50 ; The stuff to install
51 Section "Synfig Studio"
52
53   SectionIn RO
54   
55   SetOutPath "$INSTDIR\share\pixmaps"
56   !include "images\images.nsh"
57   
58   SetOutPath "$INSTDIR\share\pixmaps"
59   !include "images\icons.nsh"
60
61   SetOutPath "$INSTDIR\bin"
62   File "src\synfigapp\.libs\libsynfigapp-0.dll"
63   File "src\gtkmm\.libs\synfigstudio.exe"
64
65         FileOpen $0 $PROFILE\.gtkrc-2.0 a
66         FileSeek $0 0 END
67         FileWrite $0 "gtk-toolbar-style = 0"
68         FileWriteByte $0 "13"
69         FileWriteByte $0 "10"
70         FileWrite $0 'gtk-theme-name = "Default"'
71         FileWriteByte $0 "13"
72         FileWriteByte $0 "10"   
73         FileClose $0
74
75   WriteRegStr HKLM "${PRODUCT_REG_KEY}" "Path" "$INSTDIR"
76   WriteRegStr HKLM "${PRODUCT_REG_KEY}" "Version" "@PACKAGE_VERSION@"
77   
78   ; Write the uninstall keys for Windows
79   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayName" "@PACKAGE_NAME@"
80   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion" "@PACKAGE_VERSION@"
81   WriteRegStr HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\${PRODUCT_UNINSTALL_EXE}"'
82   WriteRegDWORD HKLM "${PRODUCT_UNINSTALL_KEY}" "NoModify" 1
83   WriteRegDWORD HKLM "${PRODUCT_UNINSTALL_KEY}" "NoRepair" 1
84
85
86         WriteRegStr HKCR ".sif" "" "Synfig.Composition"
87         WriteRegStr HKCR ".sif" "Content Type" "image/x-sif"
88         WriteRegStr HKCR ".sif" "PerceivedType" "image"
89
90         WriteRegStr HKCR ".sifz" "" "Synfig.Composition"
91         WriteRegStr HKCR ".sifz" "Content Type" "image/x-sifz"
92         WriteRegStr HKCR ".sifz" "PerceivedType" "image"
93
94         WriteRegStr HKCR "Synfig.Composition" "" "Synfig Composition File"
95         WriteRegStr HKCR "Synfig.Composition\DefaultIcon" "" "$INSTDIR\share\pixmaps\sif_icon.ico"
96         WriteRegStr HKCR "Synfig.Composition\shell" "" "open"
97         WriteRegStr HKCR "Synfig.Composition\shell\open\command" "" '$INSTDIR\bin\synfigstudio.exe "%1"'
98         
99         System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
100   WriteUninstaller "${PRODUCT_UNINSTALL_EXE}"
101 SectionEnd
102
103
104 ; Optional section (can be disabled by the user)
105 Section "Start Menu Shortcuts"
106
107   SetShellVarContext All
108   CreateDirectory "$SMPROGRAMS\Voria"
109   CreateShortCut "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" "" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" 0
110   CreateShortCut "$SMPROGRAMS\Voria\Synfig Studio.lnk" "$INSTDIR\bin\synfigstudio.exe" "" "$INSTDIR\share\pixmaps\synfig_icon.ico" 0
111   
112 SectionEnd
113
114 ;--------------------------------
115
116 ; Uninstaller
117
118 Section "Uninstall"
119   
120         DeleteRegKey HKCR "Synfig.Composition\shell\open\command" 
121         DeleteRegKey HKCR "Synfig.Composition\DefaultIcon" 
122         DeleteRegKey HKCR "Synfig.Composition\shell"
123         DeleteRegKey HKCR "Synfig.Composition" 
124         DeleteRegKey HKCR ".sif"
125         DeleteRegKey HKCR ".sifz"
126   
127   ; Remove registry keys
128   DeleteRegKey HKLM "${PRODUCT_REG_KEY}"
129   DeleteRegKey HKLM "${PRODUCT_UNINSTALL_KEY}"
130
131   ; Remove images and icons
132   !include "images\unimages.nsh"
133   !include "images\unicons.nsh"
134   RMDir "$INSTDIR\share\pixmaps"
135   RMDir "$INSTDIR\share"
136
137   ; Remove files and uninstaller
138         Delete "$INSTDIR\${PRODUCT_UNINSTALL_EXE}"
139   Delete $INSTDIR\bin\synfigstudio.exe
140   Delete $INSTDIR\bin\libsynfigapp-0.dll
141   RMDir "$INSTDIR\bin"
142
143   ; Remove shortcuts, if any
144   SetShellVarContext All
145   Delete "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk"
146   Delete "$SMPROGRAMS\Voria\Synfig Studio.lnk"
147
148   ; Remove directories used
149   RMDir "$SMPROGRAMS\Voria"
150   RMDir "$INSTDIR"
151
152         System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
153 SectionEnd
154
155 Function .onInit
156         ; Get installer location
157         ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
158 ;       IfErrors 0 +2
159 ;       ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
160         
161         StrCmp $R0 "" done
162
163         ; Get current installed version
164         ReadRegStr $R1 HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
165 ;       IfErrors 0 +2
166 ;       ReadRegStr $R1 HKCU "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
167
168 ;  StrCmp $R1 ${PRODUCT_VERSION} done
169
170         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
171
172         ; Run the uninstaller
173         
174         ClearErrors
175         ; CopyFiles "$R0" $TEMP
176         ExecWait '$R0 _?=$INSTDIR'
177         IfErrors no_remove_uninstaller
178         Delete $R0
179         RMDir $INSTDIR
180
181 no_remove_uninstaller:
182 ;    Delete "$TEMP\$R0"
183         
184     ; Check that the user completed the uninstallation by examining the registry
185     ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
186         StrCmp $R0 "" done abortInstall
187         ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
188         StrCmp $R0 "" done abortInstall
189
190 abortInstall:
191     MessageBox MB_OK|MB_ICONEXCLAMATION "Unable to uninstall previous version of @PACKAGE_NAME@"
192     Abort
193
194 done:
195     BringToFront
196
197 FunctionEnd