Fixed Fonts. (#2698)

Added Windows Build Info to log.
This commit is contained in:
gir489 2024-02-10 14:50:27 -05:00 committed by GitHub
parent 0afcb00ec7
commit 0275821f95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 0 deletions

View File

@ -73,6 +73,60 @@ namespace big
}
return patched;
}
std::string ReadRegistryKeySZ(HKEY hKeyParent, std::string subkey, std::string valueName)
{
HKEY hKey;
char value[1024];
DWORD value_length = 1024;
LONG ret = RegOpenKeyEx(hKeyParent, subkey.c_str(), 0, KEY_READ, &hKey);
if (ret != ERROR_SUCCESS)
{
LOG(INFO) << "Unable to read registry key " << subkey;
return "";
}
ret = RegQueryValueEx(hKey, valueName.c_str(), NULL, NULL, (LPBYTE)&value, &value_length);
RegCloseKey(hKey);
if (ret != ERROR_SUCCESS)
{
LOG(INFO) << "Unable to read registry key " << valueName;
return "";
}
return std::string(value);
}
DWORD ReadRegistryKeyDWORD(HKEY hKeyParent, std::string subkey, std::string valueName)
{
HKEY hKey;
DWORD value;
DWORD value_length = sizeof(DWORD);
LONG ret = RegOpenKeyEx(hKeyParent, subkey.c_str(), 0, KEY_READ, &hKey);
if (ret != ERROR_SUCCESS)
{
LOG(INFO) << "Unable to read registry key " << subkey;
return NULL;
}
ret = RegQueryValueEx(hKey, valueName.c_str(), NULL, NULL, (LPBYTE)&value, &value_length);
RegCloseKey(hKey);
if (ret != ERROR_SUCCESS)
{
LOG(INFO) << "Unable to read registry key " << valueName;
return NULL;
}
return value;
}
LPSTR GetWindowsVersion()
{
typedef LPWSTR(WINAPI * BFS)(LPCWSTR);
LPWSTR UTF16 = BFS(GetProcAddress(LoadLibrary("winbrand.dll"), "BrandingFormatString"))(L"%WINDOWS_LONG%");
int BufferSize = WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, NULL, 0, NULL, NULL);
LPSTR UTF8 = new char[BufferSize];
WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, UTF8, BufferSize, NULL, NULL);
// BrandingFormatString requires a GlobalFree.
GlobalFree(UTF16);
return UTF8;
}
}
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
@ -104,6 +158,11 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
LOG(INFO) << "Yim's Menu Initializing";
LOGF(INFO, "Git Info\n\tBranch:\t{}\n\tHash:\t{}\n\tDate:\t{}", version::GIT_BRANCH, version::GIT_SHA1, version::GIT_DATE);
auto display_version = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "DisplayVersion");
auto current_build = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuild");
auto UBR = ReadRegistryKeyDWORD(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "UBR");
LOG(INFO) << GetWindowsVersion() << " Version " << display_version << " (OS Build " << current_build << "." << UBR << ")";
#ifndef NDEBUG
LOG(WARNING) << "Debug Build. Switch to RelWithDebInfo or Release Build for a more stable experience";
#endif

View File

@ -39,6 +39,11 @@ namespace big
file font_file_path = windows_fonts.get_file("./msyh.ttc");
if (!font_file_path.exists())
font_file_path = windows_fonts.get_file("./msyh.ttf");
if (!font_file_path.exists())
{
LOG(WARNING) << "Failed to find msyh font, falling back to Arial!";
font_file_path = windows_fonts.get_file("./arial.ttf");
}
auto font_file = std::ifstream(font_file_path.get_path(), std::ios::binary | std::ios::ate);
const auto font_data_size = static_cast<int>(font_file.tellg());
const auto font_data = std::make_unique<uint8_t[]>(font_data_size);