From 69bb65e47bd3c6dcd37beb1535f24034274fb339 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 13 Aug 2023 16:51:15 +0100 Subject: [PATCH 01/10] Allow bookart to be in texutres and texutres to be in bookart. Rebased to account for upstream normalising slashes to turn forward slashes into backslashes. This simplifies some conditions that previously needed to check for both kinds. --- components/misc/resourcehelpers.cpp | 26 ++++++++++++++++---------- components/misc/resourcehelpers.hpp | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index ce552df4f7..762a8b88d2 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -46,8 +46,8 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) return changeExtension(path, ".dds"); } -std::string Misc::ResourceHelpers::correctResourcePath( - std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, + const VFS::Manager* vfs, const std::vector& alternativeDirectories) { /* Bethesda at some point converted all their BSA * textures from tga to dds for increased load speed, but all @@ -69,12 +69,18 @@ std::string Misc::ResourceHelpers::correctResourcePath( if (!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size() || correctedPath[topLevelDirectory.size()] != '\\') { - std::string topLevelPrefix = std::string{ topLevelDirectory } + '\\'; - size_t topLevelPos = correctedPath.find('\\' + topLevelPrefix); - if (topLevelPos == std::string::npos) - correctedPath = topLevelPrefix + correctedPath; - else - correctedPath.erase(0, topLevelPos + 1); + bool needsPrefix = true; + for (std::string_view alternativeDirectory : alternativeDirectories) + { + if (!correctedPath.starts_with(alternativeDirectory) || correctedPath.size() <= alternativeDirectory.size() + || correctedPath[alternativeDirectory.size()] != '\\') + { + needsPrefix = false; + break; + } + } + if (needsPrefix) + correctedPath = std::string{ topLevelDirectory } + '\\' + correctedPath; } std::string origExt = correctedPath; @@ -110,7 +116,7 @@ std::string Misc::ResourceHelpers::correctResourcePath( std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath("textures", resPath, vfs); + return correctResourcePath("textures", resPath, vfs, { "bookart" }); } std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs) @@ -120,7 +126,7 @@ std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, con std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath("bookart", resPath, vfs); + return correctResourcePath("bookart", resPath, vfs, { "textures" }); } std::string Misc::ResourceHelpers::correctBookartPath( diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index 478569ed14..f45a52a23c 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -22,8 +22,8 @@ namespace Misc namespace ResourceHelpers { bool changeExtensionToDds(std::string& path); - std::string correctResourcePath( - std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs); + std::string correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, + const VFS::Manager* vfs, const std::vector& alternativeDirectories = {}); std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs); std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs); std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs); From 575367bc18bfd030335166deedef58bd680a1c54 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 13 Aug 2023 23:35:25 +0100 Subject: [PATCH 02/10] v e c t o r --- components/misc/resourcehelpers.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index f45a52a23c..dc0b487a59 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace VFS { From f30676cbc73b9ee5135f93a3567753a89d684831 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 14 Aug 2023 14:10:45 +0100 Subject: [PATCH 03/10] Invert condition Rebased to account for upstream normalising slashes to replace forward slashes with backslashes, simplifying the part that needed to check for both variants. Perhaps if it'd been like that in the first place, I wouldn't have made the mistake that made the original version of this commit necessary. --- components/misc/resourcehelpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 762a8b88d2..32f65872c7 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -72,8 +72,8 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevel bool needsPrefix = true; for (std::string_view alternativeDirectory : alternativeDirectories) { - if (!correctedPath.starts_with(alternativeDirectory) || correctedPath.size() <= alternativeDirectory.size() - || correctedPath[alternativeDirectory.size()] != '\\') + if (correctedPath.starts_with(alternativeDirectory) && correctedPath.size() > alternativeDirectory.size() + && correctedPath[alternativeDirectory.size()] == '\\') { needsPrefix = false; break; From bf0756c5b35536949b2026d41b5ebdb3aa3c6a42 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 14 Aug 2023 22:09:51 +0100 Subject: [PATCH 04/10] c h a n g e l o g Rebased to account for other new changelog entries. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b36eb2525..dd6f7d68c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ Bug #7472: Crash when enchanting last projectiles Bug #7502: Data directories dialog (0.48.0) forces adding subdirectory instead of intended directory Bug #7505: Distant terrain does not support sample size greater than cell size + Bug #7535: Bookart paths for textures in OpenMW vs vanilla Morrowind Bug #7553: Faction reaction loading is incorrect Bug #7557: Terrain::ChunkManager::createChunk is called twice for the same position, lod on initial loading Bug #7573: Drain Fatigue can't bring fatigue below zero by default From 3a71a78d9ea32708b996b7f51fe7717ca3ad7316 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 10 Dec 2023 19:01:30 +0000 Subject: [PATCH 05/10] Combine topLevelDirectory and alternativeDirectories --- components/misc/resourcehelpers.cpp | 34 +++++++++++++---------------- components/misc/resourcehelpers.hpp | 4 ++-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 32f65872c7..b602001913 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -46,8 +46,8 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) return changeExtension(path, ".dds"); } -std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, - const VFS::Manager* vfs, const std::vector& alternativeDirectories) +std::string Misc::ResourceHelpers::correctResourcePath( + const std::vector& topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs) { /* Bethesda at some point converted all their BSA * textures from tga to dds for increased load speed, but all @@ -66,22 +66,18 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevel correctedPath.erase(0, 1); // Handle top level directory - if (!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size() - || correctedPath[topLevelDirectory.size()] != '\\') + bool needsPrefix = true; + for (std::string_view alternativeDirectory : topLevelDirectories) { - bool needsPrefix = true; - for (std::string_view alternativeDirectory : alternativeDirectories) + if (correctedPath.starts_with(alternativeDirectory) && correctedPath.size() > alternativeDirectory.size() + && correctedPath[alternativeDirectory.size()] == '\\') { - if (correctedPath.starts_with(alternativeDirectory) && correctedPath.size() > alternativeDirectory.size() - && correctedPath[alternativeDirectory.size()] == '\\') - { - needsPrefix = false; - break; - } + needsPrefix = false; + break; } - if (needsPrefix) - correctedPath = std::string{ topLevelDirectory } + '\\' + correctedPath; } + if (needsPrefix) + correctedPath = std::string{ topLevelDirectories.front() } + '\\' + correctedPath; std::string origExt = correctedPath; @@ -96,7 +92,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevel return origExt; // fall back to a resource in the top level directory if it exists - std::string fallback{ topLevelDirectory }; + std::string fallback{ topLevelDirectories.front() }; fallback += '\\'; fallback += getBasename(correctedPath); if (vfs->exists(fallback)) @@ -104,7 +100,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevel if (changedToDds) { - fallback = topLevelDirectory; + fallback = topLevelDirectories.front(); fallback += '\\'; fallback += getBasename(origExt); if (vfs->exists(fallback)) @@ -116,17 +112,17 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevel std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath("textures", resPath, vfs, { "bookart" }); + return correctResourcePath({ "textures", "bookart" }, resPath, vfs); } std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath("icons", resPath, vfs); + return correctResourcePath({ "icons" }, resPath, vfs); } std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath("bookart", resPath, vfs, { "textures" }); + return correctResourcePath({ "bookart", "textures" }, resPath, vfs); } std::string Misc::ResourceHelpers::correctBookartPath( diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index dc0b487a59..c98840dd61 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -23,8 +23,8 @@ namespace Misc namespace ResourceHelpers { bool changeExtensionToDds(std::string& path); - std::string correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, - const VFS::Manager* vfs, const std::vector& alternativeDirectories = {}); + std::string correctResourcePath(const std::vector& topLevelDirectories, + std::string_view resPath, const VFS::Manager* vfs); std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs); std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs); std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs); From 4d0aece001739f9d2fd72b2b0e54fbc55b66c8e7 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 11 Dec 2023 00:05:41 +0000 Subject: [PATCH 06/10] Clarify variable name --- components/misc/resourcehelpers.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index b602001913..7386dceb9f 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -67,10 +67,10 @@ std::string Misc::ResourceHelpers::correctResourcePath( // Handle top level directory bool needsPrefix = true; - for (std::string_view alternativeDirectory : topLevelDirectories) + for (std::string_view potentialTopLevelDirectory : topLevelDirectories) { - if (correctedPath.starts_with(alternativeDirectory) && correctedPath.size() > alternativeDirectory.size() - && correctedPath[alternativeDirectory.size()] == '\\') + if (correctedPath.starts_with(potentialTopLevelDirectory) && correctedPath.size() > potentialTopLevelDirectory.size() + && correctedPath[potentialTopLevelDirectory.size()] == '\\') { needsPrefix = false; break; From db5a43db30fc1d1a05018be032d3aff55c3575df Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 24 Dec 2023 17:48:40 +0000 Subject: [PATCH 07/10] Allow top-level prefix to be found in the middle of a path --- components/misc/resourcehelpers.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 7386dceb9f..c9a3591046 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -75,6 +75,17 @@ std::string Misc::ResourceHelpers::correctResourcePath( needsPrefix = false; break; } + else + { + std::string topLevelPrefix = std::string{ potentialTopLevelDirectory } + '\\'; + size_t topLevelPos = correctedPath.find('\\' + topLevelPrefix); + if (topLevelPos != std::string::npos) + { + correctedPath.erase(0, topLevelPos + 1); + needsPrefix = false; + break; + } + } } if (needsPrefix) correctedPath = std::string{ topLevelDirectories.front() } + '\\' + correctedPath; From 1717e696b16ff852a8e274f0f0be8c1699084376 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 23 Feb 2024 00:06:51 +0000 Subject: [PATCH 08/10] Format before clang notices and sends me an angry email --- components/misc/resourcehelpers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index c9a3591046..119936f2ab 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -69,7 +69,8 @@ std::string Misc::ResourceHelpers::correctResourcePath( bool needsPrefix = true; for (std::string_view potentialTopLevelDirectory : topLevelDirectories) { - if (correctedPath.starts_with(potentialTopLevelDirectory) && correctedPath.size() > potentialTopLevelDirectory.size() + if (correctedPath.starts_with(potentialTopLevelDirectory) + && correctedPath.size() > potentialTopLevelDirectory.size() && correctedPath[potentialTopLevelDirectory.size()] == '\\') { needsPrefix = false; From 6406095bfb478a25c0831c41db7dfc1bd26a480e Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 23 Feb 2024 01:34:01 +0000 Subject: [PATCH 09/10] s p a n --- components/misc/resourcehelpers.cpp | 8 ++++---- components/misc/resourcehelpers.hpp | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 119936f2ab..4e7f7c41e3 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -47,7 +47,7 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) } std::string Misc::ResourceHelpers::correctResourcePath( - const std::vector& topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs) + std::span topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs) { /* Bethesda at some point converted all their BSA * textures from tga to dds for increased load speed, but all @@ -124,17 +124,17 @@ std::string Misc::ResourceHelpers::correctResourcePath( std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath({ "textures", "bookart" }, resPath, vfs); + return correctResourcePath({ { "textures", "bookart" } }, resPath, vfs); } std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath({ "icons" }, resPath, vfs); + return correctResourcePath({ { "icons" } }, resPath, vfs); } std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs) { - return correctResourcePath({ "bookart", "textures" }, resPath, vfs); + return correctResourcePath({ { "bookart", "textures" } }, resPath, vfs); } std::string Misc::ResourceHelpers::correctBookartPath( diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index c98840dd61..bd95f2376b 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -1,6 +1,7 @@ #ifndef MISC_RESOURCEHELPERS_H #define MISC_RESOURCEHELPERS_H +#include #include #include #include @@ -23,8 +24,8 @@ namespace Misc namespace ResourceHelpers { bool changeExtensionToDds(std::string& path); - std::string correctResourcePath(const std::vector& topLevelDirectories, - std::string_view resPath, const VFS::Manager* vfs); + std::string correctResourcePath( + std::span topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs); std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs); std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs); std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs); From 3fbd97ffc876cf776779db3e3b4cde6984b1cacb Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 23 Feb 2024 12:48:39 +0000 Subject: [PATCH 10/10] Remove unused header --- components/misc/resourcehelpers.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index bd95f2376b..a4d46f2611 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace VFS {