2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// TODO: Remove the Windows-specific code, FILE is fine there too.
|
|
|
|
|
|
|
|
#include <map>
|
2021-05-05 23:31:38 +00:00
|
|
|
|
|
|
|
#include "Common/File/Path.h"
|
2020-05-22 00:57:41 +00:00
|
|
|
#include "Core/FileSystems/FileSystem.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
typedef void * HANDLE;
|
|
|
|
#endif
|
|
|
|
|
2018-04-17 14:51:49 +00:00
|
|
|
struct DirectoryFileHandle {
|
|
|
|
enum Flags {
|
|
|
|
NORMAL,
|
|
|
|
SKIP_REPLAY,
|
|
|
|
};
|
2014-02-15 08:59:54 +00:00
|
|
|
|
2013-07-24 20:49:45 +00:00
|
|
|
#ifdef _WIN32
|
2018-04-17 14:51:49 +00:00
|
|
|
HANDLE hFile = (HANDLE)-1;
|
2013-07-24 20:49:45 +00:00
|
|
|
#else
|
2018-04-17 14:51:49 +00:00
|
|
|
int hFile = -1;
|
2013-07-24 20:49:45 +00:00
|
|
|
#endif
|
2018-04-17 14:51:49 +00:00
|
|
|
s64 needsTrunc_ = -1;
|
|
|
|
bool replay_ = true;
|
2019-07-05 04:00:14 +00:00
|
|
|
bool inGameDir_ = false;
|
2021-07-24 16:16:12 +00:00
|
|
|
FileSystemFlags fileSystemFlags_ = (FileSystemFlags)0;
|
2018-04-17 14:51:49 +00:00
|
|
|
|
2021-07-24 16:16:12 +00:00
|
|
|
DirectoryFileHandle() {}
|
2013-07-24 20:49:45 +00:00
|
|
|
|
2021-07-24 16:16:12 +00:00
|
|
|
DirectoryFileHandle(Flags flags, FileSystemFlags fileSystemFlags)
|
|
|
|
: replay_(flags != SKIP_REPLAY), fileSystemFlags_(fileSystemFlags) {}
|
|
|
|
|
|
|
|
Path GetLocalPath(const Path &basePath, std::string localpath) const;
|
2021-05-05 23:31:38 +00:00
|
|
|
bool Open(const Path &basePath, std::string &fileName, FileAccess access, u32 &err);
|
2013-07-24 20:49:45 +00:00
|
|
|
size_t Read(u8* pointer, s64 size);
|
|
|
|
size_t Write(const u8* pointer, s64 size);
|
|
|
|
size_t Seek(s32 position, FileMove type);
|
|
|
|
void Close();
|
2013-07-28 06:46:26 +00:00
|
|
|
};
|
2013-07-24 20:49:45 +00:00
|
|
|
|
2012-12-26 07:24:19 +00:00
|
|
|
class DirectoryFileSystem : public IFileSystem {
|
2012-11-01 15:19:01 +00:00
|
|
|
public:
|
2021-05-05 23:31:38 +00:00
|
|
|
DirectoryFileSystem(IHandleAllocator *_hAlloc, const Path &_basePath, FileSystemFlags _flags = FileSystemFlags::NONE);
|
2012-12-26 07:24:19 +00:00
|
|
|
~DirectoryFileSystem();
|
|
|
|
|
2013-12-29 07:43:02 +00:00
|
|
|
void CloseAll();
|
|
|
|
|
2014-12-08 20:14:35 +00:00
|
|
|
void DoState(PointerWrap &p) override;
|
|
|
|
std::vector<PSPFileInfo> GetDirListing(std::string path) override;
|
2019-10-20 18:03:37 +00:00
|
|
|
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
void CloseFile(u32 handle) override;
|
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
|
2013-12-28 00:36:51 +00:00
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
|
2013-12-28 00:36:51 +00:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
size_t SeekFile(u32 handle, s32 position, FileMove type) override;
|
|
|
|
PSPFileInfo GetFileInfo(std::string filename) override;
|
|
|
|
bool OwnsHandle(u32 handle) override;
|
|
|
|
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
|
2020-05-22 00:57:41 +00:00
|
|
|
PSPDevType DevType(u32 handle) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
|
|
|
|
bool MkDir(const std::string &dirname) override;
|
|
|
|
bool RmDir(const std::string &dirname) override;
|
|
|
|
int RenameFile(const std::string &from, const std::string &to) override;
|
|
|
|
bool RemoveFile(const std::string &filename) override;
|
2020-05-21 22:55:25 +00:00
|
|
|
FileSystemFlags Flags() override { return flags; }
|
2014-11-01 06:48:08 +00:00
|
|
|
u64 FreeSpace(const std::string &path) override;
|
2012-12-26 07:24:19 +00:00
|
|
|
|
2021-09-11 15:50:07 +00:00
|
|
|
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override;
|
2021-09-11 15:18:39 +00:00
|
|
|
|
2012-12-26 07:24:19 +00:00
|
|
|
private:
|
|
|
|
struct OpenFileEntry {
|
2021-07-24 16:16:12 +00:00
|
|
|
DirectoryFileHandle hFile;
|
2013-12-29 07:43:02 +00:00
|
|
|
std::string guestFilename;
|
2021-07-18 14:00:07 +00:00
|
|
|
FileAccess access = FILEACCESS_NONE;
|
2012-12-26 07:24:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<u32, OpenFileEntry> EntryMap;
|
|
|
|
EntryMap entries;
|
2021-05-05 23:31:38 +00:00
|
|
|
Path basePath;
|
2012-12-26 07:24:19 +00:00
|
|
|
IHandleAllocator *hAlloc;
|
2020-05-21 22:55:25 +00:00
|
|
|
FileSystemFlags flags;
|
2021-07-24 16:16:12 +00:00
|
|
|
|
|
|
|
Path GetLocalPath(std::string internalPath) const;
|
2013-07-24 20:49:45 +00:00
|
|
|
};
|
|
|
|
|
2013-02-26 23:59:30 +00:00
|
|
|
// VFSFileSystem: Ability to map in Android APK paths as well! Does not support all features, only meant for fonts.
|
|
|
|
// Very inefficient - always load the whole file on open.
|
|
|
|
class VFSFileSystem : public IFileSystem {
|
|
|
|
public:
|
|
|
|
VFSFileSystem(IHandleAllocator *_hAlloc, std::string _basePath);
|
|
|
|
~VFSFileSystem();
|
|
|
|
|
2014-12-08 20:14:35 +00:00
|
|
|
void DoState(PointerWrap &p) override;
|
|
|
|
std::vector<PSPFileInfo> GetDirListing(std::string path) override;
|
2019-10-20 18:03:37 +00:00
|
|
|
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
void CloseFile(u32 handle) override;
|
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
|
2013-12-28 00:36:51 +00:00
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
|
2013-12-28 00:36:51 +00:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
size_t SeekFile(u32 handle, s32 position, FileMove type) override;
|
|
|
|
PSPFileInfo GetFileInfo(std::string filename) override;
|
|
|
|
bool OwnsHandle(u32 handle) override;
|
|
|
|
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
|
2020-05-22 00:57:41 +00:00
|
|
|
PSPDevType DevType(u32 handle) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
|
|
|
|
bool MkDir(const std::string &dirname) override;
|
|
|
|
bool RmDir(const std::string &dirname) override;
|
|
|
|
int RenameFile(const std::string &from, const std::string &to) override;
|
|
|
|
bool RemoveFile(const std::string &filename) override;
|
2020-05-21 23:10:08 +00:00
|
|
|
FileSystemFlags Flags() override { return FileSystemFlags::FLASH; }
|
2014-11-01 06:48:08 +00:00
|
|
|
u64 FreeSpace(const std::string &path) override { return 0; }
|
2013-02-26 23:59:30 +00:00
|
|
|
|
2021-09-11 15:18:39 +00:00
|
|
|
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
|
|
|
|
|
2013-02-26 23:59:30 +00:00
|
|
|
private:
|
|
|
|
struct OpenFileEntry {
|
|
|
|
u8 *fileData;
|
|
|
|
size_t size;
|
|
|
|
size_t seekPos;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<u32, OpenFileEntry> EntryMap;
|
|
|
|
EntryMap entries;
|
|
|
|
std::string basePath;
|
|
|
|
IHandleAllocator *hAlloc;
|
|
|
|
|
|
|
|
std::string GetLocalPath(std::string localpath);
|
|
|
|
};
|