1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #if defined _MSC_VER
32 #pragma warning(push, 1)
33 #endif
34 #include <windows.h>
35 #if defined _MSC_VER
36 #pragma warning(pop)
37 #endif
38 #include <new>
39 
40 #include "setup_main.hxx"
41 
42 //--------------------------------------------------------------------------
43 
44 void __cdecl newhandler()
45 {
46     throw std::bad_alloc();
47     return;
48 }
49 
50 //--------------------------------------------------------------------------
51 
52 SetupApp::SetupApp()
53 {
54     m_uiRet         = ERROR_SUCCESS;
55 
56     // Get OS version
57     OSVERSIONINFO sInfoOS;
58 
59     ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
60     sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
61 
62     GetVersionEx( &sInfoOS );
63 
64     m_nOSVersion    = sInfoOS.dwMajorVersion;
65     m_nMinorVersion = sInfoOS.dwMinorVersion;
66     m_bIsWin9x      = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
67     m_bNeedReboot   = false;
68     m_bAdministrative = false;
69 }
70 
71 //--------------------------------------------------------------------------
72 
73 SetupApp::~SetupApp()
74 {
75 }
76 
77 //--------------------------------------------------------------------------
78 //--------------------------------------------------------------------------
79 //--------------------------------------------------------------------------
80 
81 extern "C" int __stdcall WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
82 {
83     // Get OS version
84     OSVERSIONINFO sInfoOS;
85 
86     ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
87     sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
88 
89     GetVersionEx( &sInfoOS );
90 
91     boolean bIsWin9x = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
92 
93     SetupApp *pSetup;
94 
95     if ( bIsWin9x )
96         pSetup = Create_SetupAppA();
97     else
98         pSetup = Create_SetupAppW();
99 
100     try
101     {
102         if ( ! pSetup->Initialize( hInst ) )
103             throw pSetup->GetError();
104 
105         if ( pSetup->AlreadyRunning() )
106             throw (UINT) ERROR_INSTALL_ALREADY_RUNNING;
107 
108         if ( ! pSetup->ReadProfile() )
109             throw pSetup->GetError();
110 
111         if ( ! pSetup->CheckVersion() )
112             throw pSetup->GetError();
113 
114         if ( ! pSetup->IsAdminInstall() )
115             if ( ! pSetup->GetPatches() )
116                 throw pSetup->GetError();
117 
118         // CheckForUpgrade() has to be called after calling GetPatches()!
119         if ( ! pSetup->CheckForUpgrade() )
120             throw pSetup->GetError();
121 
122         long nLanguage;
123 
124         if ( ! pSetup->ChooseLanguage( nLanguage ) )
125             throw pSetup->GetError();
126 
127         if ( ! pSetup->InstallRuntimes() )
128             throw pSetup->GetError();
129 
130         if ( ! pSetup->Install( nLanguage ) )
131             throw pSetup->GetError();
132     }
133     catch ( std::bad_alloc )
134     {
135         pSetup->DisplayError( ERROR_OUTOFMEMORY );
136     }
137     catch ( UINT nErr )
138     {
139         pSetup->DisplayError( nErr );
140     }
141 
142     int nRet = pSetup->GetError();
143 
144     delete pSetup;
145 
146     return nRet;
147 }
148