2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2021-07-05 02:31:16 +00:00
|
|
|
* Copyright (C) 2002-2021 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-03-01 03:30:19 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-03-01 03:30:19 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 03:30:19 +00:00
|
|
|
*/
|
2009-11-26 03:37:10 +00:00
|
|
|
|
2021-09-03 10:43:33 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#include "common/Pcsx2Defs.h"
|
|
|
|
#include "common/RedtapeWindows.h"
|
|
|
|
#include "common/Exceptions.h"
|
2022-05-18 13:27:23 +00:00
|
|
|
#include "common/StringUtil.h"
|
|
|
|
|
|
|
|
#include "fmt/core.h"
|
2009-07-11 08:31:38 +00:00
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#pragma comment(lib, "User32.lib")
|
2009-03-01 03:30:19 +00:00
|
|
|
|
2021-09-03 06:23:59 +00:00
|
|
|
alignas(16) static LARGE_INTEGER lfreq;
|
2009-03-01 03:30:19 +00:00
|
|
|
|
|
|
|
void InitCPUTicks()
|
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
QueryPerformanceFrequency(&lfreq);
|
2009-03-01 03:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetTickFrequency()
|
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
return lfreq.QuadPart;
|
2009-03-01 03:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetCPUTicks()
|
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
LARGE_INTEGER count;
|
|
|
|
QueryPerformanceCounter(&count);
|
|
|
|
return count.QuadPart;
|
2009-03-01 03:30:19 +00:00
|
|
|
}
|
2009-07-11 08:31:38 +00:00
|
|
|
|
2010-11-23 21:32:52 +00:00
|
|
|
u64 GetPhysicalMemory()
|
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
MEMORYSTATUSEX status;
|
|
|
|
status.dwLength = sizeof(status);
|
|
|
|
GlobalMemoryStatusEx(&status);
|
|
|
|
return status.ullTotalPhys;
|
2010-11-23 21:32:52 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 19:25:17 +00:00
|
|
|
// Calculates the Windows OS Version and processor architecture, and returns it as a
|
2009-11-26 03:37:10 +00:00
|
|
|
// human-readable string. :)
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string GetOSVersionString()
|
2009-07-11 08:31:38 +00:00
|
|
|
{
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string retval;
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-07-06 22:53:34 +00:00
|
|
|
SYSTEM_INFO si;
|
2021-07-06 19:25:17 +00:00
|
|
|
GetNativeSystemInfo(&si);
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-07-06 22:53:34 +00:00
|
|
|
if (!IsWindows8Point1OrGreater())
|
2022-05-18 13:27:23 +00:00
|
|
|
{
|
|
|
|
retval = "Unsupported Operating System!";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retval = "Microsoft ";
|
|
|
|
|
|
|
|
if (IsWindows10OrGreater())
|
|
|
|
retval += IsWindowsServer() ? "Windows Server 2016" : "Windows 10";
|
|
|
|
else // IsWindows8Point1OrGreater()
|
|
|
|
retval += IsWindowsServer() ? "Windows Server 2012 R2" : "Windows 8.1";
|
|
|
|
}
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-07-06 22:53:34 +00:00
|
|
|
return retval;
|
2009-11-26 03:37:10 +00:00
|
|
|
}
|
2010-06-28 18:03:54 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Exception::WinApiError (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
Exception::WinApiError::WinApiError()
|
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
ErrorId = GetLastError();
|
2022-05-18 13:27:23 +00:00
|
|
|
m_message_diag = "Unspecified Windows API error.";
|
2010-06-28 18:03:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string Exception::WinApiError::GetMsgFromWindows() const
|
2010-06-28 18:03:54 +00:00
|
|
|
{
|
2021-07-06 22:53:34 +00:00
|
|
|
if (!ErrorId)
|
2022-05-18 13:27:23 +00:00
|
|
|
return "No valid error number was assigned to this exception!";
|
2010-06-28 18:03:54 +00:00
|
|
|
|
2021-07-06 22:53:34 +00:00
|
|
|
const DWORD BUF_LEN = 2048;
|
2022-05-18 13:27:23 +00:00
|
|
|
wchar_t t_Msg[BUF_LEN];
|
|
|
|
if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorId, 0, t_Msg, BUF_LEN, 0))
|
|
|
|
return fmt::format("Win32 Error #{}: {}", ErrorId, StringUtil::WideStringToUTF8String(t_Msg));
|
2010-06-28 18:03:54 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
return fmt::format("Win32 Error #{} (no text msg available)", ErrorId);
|
2010-06-28 18:03:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string Exception::WinApiError::FormatDisplayMessage() const
|
2010-06-28 18:03:54 +00:00
|
|
|
{
|
2022-05-18 13:27:23 +00:00
|
|
|
return m_message_user + "\n\n" + GetMsgFromWindows();
|
2010-06-28 18:03:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string Exception::WinApiError::FormatDiagnosticMessage() const
|
2010-06-28 18:03:54 +00:00
|
|
|
{
|
2022-05-18 13:27:23 +00:00
|
|
|
return m_message_diag + "\n\t" + GetMsgFromWindows();
|
2010-06-28 18:03:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:08:58 +00:00
|
|
|
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);
|
2015-02-26 02:08:58 +00:00
|
|
|
}
|
2021-09-03 10:43:33 +00:00
|
|
|
#endif
|