FileSys: Added preliminary support for applications reading the RomFS archive.
Archive: Fixed brace ugliness for neobrain :) FS: Commented out unused local variables to prevent warnings. ...But keeping them here for future use. archive_romfs: Removed unused #include.master
parent
82702fedb8
commit
17a6148f9d
@ -0,0 +1,54 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
class Archive : NonCopyable {
|
||||
public:
|
||||
/// Supported archive types
|
||||
enum class IdCode : u32 {
|
||||
RomFS = 0x00000003,
|
||||
SaveData = 0x00000004,
|
||||
ExtSaveData = 0x00000006,
|
||||
SharedExtSaveData = 0x00000007,
|
||||
SystemSaveData = 0x00000008,
|
||||
SDMC = 0x00000009,
|
||||
SDMCWriteOnly = 0x0000000A,
|
||||
};
|
||||
|
||||
Archive() { }
|
||||
virtual ~Archive() { }
|
||||
|
||||
/**
|
||||
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
|
||||
* @return IdCode of the archive
|
||||
*/
|
||||
virtual IdCode GetIdCode() const = 0;
|
||||
|
||||
/**
|
||||
* Read data from the archive
|
||||
* @param offset Offset in bytes to start reading archive from
|
||||
* @param length Length in bytes to read data from archive
|
||||
* @param buffer Buffer to read data into
|
||||
* @return Number of bytes read
|
||||
*/
|
||||
virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
|
||||
|
||||
/**
|
||||
* Get the size of the archive in bytes
|
||||
* @return Size of the archive in bytes
|
||||
*/
|
||||
virtual size_t GetSize() const = 0;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
@ -0,0 +1,46 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
#include "core/file_sys/archive_romfs.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
Archive_RomFS::Archive_RomFS(Loader::AppLoader& app_loader) {
|
||||
// Load the RomFS from the app
|
||||
if (Loader::ResultStatus::Success != app_loader.ReadRomFS(raw_data)) {
|
||||
WARN_LOG(FILESYS, "Unable to read RomFS!");
|
||||
}
|
||||
}
|
||||
|
||||
Archive_RomFS::~Archive_RomFS() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from the archive
|
||||
* @param offset Offset in bytes to start reading archive from
|
||||
* @param length Length in bytes to read data from archive
|
||||
* @param buffer Buffer to read data into
|
||||
* @return Number of bytes read
|
||||
*/
|
||||
size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
|
||||
DEBUG_LOG(FILESYS, "called offset=%d, length=%d", offset, length);
|
||||
memcpy(buffer, &raw_data[(u32)offset], length);
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the archive in bytes
|
||||
* @return Size of the archive in bytes
|
||||
*/
|
||||
size_t Archive_RomFS::GetSize() const {
|
||||
ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace FileSys
|
@ -0,0 +1,50 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
#include "core/file_sys/archive.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
/// File system interface to the RomFS archive
|
||||
class Archive_RomFS : public Archive {
|
||||
public:
|
||||
Archive_RomFS(Loader::AppLoader& app_loader);
|
||||
~Archive_RomFS();
|
||||
|
||||
/**
|
||||
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
|
||||
* @return IdCode of the archive
|
||||
*/
|
||||
IdCode GetIdCode() const { return IdCode::RomFS; };
|
||||
|
||||
/**
|
||||
* Read data from the archive
|
||||
* @param offset Offset in bytes to start reading archive from
|
||||
* @param length Length in bytes to read data from archive
|
||||
* @param buffer Buffer to read data into
|
||||
* @return Number of bytes read
|
||||
*/
|
||||
size_t Read(const u64 offset, const u32 length, u8* buffer) const;
|
||||
|
||||
/**
|
||||
* Get the size of the archive in bytes
|
||||
* @return Size of the archive in bytes
|
||||
*/
|
||||
size_t GetSize() const;
|
||||
|
||||
private:
|
||||
std::vector<u8> raw_data;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
@ -1,138 +0,0 @@
|
||||
// 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 "common/common.h"
|
||||
#include "common/chunk_file.h"
|
||||
|
||||
enum FileAccess {
|
||||
FILEACCESS_NONE=0,
|
||||
FILEACCESS_READ=1,
|
||||
FILEACCESS_WRITE=2,
|
||||
FILEACCESS_APPEND=4,
|
||||
FILEACCESS_CREATE=8
|
||||
};
|
||||
|
||||
enum FileMove {
|
||||
FILEMOVE_BEGIN=0,
|
||||
FILEMOVE_CURRENT=1,
|
||||
FILEMOVE_END=2
|
||||
};
|
||||
|
||||
enum FileType {
|
||||
FILETYPE_NORMAL=1,
|
||||
FILETYPE_DIRECTORY=2
|
||||
};
|
||||
|
||||
|
||||
class IHandleAllocator {
|
||||
public:
|
||||
virtual ~IHandleAllocator() {}
|
||||
virtual u32 GetNewHandle() = 0;
|
||||
virtual void FreeHandle(u32 handle) = 0;
|
||||
};
|
||||
|
||||
class SequentialHandleAllocator : public IHandleAllocator {
|
||||
public:
|
||||
SequentialHandleAllocator() : handle_(1) {}
|
||||
virtual u32 GetNewHandle() { return handle_++; }
|
||||
virtual void FreeHandle(u32 handle) {}
|
||||
private:
|
||||
int handle_;
|
||||
};
|
||||
|
||||
struct FileInfo {
|
||||
FileInfo()
|
||||
: size(0), access(0), exists(false), type(FILETYPE_NORMAL), isOnSectorSystem(false), startSector(0), numSectors(0) {}
|
||||
|
||||
void DoState(PointerWrap &p) {
|
||||
auto s = p.Section("FileInfo", 1);
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
p.Do(name);
|
||||
p.Do(size);
|
||||
p.Do(access);
|
||||
p.Do(exists);
|
||||
p.Do(type);
|
||||
p.Do(atime);
|
||||
p.Do(ctime);
|
||||
p.Do(mtime);
|
||||
p.Do(isOnSectorSystem);
|
||||
p.Do(startSector);
|
||||
p.Do(numSectors);
|
||||
p.Do(sectorSize);
|
||||
}
|
||||
|
||||
std::string name;
|
||||
s64 size;
|
||||
u32 access; //unix 777
|
||||
bool exists;
|
||||
FileType type;
|
||||
|
||||
tm atime;
|
||||
tm ctime;
|
||||
tm mtime;
|
||||
|
||||
bool isOnSectorSystem;
|
||||
u32 startSector;
|
||||
u32 numSectors;
|
||||
u32 sectorSize;
|
||||
};
|
||||
|
||||
|
||||
class IFileSystem {
|
||||
public:
|
||||
virtual ~IFileSystem() {}
|
||||
|
||||
virtual void DoState(PointerWrap &p) = 0;
|
||||
virtual std::vector<FileInfo> GetDirListing(std::string path) = 0;
|
||||
virtual u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) = 0;
|
||||
virtual void CloseFile(u32 handle) = 0;
|
||||
virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size) = 0;
|
||||
virtual size_t WriteFile(u32 handle, const u8 *pointer, s64 size) = 0;
|
||||
virtual size_t SeekFile(u32 handle, s32 position, FileMove type) = 0;
|
||||
virtual FileInfo GetFileInfo(std::string filename) = 0;
|
||||
virtual bool OwnsHandle(u32 handle) = 0;
|
||||
virtual bool MkDir(const std::string &dirname) = 0;
|
||||
virtual bool RmDir(const std::string &dirname) = 0;
|
||||
virtual int RenameFile(const std::string &from, const std::string &to) = 0;
|
||||
virtual bool RemoveFile(const std::string &filename) = 0;
|
||||
virtual bool GetHostPath(const std::string &inpath, std::string &outpath) = 0;
|
||||
};
|
||||
|
||||
|
||||
class EmptyFileSystem : public IFileSystem {
|
||||
public:
|
||||
virtual void DoState(PointerWrap &p) {}
|
||||
std::vector<FileInfo> GetDirListing(std::string path) {std::vector<FileInfo> vec; return vec;}
|
||||
u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) {return 0;}
|
||||
void CloseFile(u32 handle) {}
|
||||
size_t ReadFile(u32 handle, u8 *pointer, s64 size) {return 0;}
|
||||
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) {return 0;}
|
||||
size_t SeekFile(u32 handle, s32 position, FileMove type) {return 0;}
|
||||
FileInfo GetFileInfo(std::string filename) {FileInfo f; return f;}
|
||||
bool OwnsHandle(u32 handle) {return false;}
|
||||
virtual bool MkDir(const std::string &dirname) {return false;}
|
||||
virtual bool RmDir(const std::string &dirname) {return false;}
|
||||
virtual int RenameFile(const std::string &from, const std::string &to) {return -1;}
|
||||
virtual bool RemoveFile(const std::string &filename) {return false;}
|
||||
virtual bool GetHostPath(const std::string &inpath, std::string &outpath) {return false;}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue