BACKENDS: Add function in FS Factory to map scummvm path to system path

In most cases they are the same, but in the case of a sandboxed filesystem,
they may be different. Mapping to the full system path allows using the
path with system functions, such as fopen() or third party libraries (for
example to pass a soundfont path to the fluidsynth library).
This commit is contained in:
Thierry Crozat
2023-11-20 23:18:08 +00:00
parent 95a060e4fe
commit ab13d18e58
3 changed files with 21 additions and 0 deletions
+10
View File
@@ -74,4 +74,14 @@ void ChRootFilesystemFactory::addVirtualDrive(const Common::String &name, const
_virtualDrives[name] = path;
}
Common::String ChRootFilesystemFactory::getSystemFullPath(const Common::String& path) const {
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 it->_value + path.substr(driveEnd);
}
return _root + path;
}
#endif
+2
View File
@@ -40,6 +40,8 @@ public:
void addVirtualDrive(const Common::String &name, const Common::String &path);
Common::String getSystemFullPath(const Common::String& path) const override;
private:
const Common::String _root;
Common::StringMap _virtualDrives;
+9
View File
@@ -63,6 +63,15 @@ public:
* On Windows, it will be a special node which "contains" all drives (C:, D:, E:).
*/
virtual AbstractFSNode *makeRootFileNode() const = 0;
/**
* Returns a path suitable for systen functions such as fopen() for the given ScummVM path,
*
* In most cases the returned path is the same as the given path, but it may be different, for
* example when the application is sandboxed and ScummVM path are relative to the saandbox
* root.
*/
virtual Common::String getSystemFullPath(const Common::String& path) const { return path; }
};
#endif /*FILESYSTEM_FACTORY_H*/