From c65b071f68ee1cc8857991dde6e438b907b9a43a Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Mon, 9 Jan 2023 16:40:07 +0100 Subject: [PATCH] Force utf8 string conversion when constructing a nowide file stream --- src/config.cpp | 5 +++-- src/editor_state.cpp | 6 +++--- src/toolbox.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index e427adf..72e6695 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -13,6 +13,7 @@ #include "nowide/fstream.hpp" #include "variant_visitor.hpp" #include "widgets/lane_order.hpp" +#include "utf8_strings.hpp" void config::Marker::load_from_v1_0_0_table(const toml::table &tbl) { const auto marker_node = tbl["marker"]; @@ -100,7 +101,7 @@ config::Config::Config(const std::filesystem::path& settings) : } toml::table tbl; - nowide::ifstream config_stream{settings}; + nowide::ifstream config_stream{to_utf8_encoded_string(settings)}; try { tbl = toml::parse(config_stream); } catch (const toml::parse_error& err) { @@ -135,7 +136,7 @@ toml::table config::Config::dump_as_v1_0_0() { config::Config::~Config() { std::filesystem::create_directories(config_path.parent_path()); const auto tbl = dump_as_v1_0_0(); - nowide::ofstream config_file_stream{config_path}; + nowide::ofstream config_file_stream{to_utf8_encoded_string(config_path)}; const auto flags = ( toml::toml_formatter::default_flags & ~toml::format_flags::allow_literal_strings diff --git a/src/editor_state.cpp b/src/editor_state.cpp index d87a878..fc51ec7 100644 --- a/src/editor_state.cpp +++ b/src/editor_state.cpp @@ -40,6 +40,7 @@ #include "src/better_timing.hpp" #include "src/custom_sfml_audio/synced_sound_streams.hpp" #include "variant_visitor.hpp" +#include "utf8_strings.hpp" EditorState::EditorState(const std::filesystem::path& assets_, config::Config& config_) : config(config_), @@ -1554,7 +1555,7 @@ TimingOrigin EditorState::timing_origin() { void EditorState::save(const std::filesystem::path& path) { const auto memon = song.dump_to_memon_1_0_0(); - nowide::ofstream file{path.string()}; + nowide::ofstream file{to_utf8_encoded_string(path.string())}; if (not file) { throw std::runtime_error( fmt::format("Cannot write to file {}", path.string()) @@ -1622,8 +1623,7 @@ void feis::open_from_file( config::Config& config ) { try { - // force utf-8 song path on windows - nowide::ifstream f{song_path.string()}; + nowide::ifstream f{to_utf8_encoded_string(song_path)}; if (not f) { tinyfd_messageBox( "Error", diff --git a/src/toolbox.cpp b/src/toolbox.cpp index 34d6d26..8406e65 100644 --- a/src/toolbox.cpp +++ b/src/toolbox.cpp @@ -18,7 +18,7 @@ const std::string recent_files_file = "recent files.txt"; void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::path settings) { std::filesystem::create_directory(settings); auto recent_files_path = settings / recent_files_file; - nowide::ifstream readFile(recent_files_path); + nowide::ifstream readFile(to_utf8_encoded_string(recent_files_path)); std::list recent; std::set recent_set; for (std::string line; getline(readFile, line);) { @@ -38,7 +38,7 @@ void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::pat recent.push_front(std::filesystem::canonical(file).string()); nowide::ofstream writeFile( - recent_files_path, + to_utf8_encoded_string(recent_files_path), std::ofstream::out | std::ofstream::trunc ); for (const auto& line : recent) { @@ -48,7 +48,7 @@ void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::pat } std::vector Toolbox::getRecentFiles(std::filesystem::path settings) { - nowide::ifstream readFile{settings / recent_files_file}; + nowide::ifstream readFile{to_utf8_encoded_string(settings / recent_files_file)}; std::vector recent; for (std::string line; getline(readFile, line);) { recent.push_back(line);