Add basic infrastructure for file handler plugins.

The purpose of this is for games which use archive file formats
(containing many individual files), so that assets, files, etc. can be
worked on more rapidly.
This commit is contained in:
Unknown W. Brackets 2013-07-28 10:31:42 -07:00
parent 9ba2af1c48
commit 150a5c8f70
2 changed files with 54 additions and 3 deletions

View file

@ -94,7 +94,8 @@ void VirtualDiscFileSystem::LoadFileListIndex() {
// Check if there's a handler specified. // Check if there's a handler specified.
size_t handler_pos = line.find(':', filename_pos); size_t handler_pos = line.find(':', filename_pos);
if (handler_pos != line.npos) { if (handler_pos != line.npos) {
entry.fileName = line.substr(filename_pos + 1, handler_pos - filename_pos); entry.fileName = line.substr(filename_pos + 1, handler_pos - filename_pos - 1);
NOTICE_LOG(HLE, "Handler found: %s", line.substr(handler_pos + 1).c_str());
// TODO: Implement handler. // TODO: Implement handler.
} else { } else {
entry.fileName = line.substr(filename_pos + 1); entry.fileName = line.substr(filename_pos + 1);
@ -637,3 +638,11 @@ bool VirtualDiscFileSystem::RemoveFile(const std::string &filename)
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot remove file on virtual disc"); ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot remove file on virtual disc");
return false; return false;
} }
VirtualDiscFileSystem::Handler::Handler(const char *filename) {
// TODO
}
VirtualDiscFileSystem::Handler::~Handler() {
// TODO
}

View file

@ -24,8 +24,7 @@
#include "Core/FileSystems/FileSystem.h" #include "Core/FileSystems/FileSystem.h"
#include "Core/FileSystems/DirectoryFileSystem.h" #include "Core/FileSystems/DirectoryFileSystem.h"
class VirtualDiscFileSystem: public IFileSystem class VirtualDiscFileSystem: public IFileSystem {
{
public: public:
VirtualDiscFileSystem(IHandleAllocator *_hAlloc, std::string _basePath); VirtualDiscFileSystem(IHandleAllocator *_hAlloc, std::string _basePath);
~VirtualDiscFileSystem(); ~VirtualDiscFileSystem();
@ -53,10 +52,51 @@ private:
int getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode = false); int getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode = false);
std::string GetLocalPath(std::string localpath); std::string GetLocalPath(std::string localpath);
typedef void *HandlerLibrary;
typedef int HandlerHandle;
typedef s64 HandlerOffset;
typedef void (*HandlerLogFunc)(HandlerHandle fd, int level, const char *msg);
// The primary purpose of handlers is to make it easier to work with large archives.
// However, they have other uses as well, such as patching individual files.
struct Handler {
Handler(const char *filename);
~Handler();
HandlerLibrary library;
bool (*Init)(HandlerLogFunc logger);
void (*Shutdown)();
HandlerHandle (*Open)(const char *basePath, const char *filename);
HandlerOffset (*Seek)(HandlerHandle handle, HandlerOffset offset, FileMove origin);
HandlerOffset (*Read)(HandlerHandle handle, void *data, HandlerOffset size);
void (*Close)(HandlerHandle handle);
};
struct HandlerFileHandle {
Handler *handler;
HandlerHandle handle;
bool Open(std::string& basePath, std::string& fileName, FileAccess access) {
// Ignore access, read only.
handle = handler->Open(basePath.c_str(), fileName.c_str());
return handle > 0;
}
size_t Read(u8 *data, s64 size) {
return (size_t)handler->Read(handle, data, size);
}
size_t Seek(s32 position, FileMove type) {
return (size_t)handler->Seek(handle, position, type);
}
void Close() {
handler->Close(handle);
}
};
typedef enum { VFILETYPE_NORMAL, VFILETYPE_LBN, VFILETYPE_ISO } VirtualFileType; typedef enum { VFILETYPE_NORMAL, VFILETYPE_LBN, VFILETYPE_ISO } VirtualFileType;
struct OpenFileEntry { struct OpenFileEntry {
DirectoryFileHandle hFile; DirectoryFileHandle hFile;
HandlerFileHandle handler;
VirtualFileType type; VirtualFileType type;
u32 fileIndex; u32 fileIndex;
u32 curOffset; u32 curOffset;
@ -77,4 +117,6 @@ private:
std::vector<FileListEntry> fileList; std::vector<FileListEntry> fileList;
u32 currentBlockIndex; u32 currentBlockIndex;
std::map<std::string, Handler> handlers;
}; };