mirror of
https://github.com/izzy2lost/ppsspp.git
synced 2026-03-10 12:43:04 -07:00
105 lines
3.6 KiB
C
105 lines
3.6 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
// Like DirectoryFileSystem, but uses the Android Storage Access Framework
|
||
|
|
// to access a folder tree as if it was a PSP file system.
|
||
|
|
// Unfortunately we cannot implement all the semantics like this, let's see
|
||
|
|
// how good we can get it though.
|
||
|
|
|
||
|
|
// 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
|
||
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
||
|
|
|
||
|
|
// 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
|
||
|
|
|
||
|
|
#include "ppsspp_config.h"
|
||
|
|
|
||
|
|
#include <map>
|
||
|
|
|
||
|
|
#include "android/jni/AndroidContentURI.h"
|
||
|
|
|
||
|
|
#include "Core/FileSystems/FileSystem.h"
|
||
|
|
#include "Core/FileSystems/AndroidStorageFileSystem.h"
|
||
|
|
|
||
|
|
struct AndroidDirectoryFileHandle {
|
||
|
|
enum Flags {
|
||
|
|
NORMAL,
|
||
|
|
SKIP_REPLAY,
|
||
|
|
};
|
||
|
|
|
||
|
|
int hFile = -1;
|
||
|
|
s64 needsTrunc_ = -1;
|
||
|
|
bool replay_ = true;
|
||
|
|
bool inGameDir_ = false;
|
||
|
|
|
||
|
|
AndroidDirectoryFileHandle(Flags flags) : replay_(flags != SKIP_REPLAY) { }
|
||
|
|
|
||
|
|
// std::string GetLocalPath(const std::string &basePath, std::string localpath);
|
||
|
|
bool Open(const std::string &basePath, std::string &fileName, FileAccess access, u32 &err);
|
||
|
|
size_t Read(u8* pointer, s64 size);
|
||
|
|
size_t Write(const u8* pointer, s64 size);
|
||
|
|
size_t Seek(s32 position, FileMove type);
|
||
|
|
void Close();
|
||
|
|
};
|
||
|
|
|
||
|
|
class AndroidStorageFileSystem : public IFileSystem {
|
||
|
|
public:
|
||
|
|
AndroidStorageFileSystem(IHandleAllocator *_hAlloc, std::string basePath, FileSystemFlags _flags = FileSystemFlags::NONE);
|
||
|
|
~AndroidStorageFileSystem();
|
||
|
|
|
||
|
|
void CloseAll();
|
||
|
|
|
||
|
|
void DoState(PointerWrap &p) override;
|
||
|
|
std::vector<PSPFileInfo> GetDirListing(std::string path) override;
|
||
|
|
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;
|
||
|
|
void CloseFile(u32 handle) override;
|
||
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
|
||
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
|
||
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
|
||
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
|
||
|
|
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;
|
||
|
|
PSPDevType DevType(u32 handle) override;
|
||
|
|
|
||
|
|
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;
|
||
|
|
FileSystemFlags Flags() override { return flags; }
|
||
|
|
u64 FreeSpace(const std::string &path) override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
struct OpenFileEntry {
|
||
|
|
std::string guestFilename;
|
||
|
|
FileAccess access;
|
||
|
|
AndroidDirectoryFileHandle hFile = AndroidDirectoryFileHandle::NORMAL;
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef std::map<u32, OpenFileEntry> EntryMap;
|
||
|
|
EntryMap entries;
|
||
|
|
|
||
|
|
AndroidStorageContentURI baseContentUri;
|
||
|
|
|
||
|
|
std::string basePath;
|
||
|
|
IHandleAllocator *hAlloc;
|
||
|
|
FileSystemFlags flags;
|
||
|
|
|
||
|
|
// Actually, builds a content URI.
|
||
|
|
std::string GetLocalPath(std::string localpath);
|
||
|
|
};
|
||
|
|
|