Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,43 +1769,44 @@ void CCore::OnPostColorFilterRender()

void CCore::ApplyCoreInitSettings()
{
#if (_WIN32_WINNT >= _WIN32_WINNT_LONGHORN) // Windows Vista
bool bValue;
CVARS_GET("process_dpi_aware", bValue);
#if (_WIN32_WINNT >= _WIN32_WINNT_LONGHORN)
const auto aware = CVARS_GET_VALUE<bool>("process_dpi_aware");

if (bValue)
{
// Minimum supported client for the function below is Windows Vista
// See also: https://technet.microsoft.com/en-us/evalcenter/dn469266(v=vs.90)
if (aware)
SetProcessDPIAware();
}
#endif

if (int revision = GetApplicationSettingInt("reset-settings-revision"); revision < 21486)
{
// Force users with default skin to the 2023 version by replacing "Default" with "Default 2023".
// The GUI skin "Default 2023" was introduced in commit 2d9e03324b07e355031ecb3263477477f1a91399.
std::string currentSkinName;
CVARS_GET("current_skin", currentSkinName);
const auto revision = GetApplicationSettingInt("reset-settings-revision");

if (currentSkinName == "Default")
{
CVARS_SET("current_skin", "Default 2023");
}
if (revision >= 21486)
return;

SetApplicationSettingInt("reset-settings-revision", 21486);
}
const auto skin = CVARS_GET_VALUE<std::string>("current_skin");

if (skin == "Default")
CVARS_SET("current_skin", "Default 2023");

// Set process settings
HANDLE currProc = GetCurrentProcess();
SetApplicationSettingInt("reset-settings-revision", 21486);

// Process priority
int PriorityClassList[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS};
SetPriorityClass(currProc, PriorityClassList[CVARS_GET_VALUE<int>("process_priority") % 3]);
const auto process = GetCurrentProcess();
const int priorities[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS};
const auto priority = CVARS_GET_VALUE<int>("process_priority") % 3;

SetPriorityClass(process, priorities[priority]);

const auto affinity = CVARS_GET_VALUE<bool>("process_cpu_affinity");

if (!affinity)
return;

DWORD_PTR mask;
DWORD_PTR sys;
const auto result = GetProcessAffinityMask(process, &mask, &sys);

if (!result)
return;

// Process CPU affinity
if (CVARS_GET_VALUE<bool>("process_cpu_affinity"))
SetProcessAffinityMask(currProc, 1 << 0);
SetProcessAffinityMask(process, mask & ~1);
}

//
Expand Down
44 changes: 28 additions & 16 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3242,17 +3242,23 @@ void CSettings::LoadData()
CVARS_GET("process_cpu_affinity", bVar);
m_pProcessAffinityCheckbox->SetSelected(bVar);

DWORD_PTR affinityMask = 0;
if (bVar)
affinityMask = 1 << 0; // CPU 0 only
DWORD_PTR mask;
DWORD_PTR sys;

const auto process = GetCurrentProcess();
const auto result = GetProcessAffinityMask(process, &mask, &sys);

if (bVar && result)
{
SetProcessAffinityMask(process, mask & ~1);
}
else
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
SYSTEM_INFO info;

affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default)
GetSystemInfo(&info);
SetProcessAffinityMask(process, (1 << info.dwNumberOfProcessors) - 1);
}
SetProcessAffinityMask(GetCurrentProcess(), affinityMask);

// Update build type
CVARS_GET("update_build_type", iVar);
Expand Down Expand Up @@ -3651,20 +3657,26 @@ void CSettings::SaveData()
CScreenShot::SetPhotoSavingInsideDocuments(photoSaving);

// Process CPU Affinity
bool cpuAffinity = m_pProcessAffinityCheckbox->GetSelected();
CVARS_SET("process_cpu_affinity", cpuAffinity);
const auto affinity = m_pProcessAffinityCheckbox->GetSelected();
CVARS_SET("process_cpu_affinity", affinity);

DWORD_PTR affinityMask = 0;
if (cpuAffinity)
affinityMask = 1 << 0; // CPU 0 only
DWORD_PTR mask;
DWORD_PTR sys;

const auto process = GetCurrentProcess();
const auto result = GetProcessAffinityMask(process, &mask, &sys);

if (affinity && result)
{
SetProcessAffinityMask(process, mask & ~1);
}
else
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
SYSTEM_INFO info;

affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default)
GetSystemInfo(&info);
SetProcessAffinityMask(process, (1 << info.dwNumberOfProcessors) - 1);
}
SetProcessAffinityMask(GetCurrentProcess(), affinityMask);

// Debug setting
if (CGUIListItem* pSelected = m_pDebugSettingCombo->GetSelectedItem())
Expand Down
Loading