Replace std::filesystem::path by std::string and std::string_view in nif code

It's used only for error reporting.
fix-osga-rotate-wildly
elsid 3 months ago
parent cd3c3ebadb
commit 79b73e45a1
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -65,10 +65,10 @@ void readNIF(
std::cout << " from '" << Files::pathToUnicodeString(isBSA(source) ? source.filename() : source) << "'"; std::cout << " from '" << Files::pathToUnicodeString(isBSA(source) ? source.filename() : source) << "'";
std::cout << std::endl; std::cout << std::endl;
} }
std::filesystem::path fullPath = !source.empty() ? source / path : path; const std::filesystem::path fullPath = !source.empty() ? source / path : path;
try try
{ {
Nif::NIFFile file(fullPath); Nif::NIFFile file(Files::pathToUnicodeString(fullPath));
Nif::Reader reader(file, nullptr); Nif::Reader reader(file, nullptr);
if (vfs != nullptr) if (vfs != nullptr)
reader.parse(vfs->get(pathStr)); reader.parse(vfs->get(pathStr));

@ -1,18 +1,21 @@
#ifndef OPENMW_COMPONENTS_NIF_EXCEPTION_HPP #ifndef OPENMW_COMPONENTS_NIF_EXCEPTION_HPP
#define OPENMW_COMPONENTS_NIF_EXCEPTION_HPP #define OPENMW_COMPONENTS_NIF_EXCEPTION_HPP
#include <filesystem>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <components/files/conversion.hpp>
namespace Nif namespace Nif
{ {
struct Exception : std::runtime_error struct Exception : std::runtime_error
{ {
explicit Exception(const std::string& message, const std::filesystem::path& path) explicit Exception(std::string_view message, std::string_view path)
: std::runtime_error("NIFFile Error: " + message + " when reading " + Files::pathToUnicodeString(path)) : std::runtime_error([&] {
std::string result = "NIFFile Error: ";
result += message;
result += " when reading ";
result += path;
return result;
}())
{ {
} }
}; };

@ -4,7 +4,7 @@
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP #define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
#include <atomic> #include <atomic>
#include <filesystem> #include <cstdint>
#include <vector> #include <vector>
#include <components/files/istreamptr.hpp> #include <components/files/istreamptr.hpp>
@ -45,7 +45,7 @@ namespace Nif
std::uint32_t mBethVersion = 0; std::uint32_t mBethVersion = 0;
/// File name, used for error messages and opening the file /// File name, used for error messages and opening the file
std::filesystem::path mPath; std::string mPath;
std::string mHash; std::string mHash;
/// Record list /// Record list
@ -56,7 +56,7 @@ namespace Nif
bool mUseSkinning = false; bool mUseSkinning = false;
explicit NIFFile(const std::filesystem::path& path) explicit NIFFile(std::string_view path)
: mPath(path) : mPath(path)
{ {
} }
@ -77,7 +77,7 @@ namespace Nif
std::size_t numRoots() const { return mFile->mRoots.size(); } std::size_t numRoots() const { return mFile->mRoots.size(); }
/// Get the name of the file /// Get the name of the file
const std::filesystem::path& getFilename() const { return mFile->mPath; } const std::string& getFilename() const { return mFile->mPath; }
const std::string& getHash() const { return mFile->mHash; } const std::string& getHash() const { return mFile->mHash; }
@ -104,7 +104,7 @@ namespace Nif
std::uint32_t& mBethVersion; std::uint32_t& mBethVersion;
/// File name, used for error messages and opening the file /// File name, used for error messages and opening the file
std::filesystem::path& mFilename; std::string_view mFilename;
std::string& mHash; std::string& mHash;
/// Record list /// Record list
@ -144,7 +144,7 @@ namespace Nif
void setUseSkinning(bool skinning); void setUseSkinning(bool skinning);
/// Get the name of the file /// Get the name of the file
std::filesystem::path getFilename() const { return mFilename; } std::string_view getFilename() const { return mFilename; }
/// Get the version of the NIF format used /// Get the version of the NIF format used
std::uint32_t getVersion() const { return mVersion; } std::uint32_t getVersion() const { return mVersion; }

@ -50,7 +50,7 @@ namespace NifBullet
if (node) if (node)
roots.emplace_back(node); roots.emplace_back(node);
} }
mShape->mFileName = Files::pathToUnicodeString(nif.getFilename()); mShape->mFileName = nif.getFilename();
if (roots.empty()) if (roots.empty())
{ {
warn("Found no root nodes in NIF file " + mShape->mFileName); warn("Found no root nodes in NIF file " + mShape->mFileName);

Loading…
Cancel
Save