xref: /trunk/main/desktop/win32/source/setup/setup_main.cxx (revision 989b13ef2270bbb43d1b5fb03162470a47d7f4cc)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #define  UNICODE    1
28 #define _UNICODE    1
29 
30 #if defined _MSC_VER
31 #pragma warning(push, 1)
32 #endif
33 #include <windows.h>
34 #if defined _MSC_VER
35 #pragma warning(pop)
36 #endif
37 #include <new>
38 
39 #include "setup.hxx"
40 
41 //--------------------------------------------------------------------------
42 
43 void __cdecl newhandler()
44 {
45     throw std::bad_alloc();
46     return;
47 }
48 
49 //--------------------------------------------------------------------------
50 //--------------------------------------------------------------------------
51 //--------------------------------------------------------------------------
52 
53 extern "C" int __stdcall WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
54 {
55     SetupApp *pSetup = new SetupApp();
56 
57     try
58     {
59         if ( ! pSetup->Initialize( hInst ) )
60             throw pSetup->GetError();
61 
62         if ( pSetup->AlreadyRunning() )
63             throw (UINT) ERROR_INSTALL_ALREADY_RUNNING;
64 
65         if ( ! pSetup->ReadProfile() )
66             throw pSetup->GetError();
67 
68         if ( ! pSetup->CheckVersion() )
69             throw pSetup->GetError();
70 
71         if ( ! pSetup->IsAdminInstall() )
72             if ( ! pSetup->GetPatches() )
73                 throw pSetup->GetError();
74 
75         // CheckForUpgrade() has to be called after calling GetPatches()!
76         if ( ! pSetup->CheckForUpgrade() )
77             throw pSetup->GetError();
78 
79         long nLanguage;
80 
81         if ( ! pSetup->ChooseLanguage( nLanguage ) )
82             throw pSetup->GetError();
83 
84         if ( ! pSetup->InstallRuntimes() )
85             throw pSetup->GetError();
86 
87         if ( ! pSetup->Install( nLanguage ) )
88             throw pSetup->GetError();
89     }
90     catch ( std::bad_alloc )
91     {
92         pSetup->DisplayError( ERROR_OUTOFMEMORY );
93     }
94     catch ( UINT nErr )
95     {
96         pSetup->DisplayError( nErr );
97     }
98 
99     int nRet = pSetup->GetError();
100 
101     delete pSetup;
102 
103     return nRet;
104 }
105