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 #if defined _MSC_VER
28 #pragma warning(push, 1)
29 #endif
30 #include <windows.h>
31 #if defined _MSC_VER
32 #pragma warning(pop)
33 #endif
34 #include <new>
35
36 #include "setup_main.hxx"
37
38 //--------------------------------------------------------------------------
39
newhandler()40 void __cdecl newhandler()
41 {
42 throw std::bad_alloc();
43 return;
44 }
45
46 //--------------------------------------------------------------------------
47
SetupApp()48 SetupApp::SetupApp()
49 {
50 m_uiRet = ERROR_SUCCESS;
51
52 // Get OS version
53 OSVERSIONINFO sInfoOS;
54
55 ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
56 sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
57
58 GetVersionEx( &sInfoOS );
59
60 m_nOSVersion = sInfoOS.dwMajorVersion;
61 m_nMinorVersion = sInfoOS.dwMinorVersion;
62 m_bIsWin9x = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
63 m_bNeedReboot = false;
64 m_bAdministrative = false;
65 }
66
67 //--------------------------------------------------------------------------
68
~SetupApp()69 SetupApp::~SetupApp()
70 {
71 }
72
73 //--------------------------------------------------------------------------
74 //--------------------------------------------------------------------------
75 //--------------------------------------------------------------------------
76
WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int)77 extern "C" int __stdcall WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
78 {
79 // Get OS version
80 OSVERSIONINFO sInfoOS;
81
82 ZeroMemory( &sInfoOS, sizeof(OSVERSIONINFO) );
83 sInfoOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
84
85 GetVersionEx( &sInfoOS );
86
87 boolean bIsWin9x = ( VER_PLATFORM_WIN32_NT != sInfoOS.dwPlatformId );
88
89 SetupApp *pSetup;
90
91 if ( bIsWin9x )
92 pSetup = Create_SetupAppA();
93 else
94 pSetup = Create_SetupAppW();
95
96 try
97 {
98 if ( ! pSetup->Initialize( hInst ) )
99 throw pSetup->GetError();
100
101 if ( pSetup->AlreadyRunning() )
102 throw (UINT) ERROR_INSTALL_ALREADY_RUNNING;
103
104 if ( ! pSetup->ReadProfile() )
105 throw pSetup->GetError();
106
107 if ( ! pSetup->CheckVersion() )
108 throw pSetup->GetError();
109
110 if ( ! pSetup->IsAdminInstall() )
111 if ( ! pSetup->GetPatches() )
112 throw pSetup->GetError();
113
114 // CheckForUpgrade() has to be called after calling GetPatches()!
115 if ( ! pSetup->CheckForUpgrade() )
116 throw pSetup->GetError();
117
118 long nLanguage;
119
120 if ( ! pSetup->ChooseLanguage( nLanguage ) )
121 throw pSetup->GetError();
122
123 if ( ! pSetup->InstallRuntimes() )
124 throw pSetup->GetError();
125
126 if ( ! pSetup->Install( nLanguage ) )
127 throw pSetup->GetError();
128 }
129 catch ( std::bad_alloc )
130 {
131 pSetup->DisplayError( ERROR_OUTOFMEMORY );
132 }
133 catch ( UINT nErr )
134 {
135 pSetup->DisplayError( nErr );
136 }
137
138 int nRet = pSetup->GetError();
139
140 delete pSetup;
141
142 return nRet;
143 }
144