CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/FileSystems/DirectoryFileSystem.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819// TODO: Remove the Windows-specific code, FILE is fine there too.2021#include <map>2223#include "Common/File/Path.h"24#include "Core/FileSystems/FileSystem.h"2526#ifdef _WIN3227typedef void * HANDLE;28#endif2930struct DirectoryFileHandle {31enum Flags {32NORMAL,33SKIP_REPLAY,34};3536#ifdef _WIN3237HANDLE hFile = (HANDLE)-1;38#else39int hFile = -1;40#endif41s64 needsTrunc_ = -1;42bool replay_ = true;43bool inGameDir_ = false;44FileSystemFlags fileSystemFlags_ = (FileSystemFlags)0;4546DirectoryFileHandle() {}4748DirectoryFileHandle(Flags flags, FileSystemFlags fileSystemFlags)49: replay_(flags != SKIP_REPLAY), fileSystemFlags_(fileSystemFlags) {}5051Path GetLocalPath(const Path &basePath, std::string localpath) const;52bool Open(const Path &basePath, std::string &fileName, FileAccess access, u32 &err);53size_t Read(u8* pointer, s64 size);54size_t Write(const u8* pointer, s64 size);55size_t Seek(s32 position, FileMove type);56void Close();57};5859class DirectoryFileSystem : public IFileSystem {60public:61DirectoryFileSystem(IHandleAllocator *_hAlloc, const Path &_basePath, FileSystemFlags _flags = FileSystemFlags::NONE);62~DirectoryFileSystem();6364void CloseAll();6566void DoState(PointerWrap &p) override;67std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;68int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;69void CloseFile(u32 handle) override;70size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;71size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;72size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;73size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;74size_t SeekFile(u32 handle, s32 position, FileMove type) override;75PSPFileInfo GetFileInfo(std::string filename) override;76bool OwnsHandle(u32 handle) override;77int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;78PSPDevType DevType(u32 handle) override;7980bool MkDir(const std::string &dirname) override;81bool RmDir(const std::string &dirname) override;82int RenameFile(const std::string &from, const std::string &to) override;83bool RemoveFile(const std::string &filename) override;84FileSystemFlags Flags() override { return flags; }85u64 FreeSpace(const std::string &path) override;8687bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override;8889private:90struct OpenFileEntry {91DirectoryFileHandle hFile;92std::string guestFilename;93FileAccess access = FILEACCESS_NONE;94};9596typedef std::map<u32, OpenFileEntry> EntryMap;97EntryMap entries;98Path basePath;99IHandleAllocator *hAlloc;100FileSystemFlags flags;101102Path GetLocalPath(std::string internalPath) const;103};104105// VFSFileSystem: Ability to map in Android APK paths as well! Does not support all features, only meant for fonts.106// Very inefficient - always load the whole file on open.107class VFSFileSystem : public IFileSystem {108public:109VFSFileSystem(IHandleAllocator *_hAlloc, std::string _basePath);110~VFSFileSystem();111112void DoState(PointerWrap &p) override;113std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;114int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;115void CloseFile(u32 handle) override;116size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;117size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;118size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;119size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;120size_t SeekFile(u32 handle, s32 position, FileMove type) override;121PSPFileInfo GetFileInfo(std::string filename) override;122bool OwnsHandle(u32 handle) override;123int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;124PSPDevType DevType(u32 handle) override;125126bool MkDir(const std::string &dirname) override;127bool RmDir(const std::string &dirname) override;128int RenameFile(const std::string &from, const std::string &to) override;129bool RemoveFile(const std::string &filename) override;130FileSystemFlags Flags() override { return FileSystemFlags::FLASH; }131u64 FreeSpace(const std::string &path) override { return 0; }132133bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }134135private:136struct OpenFileEntry {137u8 *fileData;138size_t size;139size_t seekPos;140};141142typedef std::map<u32, OpenFileEntry> EntryMap;143EntryMap entries;144std::string basePath;145IHandleAllocator *hAlloc;146147std::string GetLocalPath(const std::string &localpath);148};149150151