Enhance Abseil integration and improve Windows font loading functionality
- Added additional Abseil flags modules to the CMake configuration for better support. - Refactored Windows-specific font loading code to avoid namespace conflicts by using the `::` prefix for Windows API calls. - Improved error handling and ensured proper memory management when retrieving font paths from the Windows registry.
This commit is contained in:
@@ -28,6 +28,14 @@ set(
|
||||
absl::strings
|
||||
absl::str_format
|
||||
absl::flags
|
||||
absl::flags_parse
|
||||
absl::flags_usage
|
||||
absl::flags_commandlineflag
|
||||
absl::flags_marshalling
|
||||
absl::flags_private_handle_accessor
|
||||
absl::flags_program_name
|
||||
absl::flags_config
|
||||
absl::flags_reflection
|
||||
absl::status
|
||||
absl::statusor
|
||||
absl::examine_stack
|
||||
@@ -42,15 +50,13 @@ set(
|
||||
absl::synchronization
|
||||
absl::time
|
||||
absl::symbolize
|
||||
absl::flags_commandlineflag
|
||||
absl::flags_marshalling
|
||||
absl::flags_private_handle_accessor
|
||||
absl::flags_program_name
|
||||
absl::flags_config
|
||||
absl::flags_reflection
|
||||
absl::container_memory
|
||||
absl::memory
|
||||
absl::utility
|
||||
absl::strings_internal
|
||||
absl::str_format_internal
|
||||
absl::flags_internal
|
||||
absl::container_internal
|
||||
)
|
||||
|
||||
# Add int128 only on non-Windows platforms to avoid C++23 deprecation issues
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#
|
||||
|
||||
|
||||
#include "absl/status/status.h"
|
||||
@@ -134,8 +131,11 @@ absl::Status ReloadPackageFont(const FontConfig& config) {
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Include Windows headers first to avoid namespace conflicts
|
||||
#include <Windows.h>
|
||||
#include <ShlObj.h>
|
||||
#include <combaseapi.h>
|
||||
#include <shlobj_core.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
@@ -155,11 +155,11 @@ namespace {
|
||||
// Helper function to get Windows fonts directory
|
||||
std::string GetWindowsFontsDirectory() {
|
||||
wchar_t* fontsPath = nullptr;
|
||||
HRESULT hr = SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &fontsPath);
|
||||
::HRESULT hr = ::SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &fontsPath);
|
||||
|
||||
if (SUCCEEDED(hr) && fontsPath) {
|
||||
if (::SUCCEEDED(hr) && fontsPath) {
|
||||
std::string result = WideToUtf8(fontsPath) + "\\";
|
||||
CoTaskMemFree(fontsPath);
|
||||
::CoTaskMemFree(fontsPath);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace {
|
||||
|
||||
// Check if file exists and is accessible
|
||||
bool FontFileExists(const std::string& path) {
|
||||
return GetFileAttributesA(path.c_str()) != INVALID_FILE_ATTRIBUTES;
|
||||
return ::GetFileAttributesA(path.c_str()) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,20 +234,20 @@ void LoadSystemFonts() {
|
||||
}
|
||||
|
||||
// Try to load additional fonts from registry (safer approach)
|
||||
HKEY hKey = nullptr;
|
||||
LONG result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
|
||||
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
|
||||
0, KEY_READ, &hKey);
|
||||
::HKEY hKey = nullptr;
|
||||
::LONG result = ::RegOpenKeyExA(HKEY_LOCAL_MACHINE,
|
||||
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
|
||||
0, KEY_READ, &hKey);
|
||||
|
||||
if (result == ERROR_SUCCESS && hKey) {
|
||||
DWORD valueCount = 0;
|
||||
DWORD maxValueNameSize = 0;
|
||||
DWORD maxValueDataSize = 0;
|
||||
::DWORD valueCount = 0;
|
||||
::DWORD maxValueNameSize = 0;
|
||||
::DWORD maxValueDataSize = 0;
|
||||
|
||||
// Get registry info
|
||||
result = RegQueryInfoKeyA(hKey, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
nullptr, &valueCount, &maxValueNameSize,
|
||||
&maxValueDataSize, nullptr, nullptr);
|
||||
result = ::RegQueryInfoKeyA(hKey, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
nullptr, &valueCount, &maxValueNameSize,
|
||||
&maxValueDataSize, nullptr, nullptr);
|
||||
|
||||
if (result == ERROR_SUCCESS && valueCount > 0) {
|
||||
// Allocate buffers with proper size limits
|
||||
@@ -257,21 +257,21 @@ void LoadSystemFonts() {
|
||||
if (maxDataSize > 4096) maxDataSize = 4096;
|
||||
|
||||
std::vector<char> valueName(maxNameSize);
|
||||
std::vector<BYTE> valueData(maxDataSize);
|
||||
std::vector<::BYTE> valueData(maxDataSize);
|
||||
|
||||
// Enumerate font entries (limit to prevent excessive loading)
|
||||
DWORD maxFontsToLoad = valueCount;
|
||||
::DWORD maxFontsToLoad = valueCount;
|
||||
if (maxFontsToLoad > 50) maxFontsToLoad = 50;
|
||||
|
||||
for (DWORD i = 0; i < maxFontsToLoad; i++) {
|
||||
DWORD valueNameSize = static_cast<DWORD>(maxNameSize);
|
||||
DWORD valueDataSize = static_cast<DWORD>(maxDataSize);
|
||||
DWORD valueType = 0;
|
||||
for (::DWORD i = 0; i < maxFontsToLoad; i++) {
|
||||
::DWORD valueNameSize = static_cast<::DWORD>(maxNameSize);
|
||||
::DWORD valueDataSize = static_cast<::DWORD>(maxDataSize);
|
||||
::DWORD valueType = 0;
|
||||
|
||||
result = RegEnumValueA(hKey, i, valueName.data(), &valueNameSize,
|
||||
nullptr, &valueType, valueData.data(), &valueDataSize);
|
||||
result = ::RegEnumValueA(hKey, i, valueName.data(), &valueNameSize,
|
||||
nullptr, &valueType, valueData.data(), &valueDataSize);
|
||||
|
||||
if (result == ERROR_SUCCESS && valueType == REG_SZ && valueDataSize > 0) {
|
||||
if (result == ERROR_SUCCESS && valueType == ::REG_SZ && valueDataSize > 0) {
|
||||
// Ensure null termination
|
||||
valueName[valueNameSize] = '\0';
|
||||
valueData[valueDataSize] = '\0';
|
||||
@@ -304,7 +304,7 @@ void LoadSystemFonts() {
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
::RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -434,7 +434,11 @@ class ModernCLI {
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C" int SDL_main(int argc, char* argv[]) {
|
||||
#else
|
||||
int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
absl::SetProgramUsageMessage(
|
||||
"z3ed - Yet Another Zelda3 Editor CLI Tool\n"
|
||||
"\n"
|
||||
|
||||
@@ -24,7 +24,11 @@ DEFINE_FLAG(std::string, length, "", "The length of the data to read.");
|
||||
DEFINE_FLAG(std::string, file_size, "", "The size of the file to expand to.");
|
||||
DEFINE_FLAG(std::string, dest_rom, "", "The destination ROM file.");
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C" int SDL_main(int argc, char *argv[]) {
|
||||
#else
|
||||
int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
yaze::util::FlagParser flag_parser(yaze::util::global_flag_registry());
|
||||
RETURN_IF_EXCEPTION(flag_parser.Parse(argc, argv));
|
||||
yaze::cli::ShowMain();
|
||||
|
||||
Reference in New Issue
Block a user