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