mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 13:09:42 +00:00
Merge branch 'vfs_normalized_path_4' into 'master'
Use VFS::Path::Normalized in few more places See merge request OpenMW/openmw!3934
This commit is contained in:
commit
3cb8d05fe5
7 changed files with 50 additions and 22 deletions
|
@ -328,7 +328,8 @@ namespace MWLua
|
|||
},
|
||||
[](const sol::object&) -> sol::object { return sol::nil; });
|
||||
|
||||
api["fileExists"] = [vfs](std::string_view fileName) -> bool { return vfs->exists(fileName); };
|
||||
api["fileExists"]
|
||||
= [vfs](std::string_view fileName) -> bool { return vfs->exists(VFS::Path::Normalized(fileName)); };
|
||||
api["pathsWithPrefix"] = [vfs](std::string_view prefix) {
|
||||
auto iterator = vfs->getRecursiveDirectoryIterator(prefix);
|
||||
return sol::as_function([iterator, current = iterator.begin()]() mutable -> sol::optional<std::string> {
|
||||
|
|
|
@ -72,6 +72,13 @@ namespace VFS::Path
|
|||
EXPECT_EQ(value.value(), "foo/bar/baz");
|
||||
}
|
||||
|
||||
TEST(NormalizedTest, shouldSupportOperatorDivEqualWithStringView)
|
||||
{
|
||||
Normalized value("foo/bar");
|
||||
value /= std::string_view("BAZ");
|
||||
EXPECT_EQ(value.value(), "foo/bar/baz");
|
||||
}
|
||||
|
||||
TEST(NormalizedTest, changeExtensionShouldReplaceAfterLastDot)
|
||||
{
|
||||
Normalized value("foo/bar.a");
|
||||
|
|
|
@ -37,11 +37,22 @@ namespace
|
|||
|
||||
namespace fx
|
||||
{
|
||||
namespace
|
||||
{
|
||||
VFS::Path::Normalized makeFilePath(std::string_view name)
|
||||
{
|
||||
std::string fileName(name);
|
||||
fileName += Technique::sExt;
|
||||
VFS::Path::Normalized result(Technique::sSubdir);
|
||||
result /= fileName;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Technique::Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width,
|
||||
int height, bool ubo, bool supportsNormals)
|
||||
: mName(std::move(name))
|
||||
, mFileName(Files::pathToUnicodeString(
|
||||
(Files::pathFromUnicodeString(Technique::sSubdir) / (mName + Technique::sExt))))
|
||||
, mFilePath(makeFilePath(mName))
|
||||
, mLastModificationTime(std::filesystem::file_time_type::clock::now())
|
||||
, mWidth(width)
|
||||
, mHeight(height)
|
||||
|
@ -98,9 +109,9 @@ namespace fx
|
|||
{
|
||||
clear();
|
||||
|
||||
if (!mVFS.exists(mFileName))
|
||||
if (!mVFS.exists(mFilePath))
|
||||
{
|
||||
Log(Debug::Error) << "Could not load technique, file does not exist '" << mFileName << "'";
|
||||
Log(Debug::Error) << "Could not load technique, file does not exist '" << mFilePath << "'";
|
||||
|
||||
mStatus = Status::File_Not_exists;
|
||||
return false;
|
||||
|
@ -167,7 +178,7 @@ namespace fx
|
|||
mStatus = Status::Parse_Error;
|
||||
|
||||
mLastError = "Failed parsing technique '" + getName() + "' " + e.what();
|
||||
;
|
||||
|
||||
Log(Debug::Error) << mLastError;
|
||||
}
|
||||
|
||||
|
@ -179,11 +190,6 @@ namespace fx
|
|||
return mName;
|
||||
}
|
||||
|
||||
std::string Technique::getFileName() const
|
||||
{
|
||||
return mFileName;
|
||||
}
|
||||
|
||||
bool Technique::setLastModificationTime(std::filesystem::file_time_type timeStamp)
|
||||
{
|
||||
const bool isDirty = timeStamp != mLastModificationTime;
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <osg/StateSet>
|
||||
#include <osg/Texture2D>
|
||||
|
||||
#include <components/vfs/pathutil.hpp>
|
||||
|
||||
#include "lexer.hpp"
|
||||
#include "pass.hpp"
|
||||
#include "types.hpp"
|
||||
|
@ -103,8 +105,8 @@ namespace fx
|
|||
using UniformMap = std::vector<std::shared_ptr<Types::UniformBase>>;
|
||||
using RenderTargetMap = std::unordered_map<std::string_view, Types::RenderTarget>;
|
||||
|
||||
inline static std::string sExt = ".omwfx";
|
||||
inline static std::string sSubdir = "shaders";
|
||||
static constexpr std::string_view sExt = ".omwfx";
|
||||
static constexpr std::string_view sSubdir = "shaders";
|
||||
|
||||
enum class Status
|
||||
{
|
||||
|
@ -128,7 +130,7 @@ namespace fx
|
|||
|
||||
std::string getName() const;
|
||||
|
||||
std::string getFileName() const;
|
||||
const VFS::Path::Normalized& getFileName() const { return mFilePath; }
|
||||
|
||||
bool setLastModificationTime(std::filesystem::file_time_type timeStamp);
|
||||
|
||||
|
@ -251,7 +253,7 @@ namespace fx
|
|||
|
||||
std::string mShared;
|
||||
std::string mName;
|
||||
std::string mFileName;
|
||||
VFS::Path::Normalized mFilePath;
|
||||
std::string_view mBlockName;
|
||||
std::string_view mAuthor;
|
||||
std::string_view mDescription;
|
||||
|
|
|
@ -36,11 +36,13 @@ namespace l10n
|
|||
|
||||
void Manager::readLangData(const std::string& name, MessageBundles& ctx, const icu::Locale& lang)
|
||||
{
|
||||
std::string path = "l10n/";
|
||||
path.append(name);
|
||||
path.append("/");
|
||||
path.append(lang.getName());
|
||||
path.append(".yaml");
|
||||
std::string langName(lang.getName());
|
||||
langName += ".yaml";
|
||||
|
||||
VFS::Path::Normalized path("l10n");
|
||||
path /= name;
|
||||
path /= langName;
|
||||
|
||||
if (!mVFS->exists(path))
|
||||
return;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Resource
|
|||
static bool collectStatUpdate = false;
|
||||
static bool collectStatEngine = false;
|
||||
|
||||
constexpr std::string_view sFontName = "Fonts/DejaVuLGCSansMono.ttf";
|
||||
static const VFS::Path::Normalized sFontName("Fonts/DejaVuLGCSansMono.ttf");
|
||||
|
||||
static void setupStatCollection()
|
||||
{
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace VFS::Path
|
|||
public:
|
||||
Normalized() = default;
|
||||
|
||||
Normalized(std::string_view value)
|
||||
explicit Normalized(std::string_view value)
|
||||
: mValue(normalizeFilename(value))
|
||||
{
|
||||
}
|
||||
|
@ -187,6 +187,16 @@ namespace VFS::Path
|
|||
return *this;
|
||||
}
|
||||
|
||||
Normalized& operator/=(std::string_view value)
|
||||
{
|
||||
mValue.reserve(mValue.size() + value.size() + 1);
|
||||
mValue += separator;
|
||||
const std::size_t offset = mValue.size();
|
||||
mValue += value;
|
||||
normalizeFilenameInPlace(mValue.begin() + offset, mValue.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator==(const Normalized& lhs, const Normalized& rhs) = default;
|
||||
|
||||
friend bool operator==(const Normalized& lhs, const auto& rhs) { return lhs.mValue == rhs; }
|
||||
|
|
Loading…
Reference in a new issue