mirror of
https://github.com/scummvm/scummvm.git
synced 2026-05-21 05:40:43 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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*/
|
||||
|
||||
Reference in New Issue
Block a user