Io: Track whether the game is on a UMD or storage.

This commit is contained in:
Unknown W. Brackets 2020-05-21 16:10:08 -07:00
parent 67416e5919
commit c829ccb87d
10 changed files with 26 additions and 15 deletions

View file

@ -44,7 +44,7 @@ public:
bool OwnsHandle(u32 handle) override; bool OwnsHandle(u32 handle) override;
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override; int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
int DevType(u32 handle) override; int DevType(u32 handle) override;
FileSystemFlags Flags() override { return FileSystemFlags::NONE; } FileSystemFlags Flags() override { return FileSystemFlags::FLASH; }
bool MkDir(const std::string &dirname) override; bool MkDir(const std::string &dirname) override;
bool RmDir(const std::string &dirname) override; bool RmDir(const std::string &dirname) override;

View file

@ -45,6 +45,7 @@ public:
} }
int GetBlockSize() const { return 2048;} // forced, it cannot be changed by subclasses int GetBlockSize() const { return 2048;} // forced, it cannot be changed by subclasses
virtual u32 GetNumBlocks() = 0; virtual u32 GetNumBlocks() = 0;
virtual bool IsDisc() = 0;
u32 CalculateCRC(); u32 CalculateCRC();
void NotifyReadError(); void NotifyReadError();
@ -60,6 +61,7 @@ public:
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override; bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override; bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
u32 GetNumBlocks() override { return numBlocks; } u32 GetNumBlocks() override { return numBlocks; }
bool IsDisc() override { return true; }
private: private:
FileLoader *fileLoader_; FileLoader *fileLoader_;
@ -83,6 +85,7 @@ public:
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override; bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override; bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
u32 GetNumBlocks() override {return (u32)(filesize_ / GetBlockSize());} u32 GetNumBlocks() override {return (u32)(filesize_ / GetBlockSize());}
bool IsDisc() override { return true; }
private: private:
FileLoader *fileLoader_; FileLoader *fileLoader_;
@ -107,6 +110,7 @@ public:
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override; bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
u32 GetNumBlocks() override {return (u32)lbaSize;} u32 GetNumBlocks() override {return (u32)lbaSize;}
bool IsDisc() override { return false; }
private: private:
FileLoader *fileLoader_; FileLoader *fileLoader_;

View file

@ -154,7 +154,7 @@ public:
int RenameFile(const std::string &from, const std::string &to) override; int RenameFile(const std::string &from, const std::string &to) override;
bool RemoveFile(const std::string &filename) override; bool RemoveFile(const std::string &filename) override;
bool GetHostPath(const std::string &inpath, std::string &outpath) override; bool GetHostPath(const std::string &inpath, std::string &outpath) override;
FileSystemFlags Flags() override { return FileSystemFlags::NONE; } FileSystemFlags Flags() override { return FileSystemFlags::FLASH; }
u64 FreeSpace(const std::string &path) override { return 0; } u64 FreeSpace(const std::string &path) override { return 0; }
private: private:

View file

