From 6c1ea7edd545eaedf9c26043fcaddbfca03ff2ea Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Wed, 22 May 2024 05:29:20 +0300 Subject: [PATCH] solve compile error due to usage of microsoft-specific constructor when building on win with msys2 --- dll/base.cpp | 2 +- dll/dll/common_includes.h | 3 +++ dll/local_storage.cpp | 8 ++++---- dll/settings_parser.cpp | 28 ++++++++++++++-------------- dll/steam_apps.cpp | 2 +- premake5.lua | 4 ++++ 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/dll/base.cpp b/dll/base.cpp index 589842e1..b85d5573 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -273,7 +273,7 @@ bool file_exists_(const std::string &full_path) if (_wstat(utf8_decode(full_path).c_str(), &buffer) != 0) return false; - if ( buffer.st_mode & _S_IFDIR) + if ( buffer.st_mode & S_IFDIR) return false; #else struct stat buffer{}; diff --git a/dll/dll/common_includes.h b/dll/dll/common_includes.h index 177e259e..9dd2f027 100644 --- a/dll/dll/common_includes.h +++ b/dll/dll/common_includes.h @@ -90,6 +90,8 @@ // we need this for BCryptGenRandom() in base.cpp #include + // we need non-standard S_IFDIR for Windows + #include #define MSG_NOSIGNAL 0 @@ -226,6 +228,7 @@ static inline void reset_LastError() // function entry #define PRINT_DEBUG_ENTRY() PRINT_DEBUG("") #define PRINT_DEBUG_TODO() PRINT_DEBUG("// TODO") +#define PRINT_DEBUG_GNU_WIN() PRINT_DEBUG("GNU/Win") // Emulator includes // add them here after the inline functions definitions diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 48312f38..161d1496 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -574,7 +574,7 @@ int Local_Storage::store_file_data(std::string folder, std::string file, const c create_directory(folder + file_folder); std::ofstream myfile; - myfile.open(utf8_decode(folder + file), std::ios::binary | std::ios::out); + myfile.open(std::filesystem::u8path(folder + file), std::ios::binary | std::ios::out); if (!myfile.is_open()) return -1; myfile.write(data, length); int position = myfile.tellp(); @@ -658,7 +658,7 @@ int Local_Storage::store_data_settings(std::string file, const char *data, unsig int Local_Storage::get_file_data(const std::string &full_path, char *data, unsigned int max_length, unsigned int offset) { std::ifstream myfile{}; - myfile.open(utf8_decode(full_path), std::ios::binary | std::ios::in); + myfile.open(std::filesystem::u8path(full_path), std::ios::binary | std::ios::in); if (!myfile.is_open()) return -1; myfile.seekg (offset, std::ios::beg); @@ -803,7 +803,7 @@ bool Local_Storage::update_save_filenames(std::string folder) bool Local_Storage::load_json(std::string full_path, nlohmann::json& json) { - std::ifstream inventory_file(utf8_decode(full_path)); + std::ifstream inventory_file(std::filesystem::u8path(full_path)); // If there is a file and we opened it if (inventory_file) { inventory_file.seekg(0, std::ios::end); @@ -851,7 +851,7 @@ bool Local_Storage::write_json_file(std::string folder, std::string const&file, create_directory(inv_path); - std::ofstream inventory_file(utf8_decode(full_path), std::ios::trunc | std::ios::out); + std::ofstream inventory_file(std::filesystem::u8path(full_path), std::ios::trunc | std::ios::out); if (inventory_file) { inventory_file << std::setw(2) << json; return true; diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 2b6de0de..8e189823 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -139,7 +139,7 @@ Overlay_Appearance::NotificationPosition Overlay_Appearance::translate_notificat static void load_custom_broadcasts(const std::string &base_path, std::set &custom_broadcasts) { const std::string broadcasts_filepath(base_path + "custom_broadcasts.txt"); - std::ifstream broadcasts_file(utf8_decode(broadcasts_filepath)); + std::ifstream broadcasts_file(std::filesystem::u8path(broadcasts_filepath)); if (broadcasts_file.is_open()) { common_helpers::consume_bom(broadcasts_file); PRINT_DEBUG("loading broadcasts file '%s'", broadcasts_filepath.c_str()); @@ -158,7 +158,7 @@ static void load_custom_broadcasts(const std::string &base_path, std::set, std::string>> button_pairs; @@ -619,7 +619,7 @@ static std::set parse_supported_languages(class Local_Storage *loca std::set supported_languages{}; std::string lang_config_path = Local_Storage::get_game_settings_path() + "supported_languages.txt"; - std::ifstream input( utf8_decode(lang_config_path) ); + std::ifstream input( std::filesystem::u8path(lang_config_path) ); std::string first_language{}; if (input.is_open()) { @@ -720,7 +720,7 @@ static void parse_app_paths(class Settings *settings_client, Settings *settings_ static void parse_leaderboards(class Settings *settings_client, class Settings *settings_server) { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "leaderboards.txt"; - std::ifstream input( utf8_decode(dlc_config_path) ); + std::ifstream input( std::filesystem::u8path(dlc_config_path) ); if (input.is_open()) { common_helpers::consume_bom(input); @@ -763,7 +763,7 @@ static void parse_leaderboards(class Settings *settings_client, class Settings * static void parse_stats(class Settings *settings_client, class Settings *settings_server) { std::string stats_config_path = Local_Storage::get_game_settings_path() + "stats.txt"; - std::ifstream input( utf8_decode(stats_config_path) ); + std::ifstream input( std::filesystem::u8path(stats_config_path) ); if (input.is_open()) { common_helpers::consume_bom(input); for( std::string line; getline( input, line ); ) { @@ -831,7 +831,7 @@ static void parse_stats(class Settings *settings_client, class Settings *setting static void parse_depots(class Settings *settings_client, class Settings *settings_server) { std::string depots_config_path = Local_Storage::get_game_settings_path() + "depots.txt"; - std::ifstream input( utf8_decode(depots_config_path) ); + std::ifstream input( std::filesystem::u8path(depots_config_path) ); if (input.is_open()) { common_helpers::consume_bom(input); for( std::string line; getline( input, line ); ) { @@ -858,7 +858,7 @@ static void parse_depots(class Settings *settings_client, class Settings *settin static void parse_subscribed_groups(class Settings *settings_client, class Settings *settings_server) { std::string depots_config_path = Local_Storage::get_game_settings_path() + "subscribed_groups.txt"; - std::ifstream input( utf8_decode(depots_config_path) ); + std::ifstream input( std::filesystem::u8path(depots_config_path) ); if (input.is_open()) { common_helpers::consume_bom(input); for( std::string line; getline( input, line ); ) { @@ -885,7 +885,7 @@ static void parse_subscribed_groups(class Settings *settings_client, class Setti static void parse_installed_app_Ids(class Settings *settings_client, class Settings *settings_server) { std::string installed_apps_list_path = Local_Storage::get_game_settings_path() + "installed_app_ids.txt"; - std::ifstream input( utf8_decode(installed_apps_list_path) ); + std::ifstream input( std::filesystem::u8path(installed_apps_list_path) ); if (input.is_open()) { settings_client->assumeAnyAppInstalled(false); settings_server->assumeAnyAppInstalled(false); @@ -1142,7 +1142,7 @@ static void parse_crash_printer_location() static void parse_auto_accept_invite(class Settings *settings_client, class Settings *settings_server) { std::string auto_accept_list_path = Local_Storage::get_game_settings_path() + "auto_accept_invite.txt"; - std::ifstream input( utf8_decode(auto_accept_list_path) ); + std::ifstream input( std::filesystem::u8path(auto_accept_list_path) ); if (input.is_open()) { bool accept_any_invite = true; common_helpers::consume_bom(input); @@ -1315,7 +1315,7 @@ static std::map old_itfs_map{}; static bool try_parse_old_steam_interfaces_file(std::string interfaces_path) { - std::ifstream input( utf8_decode(interfaces_path) ); + std::ifstream input( std::filesystem::u8path(interfaces_path) ); if (!input.is_open()) return false; PRINT_DEBUG("Trying to parse old steam interfaces from '%s'", interfaces_path.c_str()); @@ -1407,7 +1407,7 @@ static void load_all_config_settings() local_ini.SetUnicode(); for (const auto &config_file : config_files) { - std::ifstream local_ini_file( utf8_decode(Local_Storage::get_game_settings_path() + config_file), std::ios::binary | std::ios::in); + std::ifstream local_ini_file( std::filesystem::u8path(Local_Storage::get_game_settings_path() + config_file), std::ios::binary | std::ios::in); if (!local_ini_file.is_open()) continue; auto err = local_ini.LoadData(local_ini_file); @@ -1431,7 +1431,7 @@ static void load_all_config_settings() local_ini.SetUnicode(); for (const auto &config_file : config_files) { - std::ifstream local_ini_file( utf8_decode(local_save_folder + Local_Storage::settings_storage_folder + PATH_SEPARATOR + config_file), std::ios::binary | std::ios::in); + std::ifstream local_ini_file( std::filesystem::u8path(local_save_folder + Local_Storage::settings_storage_folder + PATH_SEPARATOR + config_file), std::ios::binary | std::ios::in); if (!local_ini_file.is_open()) continue; auto err = local_ini.LoadData(local_ini_file); @@ -1456,7 +1456,7 @@ static void load_all_config_settings() // now we can access get_user_appdata_path() which might have been changed by the above code for (const auto &config_file : config_files) { - std::ifstream ini_file( utf8_decode(Local_Storage::get_user_appdata_path() + Local_Storage::settings_storage_folder + PATH_SEPARATOR + config_file), std::ios::binary | std::ios::in); + std::ifstream ini_file( std::filesystem::u8path(Local_Storage::get_user_appdata_path() + Local_Storage::settings_storage_folder + PATH_SEPARATOR + config_file), std::ios::binary | std::ios::in); if (!ini_file.is_open()) continue; auto err = global_ini.LoadData(ini_file); diff --git a/dll/steam_apps.cpp b/dll/steam_apps.cpp index ebff9a0d..8f452ca2 100644 --- a/dll/steam_apps.cpp +++ b/dll/steam_apps.cpp @@ -417,7 +417,7 @@ SteamAPICall_t Steam_Apps::GetFileDetails( const char* pszFileName ) //TODO? this function should only return found if file is actually part of the steam depots if (file_exists_(pszFileName)) { data.m_eResult = k_EResultOK; // - std::ifstream stream(utf8_decode(pszFileName), std::ios::binary); + std::ifstream stream(std::filesystem::u8path(pszFileName), std::ios::binary); SHA1 checksum; checksum.update(stream); checksum.final().copy((char *)data.m_FileSHA, sizeof(data.m_FileSHA)); diff --git a/premake5.lua b/premake5.lua index cd9f4f1d..9bba577c 100644 --- a/premake5.lua +++ b/premake5.lua @@ -381,6 +381,10 @@ filter { "configurations:*debug" } filter { "system:windows", } defines { "_CRT_SECURE_NO_WARNINGS", + + -- https://learn.microsoft.com/en-us/cpp/c-runtime-library/compatibility + -- '_CRT_NONSTDC_NO_WARNINGS', + '_CRT_DECLARE_NONSTDC_NAMES', } -- Linux defines filter { "system:linux" }