pcsx2/common/Windows/WinMisc.cpp

120 lines
3.2 KiB
C++
Raw Normal View History

/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
2021-09-03 10:43:33 +00:00
#if defined(_WIN32)
2021-09-01 20:31:46 +00:00
#include <wx/string.h>
#include "common/Pcsx2Defs.h"
#include "common/RedtapeWindows.h"
#include "common/Exceptions.h"
#include "common/Dependencies.h"
2021-09-01 20:31:46 +00:00
#pragma comment(lib, "User32.lib")
alignas(16) static LARGE_INTEGER lfreq;
void InitCPUTicks()
{
2021-07-06 22:53:34 +00:00
QueryPerformanceFrequency(&lfreq);
}
u64 GetTickFrequency()
{
2021-07-06 22:53:34 +00:00
return lfreq.QuadPart;
}
u64 GetCPUTicks()
{
2021-07-06 22:53:34 +00:00
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
return count.QuadPart;
}
u64 GetPhysicalMemory()
{
2021-07-06 22:53:34 +00:00
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return status.ullTotalPhys;
}
// Calculates the Windows OS Version and processor architecture, and returns it as a
// human-readable string. :)
wxString GetOSVersionString()
{
2021-07-06 22:53:34 +00:00
wxString retval;
2021-07-06 22:53:34 +00:00
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
2021-07-06 22:53:34 +00:00
if (!IsWindows8Point1OrGreater())
return L"Unsupported Operating System!";
2021-07-06 22:53:34 +00:00
retval += L"Microsoft ";
2021-07-06 22:53:34 +00:00
if (IsWindows10OrGreater())
retval += IsWindowsServer() ? L"Windows Server 2016" : L"Windows 10";
else // IsWindows8Point1OrGreater()
retval += IsWindowsServer() ? L"Windows Server 2012 R2" : L"Windows 8.1";
2021-07-06 22:53:34 +00:00
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
retval += L", 64-bit";
else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
retval += L", 32-bit";
2021-07-06 22:53:34 +00:00
return retval;
}
// --------------------------------------------------------------------------------------
// Exception::WinApiError (implementations)
// --------------------------------------------------------------------------------------
Exception::WinApiError::WinApiError()
{
2021-07-06 22:53:34 +00:00
ErrorId = GetLastError();
m_message_diag = L"Unspecified Windows API error.";
}
wxString Exception::WinApiError::GetMsgFromWindows() const
{
2021-07-06 22:53:34 +00:00
if (!ErrorId)
return L"No valid error number was assigned to this exception!";
2021-07-06 22:53:34 +00:00
const DWORD BUF_LEN = 2048;
TCHAR t_Msg[BUF_LEN];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorId, 0, t_Msg, BUF_LEN, 0))
return wxsFormat(L"Win32 Error #%d: %s", ErrorId, t_Msg);
2021-07-06 22:53:34 +00:00
return wxsFormat(L"Win32 Error #%d (no text msg available)", ErrorId);
}
wxString Exception::WinApiError::FormatDisplayMessage() const
{
2021-07-06 22:53:34 +00:00
return m_message_user + L"\n\n" + GetMsgFromWindows();
}
wxString Exception::WinApiError::FormatDiagnosticMessage() const
{
2021-07-06 22:53:34 +00:00
return m_message_diag + L"\n\t" + GetMsgFromWindows();
}
void ScreensaverAllow(bool allow)
{
2021-07-06 22:53:34 +00:00
EXECUTION_STATE flags = ES_CONTINUOUS;
if (!allow)
flags |= ES_DISPLAY_REQUIRED;
SetThreadExecutionState(flags);
}
2021-09-03 10:43:33 +00:00
#endif