mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-28 15:30:32 +01:00
Fix typo in .memon file saving that circumvented proper utf8 encoding of the path
This commit is contained in:
parent
9cd1208366
commit
e32ce26b58
@ -103,13 +103,13 @@ config::Config::Config(const std::filesystem::path& settings) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
toml::table tbl;
|
toml::table tbl;
|
||||||
nowide::ifstream config_stream{to_utf8_encoded_string(config_path)};
|
nowide::ifstream config_stream{path_to_utf8_encoded_string(config_path)};
|
||||||
try {
|
try {
|
||||||
tbl = toml::parse(config_stream);
|
tbl = toml::parse(config_stream);
|
||||||
} catch (const toml::parse_error& err) {
|
} catch (const toml::parse_error& err) {
|
||||||
fmt::print(
|
fmt::print(
|
||||||
"Error while parsing {} :\n{}",
|
"Error while parsing {} :\n{}",
|
||||||
settings.string(),
|
path_to_utf8_encoded_string(settings),
|
||||||
err.what()
|
err.what()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -138,7 +138,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{to_utf8_encoded_string(config_path)};
|
nowide::ofstream config_file_stream{path_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
|
||||||
|
@ -16,7 +16,10 @@ FakePitchedSoundStream::FakePitchedSoundStream(
|
|||||||
sample(std::make_shared<sound_buffer_type>())
|
sample(std::make_shared<sound_buffer_type>())
|
||||||
{
|
{
|
||||||
if (not sample->load_from_path(path_to_sample)) {
|
if (not sample->load_from_path(path_to_sample)) {
|
||||||
throw std::runtime_error(fmt::format("Could not load audio sample : {}", path_to_sample.string()));
|
throw std::runtime_error(fmt::format(
|
||||||
|
"Could not load audio sample : {}",
|
||||||
|
path_to_utf8_encoded_string(path_to_sample)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
finish_initializing_the_sample();
|
finish_initializing_the_sample();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ OpenMusic::OpenMusic(const std::filesystem::path& filename) :
|
|||||||
m_loopSpan(0, 0)
|
m_loopSpan(0, 0)
|
||||||
{
|
{
|
||||||
if (not openFromFile(filename)) {
|
if (not openFromFile(filename)) {
|
||||||
throw std::runtime_error("Could not open "+filename.string());
|
throw std::runtime_error("Could not open " + path_to_utf8_encoded_string(filename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1590,17 +1590,23 @@ 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{to_utf8_encoded_string(path.string())};
|
nowide::ofstream file{path_to_utf8_encoded_string(path)};
|
||||||
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_to_utf8_encoded_string(path)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
file << memon.dump(4) << std::endl;
|
file << memon.dump(4) << std::endl;
|
||||||
file.close();
|
file.close();
|
||||||
if (not file) {
|
if (not file) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
fmt::format("Error while closing file {}", path.string())
|
fmt::format(
|
||||||
|
"Error while closing file {}",
|
||||||
|
path_to_utf8_encoded_string(path)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
song_path = path;
|
song_path = path;
|
||||||
@ -1658,11 +1664,14 @@ void feis::open_from_file(
|
|||||||
config::Config& config
|
config::Config& config
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
nowide::ifstream f{to_utf8_encoded_string(song_path)};
|
nowide::ifstream f{path_to_utf8_encoded_string(song_path)};
|
||||||
if (not f) {
|
if (not f) {
|
||||||
tinyfd_messageBox(
|
tinyfd_messageBox(
|
||||||
"Error",
|
"Error",
|
||||||
fmt::format("Could not open file {}", song_path.string()).c_str(),
|
fmt::format(
|
||||||
|
"Could not open file {}",
|
||||||
|
path_to_utf8_encoded_string(song_path)
|
||||||
|
).c_str(),
|
||||||
"ok",
|
"ok",
|
||||||
"error",
|
"error",
|
||||||
1
|
1
|
||||||
|
@ -44,7 +44,7 @@ const std::string beat_tick_stream = "beat_tick";
|
|||||||
*/
|
*/
|
||||||
class EditorState {
|
class EditorState {
|
||||||
public:
|
public:
|
||||||
explicit EditorState(
|
EditorState(
|
||||||
const std::filesystem::path& assets,
|
const std::filesystem::path& assets,
|
||||||
config::Config& config
|
config::Config& config
|
||||||
);
|
);
|
||||||
|
@ -73,7 +73,7 @@ std::array<LNMarker::texture_type, number> load_tex_with_prefix(
|
|||||||
if (not tex.load_from_path(texFile)) {
|
if (not tex.load_from_path(texFile)) {
|
||||||
throw std::runtime_error(fmt::format(
|
throw std::runtime_error(fmt::format(
|
||||||
"Unable to load texture folder {}, failed on texture {}",
|
"Unable to load texture folder {}, failed on texture {}",
|
||||||
folder.string(),
|
path_to_utf8_encoded_string(folder),
|
||||||
filename
|
filename
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ int main() {
|
|||||||
if (not std::filesystem::exists(font_path)) {
|
if (not std::filesystem::exists(font_path)) {
|
||||||
tinyfd_messageBox(
|
tinyfd_messageBox(
|
||||||
"Error",
|
"Error",
|
||||||
("Could not open "+to_utf8_encoded_string(font_path)).c_str(),
|
("Could not open "+path_to_utf8_encoded_string(font_path)).c_str(),
|
||||||
"ok",
|
"ok",
|
||||||
"error",
|
"error",
|
||||||
1
|
1
|
||||||
@ -64,7 +64,7 @@ int main() {
|
|||||||
ImGuiIO& IO = ImGui::GetIO();
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
IO.Fonts->Clear();
|
IO.Fonts->Clear();
|
||||||
IO.Fonts->AddFontFromFileTTF(
|
IO.Fonts->AddFontFromFileTTF(
|
||||||
to_utf8_encoded_string(assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(),
|
path_to_utf8_encoded_string(assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(),
|
||||||
16.f
|
16.f
|
||||||
);
|
);
|
||||||
ImGui::SFML::UpdateFontTexture();
|
ImGui::SFML::UpdateFontTexture();
|
||||||
|
@ -26,7 +26,7 @@ Marker::Marker(const std::filesystem::path& folder_):
|
|||||||
if (not tex.load_from_path(path)) {
|
if (not tex.load_from_path(path)) {
|
||||||
throw std::runtime_error(fmt::format(
|
throw std::runtime_error(fmt::format(
|
||||||
"Unable to load marker {} - failed on image {}",
|
"Unable to load marker {} - failed on image {}",
|
||||||
folder.string(),
|
path_to_utf8_encoded_string(folder),
|
||||||
file
|
file
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,7 +11,7 @@ Playfield::Playfield(std::filesystem::path assets_folder) :
|
|||||||
{
|
{
|
||||||
if (!base_texture.load_from_path(texture_path)) {
|
if (!base_texture.load_from_path(texture_path)) {
|
||||||
std::cerr << "Unable to load texture " << texture_path;
|
std::cerr << "Unable to load texture " << texture_path;
|
||||||
throw std::runtime_error("Unable to load texture " + texture_path.string());
|
throw std::runtime_error("Unable to load texture " + path_to_utf8_encoded_string(texture_path);
|
||||||
}
|
}
|
||||||
base_texture.setSmooth(true);
|
base_texture.setSmooth(true);
|
||||||
|
|
||||||
|
@ -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(to_utf8_encoded_string(recent_files_path));
|
nowide::ifstream readFile(path_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);) {
|
||||||
@ -29,16 +29,16 @@ void Toolbox::pushNewRecentFile(std::filesystem::path file, std::filesystem::pat
|
|||||||
}
|
}
|
||||||
readFile.close();
|
readFile.close();
|
||||||
|
|
||||||
recent.remove(to_utf8_encoded_string(file));
|
recent.remove(path_to_utf8_encoded_string(file));
|
||||||
|
|
||||||
while (recent.size() >= 10) {
|
while (recent.size() >= 10) {
|
||||||
recent.pop_back();
|
recent.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
recent.push_front(to_utf8_encoded_string(file));
|
recent.push_front(path_to_utf8_encoded_string(file));
|
||||||
|
|
||||||
nowide::ofstream writeFile(
|
nowide::ofstream writeFile(
|
||||||
to_utf8_encoded_string(recent_files_path),
|
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{to_utf8_encoded_string(settings / recent_files_file)};
|
nowide::ifstream readFile{path_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);
|
||||||
|
@ -15,7 +15,7 @@ void feis::UTF8FileInputStream::FileCloser::operator()(std::FILE* file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool feis::UTF8FileInputStream::open(const std::filesystem::path& filename) {
|
bool feis::UTF8FileInputStream::open(const std::filesystem::path& filename) {
|
||||||
m_file.reset(nowide::fopen(to_utf8_encoded_string(filename).c_str(), "rb"));
|
m_file.reset(nowide::fopen(path_to_utf8_encoded_string(filename).c_str(), "rb"));
|
||||||
return m_file != nullptr;
|
return m_file != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
std::string to_utf8_encoded_string(const std::u8string& u8s) {
|
std::string u8string_to_utf8_encoded_string(const std::u8string& u8s) {
|
||||||
std::string result{u8s.cbegin(), u8s.cend()};
|
std::string result{u8s.cbegin(), u8s.cend()};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_utf8_encoded_string(const std::filesystem::path& path) {
|
std::string path_to_utf8_encoded_string(const std::filesystem::path& path) {
|
||||||
return to_utf8_encoded_string(path.u8string());
|
return u8string_to_utf8_encoded_string(path.u8string());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::u8string to_u8string(const std::string& utf8s) {
|
std::u8string to_u8string(const std::string& utf8s) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string to_utf8_encoded_string(const std::u8string& u8s);
|
std::string u8string_to_utf8_encoded_string(const std::u8string& u8s);
|
||||||
std::string to_utf8_encoded_string(const std::filesystem::path& path);
|
std::string path_to_utf8_encoded_string(const std::filesystem::path& path);
|
||||||
std::u8string to_u8string(const std::string& utf8s);
|
std::u8string to_u8string(const std::string& utf8s);
|
||||||
std::filesystem::path to_path(const std::string& utf8s);
|
std::filesystem::path to_path(const std::string& utf8s);
|
@ -12,7 +12,7 @@ DensityGraph::DensityGraph(std::filesystem::path assets, const config::Config& c
|
|||||||
{
|
{
|
||||||
if (!base_texture.load_from_path(texture_path)) {
|
if (!base_texture.load_from_path(texture_path)) {
|
||||||
std::cerr << "Unable to load texture " << texture_path;
|
std::cerr << "Unable to load texture " << texture_path;
|
||||||
throw std::runtime_error("Unable to load texture " + texture_path.string());
|
throw std::runtime_error("Unable to load texture " + path_to_utf8_encoded_string(texture_path));
|
||||||
}
|
}
|
||||||
base_texture.setSmooth(true);
|
base_texture.setSmooth(true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user