[FIX]
[odoo/odoo.git] / openerp-server-installer.nsi
1 ##############################################################################
2 #
3 # Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsability of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # garantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 ###############################################################################
26 !ifndef VERSION
27     !error "Do not forget to specify the version of OpenERP - /DVERSION=<VERSION>"
28 !endif 
29
30 ;--------------------------------
31 ;Include Modern UI
32
33 !include "MUI.nsh"
34
35 ;--------------------------------
36 ;General
37
38 ;Name and file
39 Name "OpenERP Server"
40 OutFile "openerp-server-setup-${VERSION}.exe"
41 SetCompressor lzma
42 SetCompress auto
43
44 ;Default installation folder
45 InstallDir "$PROGRAMFILES\OpenERP Server"
46
47 ;Get installation folder from registry if available
48 InstallDirRegKey HKCU "Software\OpenERP Server" ""
49
50 BrandingText "OpenERP Server ${VERSION}"
51
52 ;Vista redirects $SMPROGRAMS to all users without this
53 RequestExecutionLevel admin
54
55 ;--------------------------------
56 ;Variables
57
58 Var MUI_TEMP
59 Var STARTMENU_FOLDER
60
61 ;--------------------------------
62 ;Interface Settings
63
64 !define MUI_ABORTWARNING
65
66 ;--------------------------------
67 ;Pages
68
69 !define MUI_ICON ".\pixmaps\openerp-icon.ico"
70 !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\openerp-intro.bmp"
71 !define MUI_UNWELCOMEFINISHPAGE_BITMAP ".\pixmaps\openerp-intro.bmp"
72 !define MUI_HEADERIMAGE
73 !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
74 !define MUI_HEADER_TRANSPARENT_TEXT ""
75 !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\openerp-slogan.bmp"
76 !define MUI_LICENSEPAGE_TEXT_BOTTOM "Usually, a proprietary license provides with the software: limited number of users, limited in time usage, etc. This Open Source license is the opposite: it garantees you the right to use, copy, study, distribute and modify Open ERP for free."
77
78 !insertmacro MUI_PAGE_WELCOME
79 !insertmacro MUI_PAGE_LICENSE "doc\License.rtf"
80 !insertmacro MUI_PAGE_DIRECTORY
81
82 ;Start Menu Folder Page Configuration
83 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
84 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\OpenERP Server"
85 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "OpenERP Server"
86
87 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
88
89 !insertmacro MUI_PAGE_INSTFILES
90
91 !define MUI_FINISHPAGE_NOAUTOCLOSE
92 !define MUI_FINISHPAGE_RUN
93 !define MUI_FINISHPAGE_RUN_CHECKED
94 !define MUI_FINISHPAGE_RUN_TEXT "Start OpenERP Server"
95 !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
96 !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
97 !define MUI_FINISHPAGE_SHOWREADME $INSTDIR\README.txt
98 !insertmacro MUI_PAGE_FINISH
99
100
101 !insertmacro MUI_UNPAGE_WELCOME
102 !insertmacro MUI_UNPAGE_CONFIRM
103 !insertmacro MUI_UNPAGE_INSTFILES
104
105 ;--------------------------------
106 ;Languages
107
108 !insertmacro MUI_LANGUAGE "English"
109
110 !macro CreateInternetShortcut FILENAME URL
111         WriteINIStr "${FILENAME}.url" "InternetShortcut" "URL" "${URL}"
112 !macroend
113
114 ;--------------------------------
115 ;Installer Sections
116 Function .onInit 
117     ClearErrors
118     ReadRegStr $0 HKCU "Software\OpenERP Server" ""
119     IfErrors DoInstall 0
120         MessageBox MB_OK "Can not install the Open ERP Server because a previous installation already exists on this system. Please uninstall your current installation and relaunch this setup wizard."
121         Quit
122     DoInstall:
123 FunctionEnd
124
125 Section "OpenERP Server" SecOpenERPServer
126     nsExec::Exec "net stop openerp-service"
127     sleep 2
128
129     SetOutPath "$INSTDIR"
130
131     ;ADD YOUR OWN FILES HERE...
132     File /r "dist\*"
133
134     SetOutPath "$INSTDIR\service"
135     File /r "win32\dist\*"
136     File "win32\start.bat"
137     File "win32\stop.bat"
138
139     ;Store installation folder
140     WriteRegStr HKCU "Software\OpenERP Server" "" $INSTDIR
141
142     ;Create uninstaller
143     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenERP Server" "DisplayName" "OpenERP Server ${VERSION}"
144     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenERP Server" "UninstallString" "$INSTDIR\Uninstall.exe"
145     WriteUninstaller "$INSTDIR\Uninstall.exe"
146
147     !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
148         ;Create shortcuts
149         CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
150         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\OpenERP Server.lnk" "$INSTDIR\openerp-server.exe"
151         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Start service.lnk" "$INSTDIR\service\start.bat"
152         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Stop service.lnk" "$INSTDIR\service\stop.bat"
153         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Edit config.lnk" "notepad.exe" "$INSTDIR\openerp-server.conf"
154         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\View log.lnk" "notepad.exe" "$INSTDIR\openerp-server.log"
155         CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\uninstall.exe"
156         !insertmacro CreateInternetShortcut "$SMPROGRAMS\$STARTMENU_FOLDER\Forum" "http://www.openerp.com/forum"
157         !insertmacro CreateInternetShortcut "$SMPROGRAMS\$STARTMENU_FOLDER\Translation" "https://translations.launchpad.net/openobject"
158     !insertmacro MUI_STARTMENU_WRITE_END
159
160     nsExec::Exec '"$INSTDIR\openerp-server.exe" --stop-after-init --logfile "$INSTDIR\openerp-server.log" -s'
161     nsExec::Exec '"$INSTDIR\service\OpenERPServerService.exe" -auto -install'
162
163 SectionEnd
164
165 ;Descriptions
166
167 ;Language strings
168 LangString DESC_SecOpenERPServer ${LANG_ENGLISH} "OpenERP Server."
169
170 ;Assign language strings to sections
171 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
172     !insertmacro MUI_DESCRIPTION_TEXT ${SecOpenERPServer} $(DESC_SecOpenERPServer)
173 !insertmacro MUI_FUNCTION_DESCRIPTION_END
174  
175 ;--------------------------------
176 ;Uninstaller Section
177
178 Section "Uninstall"
179     nsExec::Exec "net stop openerp-service"
180     sleep 2
181     nsExec::Exec '"$INSTDIR\service\OpenERPServerService.exe" -remove'
182     sleep 2
183
184     RMDIR /r "$INSTDIR" 
185     !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
186
187     Delete "$SMPROGRAMS\$MUI_TEMP\Forum.url"
188     Delete "$SMPROGRAMS\$MUI_TEMP\Translation.url"
189     Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
190     Delete "$SMPROGRAMS\$MUI_TEMP\OpenERP Server.lnk"
191     Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
192     Delete "$SMPROGRAMS\$MUI_TEMP\Start service.lnk"
193     Delete "$SMPROGRAMS\$MUI_TEMP\Stop service.lnk"
194     Delete "$SMPROGRAMS\$MUI_TEMP\Edit config.lnk"
195     Delete "$SMPROGRAMS\$MUI_TEMP\View log.lnk"
196
197     ;Delete empty start menu parent diretories
198     StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
199  
200     startMenuDeleteLoop:
201         ClearErrors
202         RMDir $MUI_TEMP
203         GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
204
205         IfErrors startMenuDeleteLoopDone
206
207         StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
208
209     startMenuDeleteLoopDone:
210
211         DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenERP Server"
212         DeleteRegKey /ifempty HKCU "Software\OpenERP Server"
213
214 SectionEnd
215
216 Function LaunchLink
217     nsExec::Exec "net start openerp-service"
218 FunctionEnd
219