Force utf8 string conversion when constructing a nowide file stream

This commit is contained in:
Stepland 2023-01-09 16:40:07 +01:00
parent c4c5b2a848
commit c65b071f68
3 changed files with 9 additions and 8 deletions

View File

@ -13,6 +13,7 @@
#include "nowide/fstream.hpp" #include "nowide/fstream.hpp"
#include "variant_visitor.hpp" #include "variant_visitor.hpp"
#include "widgets/lane_order.hpp" #include "widgets/lane_order.hpp"
#include "utf8_strings.hpp"
void config::Marker::load_from_v1_0_0_table(const toml::table &tbl) { void config::Marker::load_from_v1_0_0_table(const toml::table &tbl) {
const auto marker_node = tbl["marker"]; const auto marker_node = tbl["marker"];
@ -100,7 +101,7 @@ config::Config::Config(const std::filesystem::path& settings) :
} }
toml::table tbl; toml::table tbl;
nowide::ifstream config_stream{settings}; nowide::ifstream config_stream{to_utf8_encoded_string(settings)};
try { try {
tbl = toml::parse(config_stream); tbl = toml::parse(config_stream);
} catch (const toml::parse_error& err) { } catch (const toml::parse_error& err) {
@ -135,7 +136,7 @@ toml::table config::Config::dump_as_v1_0_0() {
config::Config::~Config() { config::Config::~Config() {
std::filesystem::create_directories(config_path.parent_path()); std::filesystem::create_directories(config_path.parent_path());
const auto tbl = dump_as_v1_0_0(); 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 = ( const auto flags = (
toml::toml_formatter::default_flags toml::toml_formatter::default_flags
& ~toml::format_flags::allow_literal_strings & ~toml::format_flags::allow_literal_strings

View File

@ -40,6 +40,7 @@
#include "src/better_timing.hpp" #include "src/better_timing.hpp"
#include "src/custom_sfml_audio/synced_sound_streams.hpp" #include "src/custom_sfml_audio/synced_sound_streams.hpp"
#include "variant_visitor.hpp" #include "variant_visitor.hpp"
#include "utf8_strings.hpp"
EditorState::EditorState(const std::filesystem::path& assets_, config::Config& config_) : EditorState::EditorState(const std::filesystem::path& assets_, config::Config& config_) :
config(config_), config(config_),
@ -1554,7 +1555,7 @@ TimingOrigin EditorState::timing_origin() {
void EditorState::save(const std::filesystem::path& path) { void EditorState::save(const std::filesystem::path& path) {
const auto memon = song.dump_to_memon_1_0_0(); 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) { if (not file) {
throw std::runtime_error( throw std::runtime_error(
fmt::format("Cannot write to file {}", path.string()) fmt::format("Cannot write to file {}", path.string())
@ -1622,8 +1623,7 @@ void feis::open_from_file(
config::Config& config config::Config& config
) { ) {
try { try {
// force utf-8 song path on windows nowide::ifstream f{to_utf8_encoded_string(song_path)};
nowide::ifstream f{song_path.string()};
if (not f) { if (not f) {
tinyfd_messageBox( tinyfd_messageBox(
"Error", "Error",

View File

@ -18,7 +18,7 @@ const std::string recent_files_file = "recent files.txt";
void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::path settings) { void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::path settings) {
std::filesystem::create_directory(settings); std::filesystem::create_directory(settings);
auto recent_files_path = settings / recent_files_file; 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<std::string> recent; std::list<std::string> recent;
std::set<std::string> recent_set; std::set<std::string> recent_set;
for (std::string line; getline(readFile, line);) { 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()); recent.push_front(std::filesystem::canonical(file).string());
nowide::ofstream writeFile( nowide::ofstream writeFile(
recent_files_path, to_utf8_encoded_string(recent_files_path),
std::ofstream::out | std::ofstream::trunc std::ofstream::out | std::ofstream::trunc
); );
for (const auto& line : recent) { for (const auto& line : recent) {
@ -48,7 +48,7 @@ void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::pat
} }
std::vector<std::string> Toolbox::getRecentFiles(std::filesystem::path settings) { std::vector<std::string> 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<std::string> recent; std::vector<std::string> recent;
for (std::string line; getline(readFile, line);) { for (std::string line; getline(readFile, line);) {
recent.push_back(line); recent.push_back(line);