diff --git a/OptiScaler/Util.cpp b/OptiScaler/Util.cpp index 7ec22a55..67d8e5db 100644 --- a/OptiScaler/Util.cpp +++ b/OptiScaler/Util.cpp @@ -9,126 +9,112 @@ extern HMODULE dllModule; std::filesystem::path Util::DllPath() { - static std::filesystem::path dll; - + static std::filesystem::path dll; - if (dll.empty()) - { - wchar_t dllPath[MAX_PATH]; - GetModuleFileNameW(dllModule, dllPath, MAX_PATH); - dll = std::filesystem::path(dllPath); - LOG_INFO("{0}", wstring_to_string(dll.wstring())); - } + if (dll.empty()) + { + wchar_t dllPath[MAX_PATH]; + GetModuleFileNameW(dllModule, dllPath, MAX_PATH); + dll = std::filesystem::path(dllPath); - return dll; + LOG_INFO("{0}", wstring_to_string(dll.wstring())); + } + + return dll; } -std::optional Util::FontPath() -{ - std::optional result; - - if (!Config::Instance()->IsRunningOnLinux) - { - wchar_t fontPath[MAX_PATH]; - - if (SHGetFolderPath(NULL, CSIDL_FONTS, NULL, 0, fontPath) == S_OK) - result = std::filesystem::path(fontPath); - } - - return result; -} std::optional Util::NvngxPath() { - // Checking _nvngx.dll / nvngx.dll location from registry based on DLSSTweaks - // https://github.com/emoose/DLSSTweaks/blob/7ebf418c79670daad60a079c0e7b84096c6a7037/src/ProxyNvngx.cpp#L303 - LOG_INFO("trying to load nvngx from registry path!"); + // Checking _nvngx.dll / nvngx.dll location from registry based on DLSSTweaks + // https://github.com/emoose/DLSSTweaks/blob/7ebf418c79670daad60a079c0e7b84096c6a7037/src/ProxyNvngx.cpp#L303 + LOG_INFO("trying to load nvngx from registry path!"); - HKEY regNGXCore; - LSTATUS ls; - std::optional result; + HKEY regNGXCore; + LSTATUS ls; + std::optional result; - ls = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services\\nvlddmkm\\NGXCore", 0, KEY_READ, ®NGXCore); + ls = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services\\nvlddmkm\\NGXCore", 0, KEY_READ, ®NGXCore); - if (ls == ERROR_SUCCESS) - { - wchar_t regNGXCorePath[260]; - DWORD NGXCorePathSize = 260; + if (ls == ERROR_SUCCESS) + { + wchar_t regNGXCorePath[260]; + DWORD NGXCorePathSize = 260; - ls = RegQueryValueExW(regNGXCore, L"NGXPath", nullptr, nullptr, (LPBYTE)regNGXCorePath, &NGXCorePathSize); + ls = RegQueryValueExW(regNGXCore, L"NGXPath", nullptr, nullptr, (LPBYTE)regNGXCorePath, &NGXCorePathSize); - if (ls == ERROR_SUCCESS) - { - auto path = std::filesystem::path(regNGXCorePath); - LOG_INFO("nvngx registry path: {0}", path.string()); - return path; - } - } + if (ls == ERROR_SUCCESS) + { + auto path = std::filesystem::path(regNGXCorePath); + LOG_INFO("nvngx registry path: {0}", path.string()); + return path; + } + } - return result; + return result; } double Util::MillisecondsNow() { - static LARGE_INTEGER s_frequency; - static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency); - double milliseconds = 0; + static LARGE_INTEGER s_frequency; + static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency); + double milliseconds = 0; - if (s_use_qpc) - { - LARGE_INTEGER now; - QueryPerformanceCounter(&now); - milliseconds = double(1000.0 * now.QuadPart) / s_frequency.QuadPart; - } - else - { - milliseconds = double(GetTickCount64()); - } + if (s_use_qpc) + { + LARGE_INTEGER now; + QueryPerformanceCounter(&now); + milliseconds = double(1000.0 * now.QuadPart) / s_frequency.QuadPart; + } + else + { + milliseconds = double(GetTickCount64()); + } - return milliseconds; + return milliseconds; } std::filesystem::path Util::ExePath() { - static std::filesystem::path exe; + static std::filesystem::path exe; - if (exe.empty()) - { - wchar_t exePath[MAX_PATH]; - GetModuleFileNameW(nullptr, exePath, MAX_PATH); - exe = std::filesystem::path(exePath); - } + if (exe.empty()) + { + wchar_t exePath[MAX_PATH]; + GetModuleFileNameW(nullptr, exePath, MAX_PATH); + exe = std::filesystem::path(exePath); + } - return exe; + return exe; } static BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam) { - const auto isMainWindow = [handle]() { - return GetWindow(handle, GW_OWNER) == nullptr && IsWindowVisible(handle) && handle != GetConsoleWindow(); - }; + const auto isMainWindow = [handle]() { + return GetWindow(handle, GW_OWNER) == nullptr && IsWindowVisible(handle) && handle != GetConsoleWindow(); + }; - DWORD pID = 0; - GetWindowThreadProcessId(handle, &pID); + DWORD pID = 0; + GetWindowThreadProcessId(handle, &pID); - if (pID != processId || !isMainWindow() || handle == GetConsoleWindow()) - return TRUE; + if (pID != processId || !isMainWindow() || handle == GetConsoleWindow()) + return TRUE; - *reinterpret_cast(lParam) = handle; + *reinterpret_cast(lParam) = handle; - return FALSE; + return FALSE; } HWND Util::GetProcessWindow() { - HWND hwnd = nullptr; - EnumWindows(EnumWindowsCallback, reinterpret_cast(&hwnd)); + HWND hwnd = nullptr; + EnumWindows(EnumWindowsCallback, reinterpret_cast(&hwnd)); - if (hwnd == nullptr) - { - LOG_DEBUG("EnumWindows returned null using GetForegroundWindow()"); - hwnd = GetForegroundWindow(); - } + if (hwnd == nullptr) + { + LOG_DEBUG("EnumWindows returned null using GetForegroundWindow()"); + hwnd = GetForegroundWindow(); + } - return hwnd; + return hwnd; } diff --git a/OptiScaler/Util.h b/OptiScaler/Util.h index fa85c03b..bdfeebda 100644 --- a/OptiScaler/Util.h +++ b/OptiScaler/Util.h @@ -5,7 +5,6 @@ namespace Util { std::filesystem::path ExePath(); std::filesystem::path DllPath(); - std::optional FontPath(); std::optional NvngxPath(); double MillisecondsNow();