mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-27 16:23:35 +01:00
Cleanup the ownership model in MetaFileSystem.
The old one was error-prone spaghetti.
This commit is contained in:
1 parent
868f5f6189
commit
9ae00b80b1
6 files changed
+73
-89
No files matched your search
@@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
#include "Core/FileSystems/FileSystem.h"
|
||||
|
||||
@@ -28,13 +29,14 @@ private:
|
||||
s32 current;
|
||||
struct MountPoint {
|
||||
std::string prefix;
|
||||
IFileSystem *system;
|
||||
std::shared_ptr<IFileSystem> system;
|
||||
|
||||
bool operator == (const MountPoint &other) const {
|
||||
return prefix == other.prefix && system == other.system;
|
||||
}
|
||||
};
|
||||
|
||||
// The order of this vector is meaningful - lookups are always a linear search from the start.
|
||||
std::vector<MountPoint> fileSystems;
|
||||
|
||||
typedef std::map<int, std::string> currentDir_t;
|
||||
@@ -43,26 +45,34 @@ private:
|
||||
std::string startingDirectory;
|
||||
std::recursive_mutex lock; // must be recursive
|
||||
|
||||
public:
|
||||
MetaFileSystem() {
|
||||
void Reset() {
|
||||
// This used to be 6, probably an attempt to replicate PSP handles.
|
||||
// However, that's an artifact of using psplink anyway...
|
||||
current = 1;
|
||||
startingDirectory.clear();
|
||||
}
|
||||
|
||||
void Mount(std::string prefix, IFileSystem *system);
|
||||
void Unmount(std::string prefix, IFileSystem *system);
|
||||
void Remount(std::string prefix, IFileSystem *newSystem);
|
||||
public:
|
||||
MetaFileSystem() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Mount(std::string prefix, std::shared_ptr<IFileSystem> system);
|
||||
// Fails if there's not already a file system at prefix.
|
||||
bool Remount(std::string prefix, std::shared_ptr<IFileSystem> system);
|
||||
|
||||
void UnmountAll();
|
||||
|
||||
// The pointer returned from these are for temporary usage only. Do not store.
|
||||
IFileSystem *GetSystem(const std::string &prefix);
|
||||
IFileSystem *GetSystemFromFilename(const std::string &filename);
|
||||
IFileSystem *GetHandleOwner(u32 handle);
|
||||
FileSystemFlags FlagsFromFilename(const std::string &filename) {
|
||||
IFileSystem *sys = GetSystemFromFilename(filename);
|
||||
return sys ? sys->Flags() : FileSystemFlags::NONE;
|
||||
}
|
||||
|
||||
void ThreadEnded(int threadID);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
u32 GetNewHandle() override {
|
||||
@@ -77,14 +87,13 @@ public:
|
||||
|
||||
void DoState(PointerWrap &p) override;
|
||||
|
||||
IFileSystem *GetHandleOwner(u32 handle);
|
||||
int MapFilePath(const std::string &inpath, std::string &outpath, MountPoint **system);
|
||||
|
||||
inline int MapFilePath(const std::string &_inpath, std::string &outpath, IFileSystem **system) {
|
||||
MountPoint *mountPoint;
|
||||
int error = MapFilePath(_inpath, outpath, &mountPoint);
|
||||
if (error == 0) {
|
||||
*system = mountPoint->system;
|
||||
*system = mountPoint->system.get();
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user