~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Core/FileSystems/MetaFileSystem.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012- PPSSPP Project.
 
2
 
 
3
// This program is free software: you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation, version 2.0 or later versions.
 
6
 
 
7
// This program is distributed in the hope that it will be useful,
 
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
// GNU General Public License 2.0 for more details.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#pragma once
 
19
 
 
20
#include <string>
 
21
#include <vector>
 
22
 
 
23
#include "base/mutex.h"
 
24
#include "Core/FileSystems/FileSystem.h"
 
25
 
 
26
class MetaFileSystem : public IHandleAllocator, public IFileSystem {
 
27
private:
 
28
        s32 current;
 
29
        struct MountPoint {
 
30
                std::string prefix;
 
31
                IFileSystem *system;
 
32
 
 
33
                bool operator == (const MountPoint &other) const {
 
34
                        return prefix == other.prefix && system == other.system;
 
35
                }
 
36
        };
 
37
 
 
38
        std::vector<MountPoint> fileSystems;
 
39
 
 
40
        typedef std::map<int, std::string> currentDir_t;
 
41
        currentDir_t currentDir;
 
42
 
 
43
        std::string startingDirectory;
 
44
        int lastOpenError;
 
45
        recursive_mutex lock;
 
46
 
 
47
public:
 
48
        MetaFileSystem() {
 
49
                current = 6;  // what?
 
50
        }
 
51
 
 
52
        void Mount(std::string prefix, IFileSystem *system);
 
53
        void Unmount(std::string prefix, IFileSystem *system);
 
54
        void Remount(IFileSystem *oldSystem, IFileSystem *newSystem);
 
55
 
 
56
        IFileSystem *GetSystem(const std::string &prefix);
 
57
        IFileSystem *GetSystemFromFilename(const std::string &filename);
 
58
 
 
59
        void ThreadEnded(int threadID);
 
60
 
 
61
        void Shutdown();
 
62
 
 
63
        u32 GetNewHandle() override {
 
64
                u32 res = current++;
 
65
                if (current < 0) {
 
66
                        current = 0;
 
67
                }
 
68
                return res;
 
69
        }
 
70
        void FreeHandle(u32 handle) override {}
 
71
 
 
72
        void DoState(PointerWrap &p) override;
 
73
 
 
74
        IFileSystem *GetHandleOwner(u32 handle);
 
75
        bool MapFilePath(const std::string &inpath, std::string &outpath, MountPoint **system);
 
76
 
 
77
        inline bool MapFilePath(const std::string &_inpath, std::string &outpath, IFileSystem **system) {
 
78
                MountPoint *mountPoint;
 
79
                if (MapFilePath(_inpath, outpath, &mountPoint)) {
 
80
                        *system = mountPoint->system;
 
81
                        return true;
 
82
                }
 
83
 
 
84
                return false;
 
85
        }
 
86
 
 
87
        std::string NormalizePrefix(std::string prefix) const;
 
88
 
 
89
        // Only possible if a file system is a DirectoryFileSystem or similar.
 
90
        bool GetHostPath(const std::string &inpath, std::string &outpath) override;
 
91
 
 
92
        std::vector<PSPFileInfo> GetDirListing(std::string path) override;
 
93
        u32      OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override;
 
94
        u32      OpenWithError(int &error, std::string filename, FileAccess access, const char *devicename = NULL);
 
95
        void     CloseFile(u32 handle) override;
 
96
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size) override;
 
97
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
 
98
        size_t   WriteFile(u32 handle, const u8 *pointer, s64 size) override;
 
99
        size_t   WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
 
100
        size_t   SeekFile(u32 handle, s32 position, FileMove type) override;
 
101
        PSPFileInfo GetFileInfo(std::string filename) override;
 
102
        bool     OwnsHandle(u32 handle) override { return false; }
 
103
        inline size_t GetSeekPos(u32 handle)
 
104
        {
 
105
                return SeekFile(handle, 0, FILEMOVE_CURRENT);
 
106
        }
 
107
 
 
108
        virtual int ChDir(const std::string &dir);
 
109
 
 
110
        bool MkDir(const std::string &dirname) override;
 
111
        bool RmDir(const std::string &dirname) override;
 
112
        int  RenameFile(const std::string &from, const std::string &to) override;
 
113
        bool RemoveFile(const std::string &filename) override;
 
114
        int  Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
 
115
        int  DevType(u32 handle) override;
 
116
        int  Flags() override { return 0; }
 
117
        u64  FreeSpace(const std::string &path) override;
 
118
 
 
119
        // Convenience helper - returns < 0 on failure.
 
120
        int ReadEntireFile(const std::string &filename, std::vector<u8> &data);
 
121
 
 
122
        void SetStartingDirectory(const std::string &dir) {
 
123
                lock_guard guard(lock);
 
124
                startingDirectory = dir;
 
125
        }
 
126
};