BACKENDS: Add possibility to specify virtual drive in ChRootFilesystemFactory

It allows to get access to additional directories outside of the sandbox root.
This is used on iOS to access files in the app bundle.
This commit is contained in:
Thierry Crozat 2023-03-19 23:30:11 +00:00 committed by Eugene Sandulenko
parent 9bf4f3609a
commit 148892f102
No known key found for this signature in database
GPG key ID: 014D387312D34F08
5 changed files with 47 additions and 14 deletions

View file

@ -47,16 +47,31 @@ AbstractFSNode *ChRootFilesystemFactory::makeCurrentDirectoryFileNode() const {
return NULL;
}
if (Common::String(buf).hasPrefix(_root + Common::String("/"))) {
Common::String curPath(buf);
if (curPath.hasPrefix(_root + Common::String("/"))) {
return new ChRootFilesystemNode(_root, buf + _root.size());
}
for (auto it = _virtualDrives.begin() ; it != _virtualDrives.end() ; ++it) {
if (curPath.hasPrefix(it->_value + Common::String("/")))
return new ChRootFilesystemNode(it->_value, buf + it->_value.size(), it->_key);
}
return new ChRootFilesystemNode(_root, "/");
}
AbstractFSNode *ChRootFilesystemFactory::makeFileNodePath(const Common::String &path) const {
assert(!path.empty());
size_t driveEnd = path.findFirstOf('/');
if (driveEnd != Common::String::npos && driveEnd > 0) {
auto it = _virtualDrives.find(path.substr(0, driveEnd));
if (it != _virtualDrives.end())
return new ChRootFilesystemNode(it->_value, path.substr(driveEnd), it->_key);
}
return new ChRootFilesystemNode(_root, path);
}
void ChRootFilesystemFactory::addVirtualDrive(const Common::String &name, const Common::String &path) {
_virtualDrives[name] = path;
}
#endif