@ -53,6 +53,9 @@ enum DevType {
enum class FileSystemFlags { enum class FileSystemFlags {
NONE = 0, NONE = 0,
SIMULATE_FAT32 = 1, SIMULATE_FAT32 = 1,
UMD = 2,
CARD = 4,
FLASH = 8,
}; };
inline FileSystemFlags operator |(const FileSystemFlags &lhs, const FileSystemFlags &rhs) { inline FileSystemFlags operator |(const FileSystemFlags &lhs, const FileSystemFlags &rhs) {

View file

@ -467,6 +467,12 @@ int ISOFileSystem::DevType(u32 handle)
return iter->second.isBlockSectorMode ? PSP_DEV_TYPE_BLOCK : PSP_DEV_TYPE_FILE; return iter->second.isBlockSectorMode ? PSP_DEV_TYPE_BLOCK : PSP_DEV_TYPE_FILE;
} }
FileSystemFlags ISOFileSystem::Flags() {
// TODO: Here may be a good place to force things, in case users recompress games
// as PBP or CSO when they were originally the other type.
return blockDevice->IsDisc() ? FileSystemFlags::UMD : FileSystemFlags::CARD;
}
size_t ISOFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) size_t ISOFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
{ {
int ignored; int ignored;

View file

@ -42,7 +42,7 @@ public:
bool OwnsHandle(u32 handle) override; bool OwnsHandle(u32 handle) override;
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override; int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
int DevType(u32 handle) override; int DevType(u32 handle) override;
FileSystemFlags Flags() override { return FileSystemFlags::NONE; } FileSystemFlags Flags() override;
u64 FreeSpace(const std::string &path) override { return 0; } u64 FreeSpace(const std::string &path) override { return 0; }
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override; size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;

View file

@ -56,6 +56,10 @@ public:
IFileSystem *GetSystem(const std::string &prefix); IFileSystem *GetSystem(const std::string &prefix);
IFileSystem *GetSystemFromFilename(const std::string &filename); IFileSystem *GetSystemFromFilename(const std::string &filename);
FileSystemFlags FlagsFromFilename(const std::string &filename) {
IFileSystem *sys = GetSystemFromFilename(filename);
return sys ? sys->Flags() : FileSystemFlags::NONE;
}
void ThreadEnded(int threadID); void ThreadEnded(int threadID);

View file

@ -41,7 +41,7 @@ public:
int DevType(u32 handle) override; int DevType(u32 handle) override;
bool GetHostPath(const std::string &inpath, std::string &outpath) override; bool GetHostPath(const std::string &inpath, std::string &outpath) override;
std::vector<PSPFileInfo> GetDirListing(std::string path) override; std::vector<PSPFileInfo> GetDirListing(std::string path) override;
FileSystemFlags Flags() override { return FileSystemFlags::NONE; } FileSystemFlags Flags() override { return FileSystemFlags::UMD; }
u64 FreeSpace(const std::string &path) override { return 0; } u64 FreeSpace(const std::string &path) override { return 0; }
// unsupported operations // unsupported operations

View file

@ -621,9 +621,9 @@ void __IoInit() {
asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify); asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify);
syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify); syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify);
memstickSystem = new DirectoryFileSystem(&pspFileSystem, g_Config.memStickDirectory, FileSystemFlags::SIMULATE_FAT32); memstickSystem = new DirectoryFileSystem(&pspFileSystem, g_Config.memStickDirectory, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD);
#if defined(USING_WIN_UI) || defined(APPLE) #if defined(USING_WIN_UI) || defined(APPLE)
flash0System = new DirectoryFileSystem(&pspFileSystem, g_Config.flash0Directory); flash0System = new DirectoryFileSystem(&pspFileSystem, g_Config.flash0Directory, FileSystemFlags::FLASH);
#else #else
flash0System = new VFSFileSystem(&pspFileSystem, "flash0"); flash0System = new VFSFileSystem(&pspFileSystem, "flash0");
#endif #endif
@ -637,7 +637,7 @@ void __IoInit() {
const std::string gameId = g_paramSFO.GetValueString("DISC_ID"); const std::string gameId = g_paramSFO.GetValueString("DISC_ID");
const std::string exdataPath = g_Config.memStickDirectory + "exdata/" + gameId + "/"; const std::string exdataPath = g_Config.memStickDirectory + "exdata/" + gameId + "/";
if (File::Exists(exdataPath)) { if (File::Exists(exdataPath)) {
exdataSystem = new DirectoryFileSystem(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32); exdataSystem = new DirectoryFileSystem(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD);
pspFileSystem.Mount("exdata0:", exdataSystem); pspFileSystem.Mount("exdata0:", exdataSystem);
INFO_LOG(SCEIO, "Mounted exdata/%s/ under memstick for exdata0:/", gameId.c_str()); INFO_LOG(SCEIO, "Mounted exdata/%s/ under memstick for exdata0:/", gameId.c_str());
} else { } else {
@ -2287,13 +2287,7 @@ static u32 sceIoDread(int id, u32 dirent_addr) {
strncpy(entry->d_name, info.name.c_str(), 256); strncpy(entry->d_name, info.name.c_str(), 256);
entry->d_name[255] = '\0'; entry->d_name[255] = '\0';
bool isFAT = false; bool isFAT = pspFileSystem.FlagsFromFilename(dir->name) & FileSystemFlags::SIMULATE_FAT32;
IFileSystem *sys = pspFileSystem.GetSystemFromFilename(dir->name);
if (sys && (sys->Flags() & FileSystemFlags::SIMULATE_FAT32))
isFAT = true;
else
isFAT = false;
// Only write d_private for memory stick // Only write d_private for memory stick
if (isFAT) { if (isFAT) {
// write d_private for supporting Custom BGM // write d_private for supporting Custom BGM

View file

@ -386,7 +386,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
pspFileSystem.SetStartingDirectory(ms_path); pspFileSystem.SetStartingDirectory(ms_path);
} }
DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path, FileSystemFlags::SIMULATE_FAT32); DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD);
pspFileSystem.Mount("umd0:", fs); pspFileSystem.Mount("umd0:", fs);
std::string finalName = ms_path + file + extension; std::string finalName = ms_path + file + extension;