2022-04-14 22:41:41 +02:00
|
|
|
#pragma once
|
|
|
|
#include "DirInfo.h"
|
|
|
|
#include "FileInfo.h"
|
|
|
|
#include "IFSWrapper.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include <coreinit/filesystem.h>
|
|
|
|
#include <coreinit/mutex.h>
|
|
|
|
#include <functional>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
class FSWrapper : public IFSWrapper {
|
|
|
|
public:
|
|
|
|
FSWrapper(const std::string &name, const std::string &pathToReplace, const std::string &replacePathWith, bool fallbackOnError, bool isWriteable) {
|
|
|
|
this->pName = name;
|
|
|
|
this->pPathToReplace = pathToReplace;
|
|
|
|
this->pReplacePathWith = replacePathWith;
|
|
|
|
this->pFallbackOnError = fallbackOnError;
|
|
|
|
this->pIsWriteable = isWriteable;
|
|
|
|
this->pCheckIfDeleted = fallbackOnError;
|
|
|
|
|
|
|
|
std::replace(pPathToReplace.begin(), pPathToReplace.end(), '\\', '/');
|
|
|
|
std::replace(pReplacePathWith.begin(), pReplacePathWith.end(), '\\', '/');
|
|
|
|
}
|
|
|
|
~FSWrapper() override {
|
2022-04-29 13:34:04 +02:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lockFiles(openFilesMutex);
|
2022-04-14 22:41:41 +02:00
|
|
|
openFiles.clear();
|
|
|
|
}
|
2022-04-29 13:34:04 +02:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lockDirs(openDirsMutex);
|
2022-04-14 22:41:41 +02:00
|
|
|
openDirs.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSOpenDirWrapper(const char *path,
|
|
|
|
FSDirectoryHandle *handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSReadDirWrapper(FSDirectoryHandle handle,
|
|
|
|
FSDirectoryEntry *entry) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSCloseDirWrapper(FSDirectoryHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSMakeDirWrapper(const char *path) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSRewindDirWrapper(FSDirectoryHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSOpenFileWrapper(const char *path,
|
|
|
|
const char *mode,
|
|
|
|
FSFileHandle *handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSCloseFileWrapper(FSFileHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSGetStatWrapper(const char *path, FSStat *stats) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSGetStatFileWrapper(FSFileHandle handle,
|
|
|
|
FSStat *stats) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSReadFileWrapper(void *buffer,
|
|
|
|
uint32_t size,
|
|
|
|
uint32_t count,
|
|
|
|
FSFileHandle handle,
|
|
|
|
uint32_t unk1) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSReadFileWithPosWrapper(void *buffer,
|
|
|
|
uint32_t size,
|
|
|
|
uint32_t count,
|
|
|
|
uint32_t pos,
|
|
|
|
FSFileHandle handle,
|
|
|
|
int32_t unk1) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSSetPosFileWrapper(FSFileHandle handle,
|
|
|
|
uint32_t pos) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSGetPosFileWrapper(FSFileHandle handle,
|
|
|
|
uint32_t *pos) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSIsEofWrapper(FSFileHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSTruncateFileWrapper(FSFileHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSWriteFileWrapper(uint8_t *buffer,
|
|
|
|
uint32_t size,
|
|
|
|
uint32_t count,
|
|
|
|
FSFileHandle handle,
|
|
|
|
uint32_t unk1) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSRemoveWrapper(const char *path) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSRenameWrapper(const char *oldPath,
|
|
|
|
const char *newPath) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-08-07 19:22:20 +02:00
|
|
|
FSError FSFlushFileWrapper(FSFileHandle handle) override;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool IsFileModeAllowed(const char *mode);
|
|
|
|
|
|
|
|
virtual bool IsPathToReplace(const std::string_view &path);
|
|
|
|
|
|
|
|
std::string GetNewPath(const std::string_view &path);
|
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
std::shared_ptr<DirInfo> getDirFromHandle(FSDirectoryHandle handle);
|
|
|
|
std::shared_ptr<FileInfo> getFileFromHandle(FSFileHandle handle);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
bool isValidDirHandle(FSDirectoryHandle handle) override;
|
|
|
|
bool isValidFileHandle(FSFileHandle handle) override;
|
|
|
|
|
|
|
|
void deleteDirHandle(FSDirectoryHandle handle) override;
|
|
|
|
void deleteFileHandle(FSFileHandle handle) override;
|
|
|
|
|
|
|
|
virtual bool CheckFileShouldBeIgnored(std::string &path);
|
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
virtual std::shared_ptr<FileInfo> getNewFileHandle();
|
|
|
|
virtual std::shared_ptr<DirInfo> getNewDirHandle();
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
virtual bool SkipDeletedFilesInReadDir();
|
|
|
|
|
|
|
|
bool pCheckIfDeleted = false;
|
|
|
|
|
|
|
|
std::string deletePrefix = ".deleted_";
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string pPathToReplace;
|
|
|
|
std::string pReplacePathWith;
|
|
|
|
bool pIsWriteable = false;
|
|
|
|
std::mutex openFilesMutex;
|
|
|
|
std::mutex openDirsMutex;
|
2022-04-29 13:34:04 +02:00
|
|
|
std::vector<std::shared_ptr<FileInfo>> openFiles;
|
|
|
|
std::vector<std::shared_ptr<DirInfo>> openDirs;
|
2022-04-14 22:41:41 +02:00
|
|
|
};
|