diff --git a/crash_printer/tests/test_helper.hpp b/crash_printer/tests/test_helper.hpp index c17eac49..cdedb9d5 100644 --- a/crash_printer/tests/test_helper.hpp +++ b/crash_printer/tests/test_helper.hpp @@ -7,15 +7,16 @@ static inline bool remove_file(const std::string &file) { - if (!std::filesystem::exists(file)) { + const std::filesystem::u8path p_file(std::filesystem::u8path(file)); + if (!std::filesystem::exists(p_file)) { return true; } - if (std::filesystem::is_directory(file)) { + if (std::filesystem::is_directory(p_file)) { return false; } - return std::filesystem::remove(file); + return std::filesystem::remove(p_file); } static inline bool remove_file(const std::wstring &file) @@ -32,4 +33,4 @@ static inline bool remove_file(const std::wstring &file) } -#endif // _TEST_CRASH_PRINTER_HELPER_H \ No newline at end of file +#endif // _TEST_CRASH_PRINTER_HELPER_H diff --git a/dll/dll/steam_remote_storage.h b/dll/dll/steam_remote_storage.h index fe4d73ba..4a6785a9 100644 --- a/dll/dll/steam_remote_storage.h +++ b/dll/dll/steam_remote_storage.h @@ -57,10 +57,11 @@ static void copy_file(const std::string &src_filepath, const std::string &dst_fi try { PRINT_DEBUG("copying file '%s' to '%s'", src_filepath.c_str(), dst_filepath.c_str()); - const auto src_p = std::filesystem::path(src_filepath); - if (!std::filesystem::exists(src_p) || std::filesystem::is_directory(src_p)) return; + const std::filesystem::path src_p(std::filesystem::u8path(src_filepath)); - const auto dst_p = std::filesystem::path(dst_filepath); + if (!common_helpers::file_exist(src_p)) return; + + const std::filesystem::path dst_p(std::filesystem::u8path(dst_filepath)); std::filesystem::create_directories(dst_p.parent_path()); // make the folder tree if needed std::filesystem::copy_file(src_p, dst_p, std::filesystem::copy_options::overwrite_existing); } catch(...) {} diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 016b4b92..48312f38 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -617,8 +617,8 @@ std::vector Local_Storage::get_folders_path(std::string path) std::vector output{}; try { - const auto path_p = std::filesystem::path(path); - if (!std::filesystem::is_directory(path_p)) return output; + const std::filesystem::path path_p(std::filesystem::u8path(path)); + if (!common_helpers::dir_exist(path_p)) return output; for (const auto &dir_entry : std::filesystem::directory_iterator(path_p, std::filesystem::directory_options::follow_directory_symlink)) { diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index d21bbf5c..a7de5aee 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -198,7 +198,7 @@ static void load_overlay_appearance(class Settings *settings_client, class Setti PRINT_DEBUG(" Overlay appearance line '%s'='%s'", name.c_str(), value.c_str()); try { if (name.compare("Font_Override") == 0) { - value = common_helpers::string_strip(Settings::sanitize(value)); + value = common_helpers::string_strip(value); // first try the local settings folder std::string nfont_override(common_helpers::to_absolute(value, Local_Storage::get_game_settings_path() + "fonts")); if (!common_helpers::file_exist(nfont_override)) { @@ -513,7 +513,7 @@ static bool parse_local_save(std::string &save_path) auto ptr = ini.GetValue("user::saves", "local_save_path"); if (!ptr || !ptr[0]) return false; - save_path = common_helpers::to_absolute(common_helpers::string_strip(Settings::sanitize(ptr)), Local_Storage::get_program_path()); + save_path = common_helpers::to_absolute(common_helpers::string_strip(ptr), Local_Storage::get_program_path()); if (save_path.size() && save_path.back() != *PATH_SEPARATOR) { save_path.push_back(*PATH_SEPARATOR); } @@ -1104,7 +1104,7 @@ static void parse_build_id(class Settings *settings_client, class Settings *sett // main::general::crash_printer_location static void parse_crash_printer_location() { - std::string line(common_helpers::string_strip(Settings::sanitize(ini.GetValue("main::general", "crash_printer_location", "")))); + std::string line(common_helpers::string_strip(ini.GetValue("main::general", "crash_printer_location", ""))); if (line.size()) { auto crash_path = utf8_decode(common_helpers::to_absolute(line, get_full_program_path())); if (crash_path.size()) { diff --git a/helpers/common_helpers.cpp b/helpers/common_helpers.cpp index 77e199f1..21942dbe 100644 --- a/helpers/common_helpers.cpp +++ b/helpers/common_helpers.cpp @@ -21,7 +21,7 @@ static bool create_dir_impl(std::filesystem::path &dirpath) bool common_helpers::create_dir(const std::string_view &filepath) { - std::filesystem::path parent(std::filesystem::path(filepath).parent_path()); + std::filesystem::path parent(std::filesystem::u8path(filepath).parent_path()); return create_dir_impl(parent); } @@ -231,17 +231,17 @@ static std::filesystem::path to_absolute_impl(const std::filesystem::path &path, std::string common_helpers::to_absolute(const std::string_view &path, const std::string_view &base) { - if (path.empty()) return std::string(path); + if (path.empty()) return {}; auto path_abs = to_absolute_impl( - std::filesystem::path(path), - base.empty() ? std::filesystem::current_path() : std::filesystem::path(base) + std::filesystem::u8path(path), + base.empty() ? std::filesystem::current_path() : std::filesystem::u8path(base) ); return path_abs.u8string(); } std::wstring common_helpers::to_absolute(const std::wstring_view &path, const std::wstring_view &base) { - if (path.empty()) return std::wstring(path); + if (path.empty()) return {}; auto path_abs = to_absolute_impl( std::filesystem::path(path), base.empty() ? std::filesystem::current_path() : std::filesystem::path(base) @@ -263,15 +263,13 @@ bool common_helpers::file_exist(const std::filesystem::path &filepath) bool common_helpers::file_exist(const std::string &filepath) { if (filepath.empty()) return false; - std::filesystem::path path(filepath); - return file_exist(path); + return file_exist(std::filesystem::u8path(filepath)); } bool common_helpers::file_exist(const std::wstring &filepath) { if (filepath.empty()) return false; - std::filesystem::path path(filepath); - return file_exist(path); + return file_exist(std::filesystem::path(filepath)); } bool common_helpers::file_size(const std::filesystem::path &filepath, size_t &size) @@ -285,14 +283,12 @@ bool common_helpers::file_size(const std::filesystem::path &filepath, size_t &si bool common_helpers::file_size(const std::string &filepath, size_t &size) { - const auto file_p = std::filesystem::path(filepath); - return file_size(file_p, size); + return file_size(std::filesystem::u8path(filepath), size); } bool common_helpers::file_size(const std::wstring &filepath, size_t &size) { - const auto file_p = std::filesystem::path(filepath); - return file_size(file_p, size); + return file_size(std::filesystem::path(filepath), size); } bool common_helpers::dir_exist(const std::filesystem::path &dirpath) @@ -307,13 +303,11 @@ bool common_helpers::dir_exist(const std::filesystem::path &dirpath) bool common_helpers::dir_exist(const std::string &dirpath) { if (dirpath.empty()) return false; - std::filesystem::path path(dirpath); - return dir_exist(path); + return dir_exist(std::filesystem::u8path(dirpath)); } bool common_helpers::dir_exist(const std::wstring &dirpath) { if (dirpath.empty()) return false; - std::filesystem::path path(dirpath); - return dir_exist(path); + return dir_exist(std::filesystem::path(dirpath)); }