From c0ace90b5a315e3f95f394f3a262b71a0bd8e0e9 Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 11 Nov 2025 22:57:11 -0500 Subject: [PATCH] path changes --- src/anm2/sound.cpp | 14 +++++++++++++- src/anm2/spritesheet.cpp | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/anm2/sound.cpp b/src/anm2/sound.cpp index 6a4380a..deb61e9 100644 --- a/src/anm2/sound.cpp +++ b/src/anm2/sound.cpp @@ -21,10 +21,22 @@ namespace anm2ed::anm2 return *this; } + namespace + { + std::filesystem::path make_relative_or_keep(const std::filesystem::path& input) + { + if (input.empty()) return input; + std::error_code ec{}; + auto relative = std::filesystem::relative(input, ec); + if (!ec) return relative; + return input; + } + } + Sound::Sound(const std::string& directory, const std::string& path) { filesystem::WorkingDirectory workingDirectory(directory); - this->path = !path.empty() ? std::filesystem::relative(path) : this->path; + this->path = !path.empty() ? make_relative_or_keep(path) : this->path; this->path = filesystem::path_lower_case_backslash_handle(this->path); audio = Audio(this->path); } diff --git a/src/anm2/spritesheet.cpp b/src/anm2/spritesheet.cpp index 0ef2545..88f6093 100644 --- a/src/anm2/spritesheet.cpp +++ b/src/anm2/spritesheet.cpp @@ -21,10 +21,22 @@ namespace anm2ed::anm2 texture = Texture(path); } + namespace + { + std::filesystem::path make_relative_or_keep(const std::filesystem::path& input) + { + if (input.empty()) return input; + std::error_code ec{}; + auto relative = std::filesystem::relative(input, ec); + if (!ec) return relative; + return input; + } + } + Spritesheet::Spritesheet(const std::string& directory, const std::string& path) { filesystem::WorkingDirectory workingDirectory(directory); - this->path = !path.empty() ? std::filesystem::relative(path) : this->path; + this->path = !path.empty() ? make_relative_or_keep(path) : this->path; this->path = filesystem::path_lower_case_backslash_handle(this->path); texture = Texture(this->path); } @@ -58,7 +70,7 @@ namespace anm2ed::anm2 bool Spritesheet::save(const std::string& directory, const std::string& path) { filesystem::WorkingDirectory workingDirectory(directory); - this->path = !path.empty() ? std::filesystem::relative(path) : this->path; + this->path = !path.empty() ? make_relative_or_keep(path) : this->path; return texture.write_png(this->path); }