1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2722ceddSAndrew Rist  * distributed with this work for additional information
6*2722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2722ceddSAndrew Rist  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist  *
13*2722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist  * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2722ceddSAndrew Rist  * specific language governing permissions and limitations
18*2722ceddSAndrew Rist  * under the License.
19*2722ceddSAndrew Rist  *
20*2722ceddSAndrew Rist  *************************************************************/
21*2722ceddSAndrew Rist 
22*2722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #if defined _MSC_VER
28cdf0e10cSrcweir #pragma warning(push, 1)
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <windows.h>
31cdf0e10cSrcweir #if defined _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <new>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "setup_main.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //--------------------------------------------------------------------------
39cdf0e10cSrcweir 
newhandler()40cdf0e10cSrcweir void __cdecl newhandler()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     throw std::bad_alloc();
43cdf0e10cSrcweir     return;
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //--------------------------------------------------------------------------
47cdf0e10cSrcweir 
SetupApp()48cdf0e10cSrcweir SetupApp::SetupApp()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     m_uiRet         = ERROR_SUCCESS;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     // Get OS version
53cdf0e10cSrcweir     OSVERSIONINFO sInfoOS;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
56cdf0e10cSrcweir     sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     GetVersionEx( &sInfoOS );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     m_nOSVersion    = sInfoOS.dwMajorVersion;
61cdf0e10cSrcweir     m_nMinorVersion = sInfoOS.dwMinorVersion;
62cdf0e10cSrcweir     m_bIsWin9x      = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
63cdf0e10cSrcweir     m_bNeedReboot   = false;
64cdf0e10cSrcweir     m_bAdministrative = false;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //--------------------------------------------------------------------------
68cdf0e10cSrcweir 
~SetupApp()69cdf0e10cSrcweir SetupApp::~SetupApp()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //--------------------------------------------------------------------------
74cdf0e10cSrcweir //--------------------------------------------------------------------------
75cdf0e10cSrcweir //--------------------------------------------------------------------------
76cdf0e10cSrcweir 
WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int)77cdf0e10cSrcweir extern "C" int __stdcall WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     // Get OS version
80cdf0e10cSrcweir     OSVERSIONINFO sInfoOS;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
83cdf0e10cSrcweir     sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     GetVersionEx( &sInfoOS );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     boolean bIsWin9x = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     SetupApp *pSetup;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     if ( bIsWin9x )
92cdf0e10cSrcweir         pSetup = Create_SetupAppA();
93cdf0e10cSrcweir     else
94cdf0e10cSrcweir         pSetup = Create_SetupAppW();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     try
97cdf0e10cSrcweir     {
98cdf0e10cSrcweir         if ( ! pSetup->Initialize( hInst ) )
99cdf0e10cSrcweir             throw pSetup->GetError();
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         if ( pSetup->AlreadyRunning() )
102cdf0e10cSrcweir             throw (UINT) ERROR_INSTALL_ALREADY_RUNNING;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         if ( ! pSetup->ReadProfile() )
105cdf0e10cSrcweir             throw pSetup->GetError();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         if ( ! pSetup->CheckVersion() )
108cdf0e10cSrcweir             throw pSetup->GetError();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         if ( ! pSetup->IsAdminInstall() )
111cdf0e10cSrcweir             if ( ! pSetup->GetPatches() )
112cdf0e10cSrcweir                 throw pSetup->GetError();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         // CheckForUpgrade() has to be called after calling GetPatches()!
115cdf0e10cSrcweir         if ( ! pSetup->CheckForUpgrade() )
116cdf0e10cSrcweir             throw pSetup->GetError();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         long nLanguage;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         if ( ! pSetup->ChooseLanguage( nLanguage ) )
121cdf0e10cSrcweir             throw pSetup->GetError();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         if ( ! pSetup->InstallRuntimes() )
124cdf0e10cSrcweir             throw pSetup->GetError();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         if ( ! pSetup->Install( nLanguage ) )
127cdf0e10cSrcweir             throw pSetup->GetError();
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir     catch ( std::bad_alloc )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         pSetup->DisplayError( ERROR_OUTOFMEMORY );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     catch ( UINT nErr )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         pSetup->DisplayError( nErr );
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     int nRet = pSetup->GetError();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     delete pSetup;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     return nRet;
143cdf0e10cSrcweir }
144