diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 4e38a7add..e2f83daca 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -261,18 +261,36 @@ namespace wiHelper return ss.str(); } - string GetFileNameFromPath(const std::string& path) + void SplitPath(const std::string& fullPath, string& dir, string& fileName) { - std::filesystem::path filepath = path; - filepath = std::filesystem::absolute(filepath); - return filepath.filename().string(); + size_t found; + found = fullPath.find_last_of("/\\"); + dir = fullPath.substr(0, found + 1); + fileName = fullPath.substr(found + 1); } - string GetDirectoryFromPath(const std::string& path) + string GetFileNameFromPath(const std::string& fullPath) { - std::filesystem::path filepath = path; - filepath = std::filesystem::absolute(filepath); - return filepath.parent_path().string() + "/"; + if (fullPath.empty()) + { + return fullPath; + } + + string ret, empty; + SplitPath(fullPath, empty, ret); + return ret; + } + + string GetDirectoryFromPath(const std::string& fullPath) + { + if (fullPath.empty()) + { + return fullPath; + } + + string ret, empty; + SplitPath(fullPath, ret, empty); + return ret; } string GetExtensionFromFileName(const string& filename) @@ -289,6 +307,20 @@ namespace wiHelper return ""; } + void MakePathRelative(const std::string& rootdir, std::string& path) + { + if (rootdir.empty() || path.empty()) + { + return; + } + + size_t found = path.rfind(rootdir); + if (found != std::string::npos) + { + path = path.substr(found + rootdir.length()); + } + } + bool FileRead(const std::string& fileName, std::vector& data) { #ifndef PLATFORM_UWP diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index 2af9efdb6..617474f94 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -45,12 +45,16 @@ namespace wiHelper std::string getCurrentDateTimeAsString(); + void SplitPath(const std::string& fullPath, std::string& dir, std::string& fileName); + std::string GetFileNameFromPath(const std::string& path); std::string GetDirectoryFromPath(const std::string& path); std::string GetExtensionFromFileName(const std::string& filename); + void MakePathRelative(const std::string& rootdir, std::string& path); + bool FileRead(const std::string& fileName, std::vector& data); bool FileWrite(const std::string& fileName, const uint8_t* data, size_t size); diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index 0b8e44b9e..40464cf35 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -246,11 +246,7 @@ namespace wiScene { for (auto& x : textures) { - size_t found = x.name.rfind(dir); - if (found != std::string::npos) - { - x.name = x.name.substr(found + dir.length()); - } + wiHelper::MakePathRelative(dir, x.name); } } @@ -727,11 +723,7 @@ namespace wiScene { for (size_t i = 0; i < lensFlareNames.size(); ++i) { - size_t found = lensFlareNames[i].rfind(dir); - if (found != std::string::npos) - { - lensFlareNames[i] = lensFlareNames[i].substr(found + dir.length()); - } + wiHelper::MakePathRelative(dir, lensFlareNames[i]); } } archive << lensFlareNames; @@ -986,21 +978,8 @@ namespace wiScene archive << oceanParameters.surfaceDetail; archive << oceanParameters.surfaceDisplacementTolerance; - // If detecting an absolute path in textures, remove it and convert to relative: - if (!dir.empty()) - { - size_t found = skyMapName.rfind(dir); - if (found != std::string::npos) - { - skyMapName = skyMapName.substr(found + dir.length()); - } - - found = colorGradingMapName.rfind(dir); - if (found != std::string::npos) - { - colorGradingMapName = colorGradingMapName.substr(found + dir.length()); - } - } + wiHelper::MakePathRelative(dir, skyMapName); + wiHelper::MakePathRelative(dir, colorGradingMapName); if (archive.GetVersion() >= 32) { @@ -1038,15 +1017,7 @@ namespace wiScene } else { - // If detecting an absolute path in textures, remove it and convert to relative: - if(!dir.empty()) - { - size_t found = filename.rfind(dir); - if (found != std::string::npos) - { - filename = filename.substr(found + dir.length()); - } - } + wiHelper::MakePathRelative(dir, filename); archive << _flags; archive << filename; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index da278b446..77ba66597 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates, breaking compatibility changes const int minor = 53; // minor bug fixes, alterations, refactors, updates - const int revision = 14; + const int revision = 15; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);