/[pcsx2_0.9.7]/trunk/common/src/Utilities/Windows/WinMisc.cpp
ViewVC logotype

Contents of /trunk/common/src/Utilities/Windows/WinMisc.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 7799 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma comment(lib, "User32.lib")
17
18 #include "PrecompiledHeader.h"
19 #include "RedtapeWindows.h"
20
21 #include <ShTypes.h>
22
23 static __aligned16 LARGE_INTEGER lfreq;
24
25 void InitCPUTicks()
26 {
27 QueryPerformanceFrequency( &lfreq );
28 }
29
30 u64 GetTickFrequency()
31 {
32 return lfreq.QuadPart;
33 }
34
35 u64 GetCPUTicks()
36 {
37 LARGE_INTEGER count;
38 QueryPerformanceCounter( &count );
39 return count.QuadPart;
40 }
41
42 u64 GetPhysicalMemory()
43 {
44 MEMORYSTATUSEX status;
45 status.dwLength = sizeof(status);
46 GlobalMemoryStatusEx(&status);
47 return status.ullTotalPhys;
48 }
49
50 // Windows SDK 7 provides this but previous ones do not, so roll our own in those cases:
51 #ifndef VER_SUITE_WH_SERVER
52 # define VER_SUITE_WH_SERVER 0x00008000
53 #endif
54
55 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
56 typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
57
58 // Calculates the Windows OS Version and install information, and returns it as a
59 // human-readable string. :)
60 // (Handy function borrowed from Microsoft's MSDN Online, and reformatted to use wxString.)
61 wxString GetOSVersionString()
62 {
63 wxString retval;
64
65 OSVERSIONINFOEX osvi;
66 SYSTEM_INFO si;
67 PGNSI pGNSI;
68 PGPI pGPI;
69 BOOL bOsVersionInfoEx;
70 DWORD dwType;
71
72 memzero( si );
73 memzero( osvi );
74
75 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
76
77 if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
78 return L"GetVersionEx Error!";
79
80 // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
81
82 pGNSI = (PGNSI) GetProcAddress( GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo" );
83 if(NULL != pGNSI)
84 pGNSI( &si );
85 else
86 GetSystemInfo( &si );
87
88 if ( VER_PLATFORM_WIN32_NT!=osvi.dwPlatformId || osvi.dwMajorVersion <= 4 )
89 return L"Unsupported Operating System!";
90
91 retval += L"Microsoft ";
92
93 // Test for the specific product.
94
95 if ( osvi.dwMajorVersion == 6 )
96 {
97 if( osvi.dwMinorVersion == 0 )
98 retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows Vista " : L"Windows Server 2008 ";
99
100 if ( osvi.dwMinorVersion == 1 )
101 retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows 7 " : L"Windows Server 2008 R2 ";
102
103 pGPI = (PGPI) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
104
105 pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
106
107 switch( dwType )
108 {
109 case PRODUCT_ULTIMATE: retval += L"Ultimate Edition"; break;
110 case PRODUCT_HOME_PREMIUM: retval += L"Home Premium Edition"; break;
111 case PRODUCT_HOME_BASIC: retval += L"Home Basic Edition"; break;
112 case PRODUCT_ENTERPRISE: retval += L"Enterprise Edition"; break;
113 case PRODUCT_BUSINESS: retval += L"Business Edition"; break;
114 case PRODUCT_STARTER: retval += L"Starter Edition"; break;
115 case PRODUCT_CLUSTER_SERVER: retval += L"Cluster Server Edition"; break;
116 case PRODUCT_DATACENTER_SERVER: retval += L"Datacenter Edition"; break;
117 case PRODUCT_DATACENTER_SERVER_CORE: retval += L"Datacenter Edition (core installation)"; break;
118 case PRODUCT_ENTERPRISE_SERVER: retval += L"Enterprise Edition"; break;
119 case PRODUCT_ENTERPRISE_SERVER_CORE: retval += L"Enterprise Edition (core installation)"; break;
120 case PRODUCT_SMALLBUSINESS_SERVER: retval += L"Small Business Server"; break;
121 case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: retval += L"Small Business Server Premium Edition"; break;
122 case PRODUCT_STANDARD_SERVER: retval += L"Standard Edition"; break;
123 case PRODUCT_STANDARD_SERVER_CORE: retval += L"Standard Edition (core installation)"; break;
124 case PRODUCT_WEB_SERVER: retval += L"Web Server Edition"; break;
125 }
126 }
127
128 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
129 {
130 if( GetSystemMetrics(SM_SERVERR2) )
131 retval += L"Windows Server 2003 R2, ";
132 else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
133 retval += L"Windows Storage Server 2003";
134 else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER )
135 retval += L"Windows Home Server";
136 else if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
137 retval += L"Windows XP Professional x64 Edition";
138 else
139 retval += L"Windows Server 2003, ";
140
141 // Test for the server type.
142 if ( osvi.wProductType != VER_NT_WORKSTATION )
143 {
144 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
145 {
146 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
147 retval += L"Datacenter x64 Edition";
148 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
149 retval += L"Enterprise x64 Edition";
150 else
151 retval += L"Standard x64 Edition";
152 }
153
154 else
155 {
156 if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
157 retval += L"Compute Cluster Edition";
158 else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
159 retval += L"Datacenter Edition";
160 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
161 retval += L"Enterprise Edition";
162 else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
163 retval += L"Web Edition";
164 else
165 retval += L"Standard Edition";
166 }
167 }
168 }
169
170 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
171 {
172 retval += L"Windows XP ";
173 retval += ( osvi.wSuiteMask & VER_SUITE_PERSONAL ) ? L"Professional" : L"Home Edition";
174 }
175
176 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
177 {
178 retval += L"Windows 2000 ";
179
180 if ( osvi.wProductType == VER_NT_WORKSTATION )
181 {
182 retval += L"Professional";
183 }
184 else
185 {
186 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
187 retval += L"Datacenter Server";
188 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
189 retval += L"Advanced Server";
190 else
191 retval += L"Server";
192 }
193 }
194
195 // Include service pack (if any) and build number.
196
197 if( _tcslen(osvi.szCSDVersion) > 0 )
198 retval += (wxString)L" " + osvi.szCSDVersion;
199
200 retval += wxsFormat( L" (build %d)", osvi.dwBuildNumber );
201
202 if ( osvi.dwMajorVersion >= 6 )
203 {
204 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
205 retval += L", 64-bit";
206 else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
207 retval += L", 32-bit";
208 }
209
210 return retval;
211 }
212
213 // --------------------------------------------------------------------------------------
214 // Exception::WinApiError (implementations)
215 // --------------------------------------------------------------------------------------
216 Exception::WinApiError::WinApiError()
217 {
218 ErrorId = GetLastError();
219 m_message_diag = L"Unspecified Windows API error.";
220 }
221
222 wxString Exception::WinApiError::GetMsgFromWindows() const
223 {
224 if (!ErrorId) return L"No valid error number was assigned to this exception!";
225
226 const DWORD BUF_LEN = 2048;
227 TCHAR t_Msg[BUF_LEN];
228 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorId, 0, t_Msg, BUF_LEN, 0))
229 return wxsFormat( L"Win32 Error #%d: %s", ErrorId, t_Msg );
230
231 return wxsFormat( L"Win32 Error #%d (no text msg available)", ErrorId );
232 }
233
234 wxString Exception::WinApiError::FormatDisplayMessage() const
235 {
236 return m_message_user + L"\n\n" + GetMsgFromWindows();
237 }
238
239 wxString Exception::WinApiError::FormatDiagnosticMessage() const
240 {
241 return m_message_diag + L"\n\t" + GetMsgFromWindows();
242 }
243

  ViewVC Help
Powered by ViewVC 1.1.22