Added MappingFileSystemAdapter and adjusted some more stuff in the VFS module.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user