Added MappingFileSystemAdapter and adjusted some more stuff in the VFS module.

This commit is contained in:
2025-03-02 18:41:04 +01:00
parent 8f2cee4968
commit 6407c5ca09
6 changed files with 248 additions and 36 deletions

View File

@@ -30,24 +30,6 @@ namespace mijin
// public functions
//
std::vector<fs::path> StackedFileSystemAdapter::getRoots()
{
std::vector<fs::path> roots;
for (auto& adapter : adapters_)
{
for (const fs::path& root : adapter->getRoots())
{
auto it = std::find(roots.begin(), roots.end(), root);
if (it == roots.end()) {
roots.push_back(root);
}
}
}
return roots;
}
fs::path StackedFileSystemAdapter::getHomeFolder()
{
if (adapters_.empty()) {
@@ -105,13 +87,28 @@ Optional<fs::path> StackedFileSystemAdapter::getNativePath(const fs::path& file)
StreamError StackedFileSystemAdapter::open(const fs::path& path, FileOpenMode mode, std::unique_ptr<Stream>& outStream)
{
// try to open existing files first
for (auto& adapter : adapters_)
{
const FileInfo fileInfo = adapter->getFileInfo(path);
if (fileInfo.exists) {
if (fileInfo.exists)
{
return adapter->open(path, mode, outStream);
}
}
// if that doesn't work we attempt to write, try creating it
if (mode == FileOpenMode::WRITE || mode == FileOpenMode::READ_WRITE)
{
for (auto& adapter : adapters_)
{
const StreamError error = adapter->open(path, mode, outStream);
if (error == StreamError::SUCCESS)
{
return StreamError::SUCCESS;
}
}
}
return StreamError::IO_ERROR;
}