Apply 1695492: install start menu shortcuts for all users on Win32. Patch by Dmitriy...
[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\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   !include "images\images.nsh"
61   
62   SetOutPath "$INSTDIR\share\pixmaps"
63   !include "images\icons.nsh"
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 ".sifz" "" "Synfig.Composition"
95         WriteRegStr HKCR ".sifz" "Content Type" "image/x-sifz"
96         WriteRegStr HKCR ".sifz" "PerceivedType" "image"
97
98         WriteRegStr HKCR "Synfig.Composition" "" "Synfig Composition File"
99         WriteRegStr HKCR "Synfig.Composition\DefaultIcon" "" "$INSTDIR\share\pixmaps\sif_icon.ico"
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   SetShellVarContext All
112   CreateDirectory "$SMPROGRAMS\Voria"
113   CreateShortCut "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" "" "$INSTDIR\uninstall-@PACKAGE_TARNAME@.exe" 0
114   CreateShortCut "$SMPROGRAMS\Voria\Synfig Studio.lnk" "$INSTDIR\bin\synfigstudio.exe" "" "$INSTDIR\share\pixmaps\synfig_icon.ico" 0
115   
116 SectionEnd
117
118 ;--------------------------------
119
120 ; Uninstaller
121
122 Section "Uninstall"
123   
124         DeleteRegKey HKCR "Synfig.Composition\shell\open\command" 
125         DeleteRegKey HKCR "Synfig.Composition\DefaultIcon" 
126         DeleteRegKey HKCR "Synfig.Composition\shell"
127         DeleteRegKey HKCR "Synfig.Composition" 
128         DeleteRegKey HKCR ".sif"
129         DeleteRegKey HKCR ".sifz"
130   
131   ; Remove registry keys
132   DeleteRegKey HKLM "${PRODUCT_REG_KEY}"
133   DeleteRegKey HKLM "${PRODUCT_UNINSTALL_KEY}"
134
135   ; Remove images and icons
136   !include "images\unimages.nsh"
137   !include "images\unicons.nsh"
138   RMDir "$INSTDIR\share\pixmaps"
139   RMDir "$INSTDIR\share"
140
141   ; Remove files and uninstaller
142         Delete "$INSTDIR\${PRODUCT_UNINSTALL_EXE}"
143   Delete $INSTDIR\bin\synfigstudio.exe
144   Delete $INSTDIR\bin\libsynfigapp-0.dll
145   RMDir "$INSTDIR\bin"
146
147   ; Remove shortcuts, if any
148   SetShellVarContext All
149   Delete "$SMPROGRAMS\Voria\Uninstall Synfig Studio.lnk"
150   Delete "$SMPROGRAMS\Voria\Synfig Studio.lnk"
151
152   ; Remove directories used
153   RMDir "$SMPROGRAMS\Voria"
154   RMDir "$INSTDIR"
155
156         System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
157 SectionEnd
158
159 Function .onInit
160         ; Get installer location
161         ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
162 ;       IfErrors 0 +2
163 ;       ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
164         
165         StrCmp $R0 "" done
166
167         ; Get current installed version
168         ReadRegStr $R1 HKLM "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
169 ;       IfErrors 0 +2
170 ;       ReadRegStr $R1 HKCU "${PRODUCT_UNINSTALL_KEY}" "DisplayVersion"
171
172 ;  StrCmp $R1 ${PRODUCT_VERSION} done
173
174         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
175
176         ; Run the uninstaller
177         
178         ClearErrors
179         ; CopyFiles "$R0" $TEMP
180         ExecWait '$R0 _?=$INSTDIR'
181         IfErrors no_remove_uninstaller
182         Delete $R0
183         RMDir $INSTDIR
184
185 no_remove_uninstaller:
186 ;    Delete "$TEMP\$R0"
187         
188     ; Check that the user completed the uninstallation by examining the registry
189     ReadRegStr $R0 HKLM "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
190         StrCmp $R0 "" done abortInstall
191         ReadRegStr $R0 HKCU "${PRODUCT_UNINSTALL_KEY}" "UninstallString"
192         StrCmp $R0 "" done abortInstall
193
194 abortInstall:
195     MessageBox MB_OK|MB_ICONEXCLAMATION "Unable to uninstall previous version of @PACKAGE_NAME@"
196     Abort
197
198 done:
199     BringToFront
200
201 FunctionEnd