Skip to content

Commit

Permalink
Fix Windows build with /p:CharacterSet=Unicode
Browse files Browse the repository at this point in the history
Use TCHAR/TEXT macros for strings when interfacing with the Win32 API.
Use native Win32 GetFileAttributes call to check if a file exists. Pass
the layer settings file path around as a std::filesystem::path to avoid
the need for an encoding conversion on Windows.
  • Loading branch information
mikes-lunarg authored and christophe-lunarg committed Aug 31, 2023
1 parent 21bebf6 commit dd26ae7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/layer/layer_settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ LayerSettings::LayerSettings(const char *pLayerName, const VkLayerSettingsCreate
(void)pAllocator;
assert(pLayerName != nullptr);

std::string settings_file = this->FindSettingsFile();
this->ParseSettingsFile(settings_file.c_str());
std::filesystem::path settings_file = this->FindSettingsFile();
this->ParseSettingsFile(settings_file);
}

LayerSettings::~LayerSettings() {}

void LayerSettings::ParseSettingsFile(const char *filename) {
void LayerSettings::ParseSettingsFile(const std::filesystem::path &filename) {
// Extract option = value pairs from a file
std::ifstream file(filename);
if (file.good()) {
Expand All @@ -134,7 +134,7 @@ void LayerSettings::ParseSettingsFile(const char *filename) {
}
}

std::string LayerSettings::FindSettingsFile() {
std::filesystem::path LayerSettings::FindSettingsFile() {
struct stat info;

#if defined(WIN32)
Expand All @@ -145,9 +145,9 @@ std::string LayerSettings::FindSettingsFile() {
const size_t hives_to_check_count = IsHighIntegrity() ? 1 : hives.size(); // Admin checks only the default hive

for (size_t hive_index = 0; hive_index < hives_to_check_count; ++hive_index) {
LSTATUS err = RegOpenKeyEx(hives[hive_index], "Software\\Khronos\\Vulkan\\Settings", 0, KEY_READ, &key);
LSTATUS err = RegOpenKeyEx(hives[hive_index], TEXT("Software\\Khronos\\Vulkan\\Settings"), 0, KEY_READ, &key);
if (err == ERROR_SUCCESS) {
char name[2048];
TCHAR name[2048];
DWORD i = 0, name_size, type, pValues, value_size;
while (ERROR_SUCCESS == RegEnumValue(key, i++, name, &(name_size = sizeof(name)), nullptr, &type,
reinterpret_cast<LPBYTE>(&pValues), &(value_size = sizeof(pValues)))) {
Expand All @@ -157,7 +157,8 @@ std::string LayerSettings::FindSettingsFile() {
}

// Check if this actually points to a file
if ((stat(name, &info) != 0) || !(info.st_mode & S_IFREG)) {
DWORD fileAttrib = GetFileAttributes(name);
if ((fileAttrib == INVALID_FILE_ATTRIBUTES) || (fileAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions src/layer/layer_settings_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include <map>
#include <filesystem>

namespace vl {
class LayerSettings {
Expand Down Expand Up @@ -48,8 +49,8 @@ namespace vl {
std::string last_log_setting;
std::string last_log_message;

std::string FindSettingsFile();
void ParseSettingsFile(const char *filename);
std::filesystem::path FindSettingsFile();
void ParseSettingsFile(const std::filesystem::path &filename);

std::string layer_name;
const VkLayerSettingsCreateInfoEXT *create_info{nullptr};
Expand Down

0 comments on commit dd26ae7

Please sign in to comment.