path changes

This commit is contained in:
2025-11-11 22:57:11 -05:00
parent 57b2e3aa4c
commit c0ace90b5a
2 changed files with 27 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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);
}