From 4977f4476cd1ed7a52670171f92e47c0ae5bd399 Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 13 Dec 2025 02:33:12 -0500 Subject: [PATCH] maybe... --- src/anm2/anm2.cpp | 8 ++++++-- src/util/filesystem_.cpp | 13 +++++++++++++ src/util/filesystem_.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index 7a78b79..0bc0bb5 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -23,7 +23,9 @@ namespace anm2ed::anm2 { XMLDocument document; - if (document.LoadFile(path.string().c_str()) != XML_SUCCESS) + filesystem::File file{path, "rb"}; + + if (!file.get() || document.LoadFile(file.get()) != XML_SUCCESS) { if (errorString) *errorString = document.ErrorStr(); return; @@ -56,7 +58,9 @@ namespace anm2ed::anm2 XMLDocument document; document.InsertFirstChild(to_element(document)); - if (document.SaveFile(path.string().c_str()) != XML_SUCCESS) + filesystem::File file{path, "w"}; + + if (!file.get() || document.SaveFile(file.get()) != XML_SUCCESS) { if (errorString) *errorString = document.ErrorStr(); return false; diff --git a/src/util/filesystem_.cpp b/src/util/filesystem_.cpp index a4471e6..f50c622 100644 --- a/src/util/filesystem_.cpp +++ b/src/util/filesystem_.cpp @@ -20,6 +20,19 @@ namespace anm2ed::util::filesystem } } + File::File(const std::filesystem::path& path, const char* mode) + { +#ifdef _WIN32 + _wfopen_s(&this->internal, path.c_str(), mode); +#else + this->internal = fopen(path.c_str(), mode); +#endif + } + + File::~File() { fclose(this->internal); } + + FILE* File::get() { return internal; } + std::filesystem::path path_preferences_get() { auto path = SDL_GetPrefPath(nullptr, "anm2ed"); diff --git a/src/util/filesystem_.h b/src/util/filesystem_.h index 7d9e8b8..44ce68b 100644 --- a/src/util/filesystem_.h +++ b/src/util/filesystem_.h @@ -14,6 +14,8 @@ namespace anm2ed::util::filesystem std::filesystem::path path_lower_case_backslash_handle(const std::filesystem::path&); + FILE* open(const std::filesystem::path&, const char*); + class WorkingDirectory { public: @@ -22,4 +24,14 @@ namespace anm2ed::util::filesystem WorkingDirectory(const std::filesystem::path&, bool = false); ~WorkingDirectory(); }; + + class File + { + public: + FILE* internal{}; + + File(const std::filesystem::path&, const char*); + ~File(); + FILE* get(); + }; }