diff options
| author | 2014-06-27 16:18:56 -0400 | |
|---|---|---|
| committer | 2014-07-04 20:37:45 -0400 | |
| commit | 17a6148f9df406a6ca4bdca98777e0aaf21f582a (patch) | |
| tree | 3763cf9417649428c81c7e9e0cb6abac251faa49 /src/core/file_sys | |
| parent | APT: Added stubbed ReceiveParameter and various cleanups. (diff) | |
| download | yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.tar.gz yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.tar.xz yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.zip | |
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.
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive.h | 54 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 46 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 50 | ||||
| -rw-r--r-- | src/core/file_sys/file_sys.h | 138 |
4 files changed, 150 insertions, 138 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h new file mode 100644 index 000000000..ed2d83640 --- /dev/null +++ b/src/core/file_sys/archive.h | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | #include "core/hle/kernel/kernel.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | // FileSys namespace | ||
| 13 | |||
| 14 | namespace FileSys { | ||
| 15 | |||
| 16 | class Archive : NonCopyable { | ||
| 17 | public: | ||
| 18 | /// Supported archive types | ||
| 19 | enum class IdCode : u32 { | ||
| 20 | RomFS = 0x00000003, | ||
| 21 | SaveData = 0x00000004, | ||
| 22 | ExtSaveData = 0x00000006, | ||
| 23 | SharedExtSaveData = 0x00000007, | ||
| 24 | SystemSaveData = 0x00000008, | ||
| 25 | SDMC = 0x00000009, | ||
| 26 | SDMCWriteOnly = 0x0000000A, | ||
| 27 | }; | ||
| 28 | |||
| 29 | Archive() { } | ||
| 30 | virtual ~Archive() { } | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | ||
| 34 | * @return IdCode of the archive | ||
| 35 | */ | ||
| 36 | virtual IdCode GetIdCode() const = 0; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Read data from the archive | ||
| 40 | * @param offset Offset in bytes to start reading archive from | ||
| 41 | * @param length Length in bytes to read data from archive | ||
| 42 | * @param buffer Buffer to read data into | ||
| 43 | * @return Number of bytes read | ||
| 44 | */ | ||
| 45 | virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Get the size of the archive in bytes | ||
| 49 | * @return Size of the archive in bytes | ||
| 50 | */ | ||
| 51 | virtual size_t GetSize() const = 0; | ||
| 52 | }; | ||
| 53 | |||
| 54 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp new file mode 100644 index 000000000..6fdb768d6 --- /dev/null +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | |||
| 7 | #include "core/file_sys/archive_romfs.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // FileSys namespace | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | Archive_RomFS::Archive_RomFS(Loader::AppLoader& app_loader) { | ||
| 15 | // Load the RomFS from the app | ||
| 16 | if (Loader::ResultStatus::Success != app_loader.ReadRomFS(raw_data)) { | ||
| 17 | WARN_LOG(FILESYS, "Unable to read RomFS!"); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | Archive_RomFS::~Archive_RomFS() { | ||
| 22 | } | ||
| 23 | |||
| 24 | /** | ||
| 25 | * Read data from the archive | ||
| 26 | * @param offset Offset in bytes to start reading archive from | ||
| 27 | * @param length Length in bytes to read data from archive | ||
| 28 | * @param buffer Buffer to read data into | ||
| 29 | * @return Number of bytes read | ||
| 30 | */ | ||
| 31 | size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { | ||
| 32 | DEBUG_LOG(FILESYS, "called offset=%d, length=%d", offset, length); | ||
| 33 | memcpy(buffer, &raw_data[(u32)offset], length); | ||
| 34 | return length; | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Get the size of the archive in bytes | ||
| 39 | * @return Size of the archive in bytes | ||
| 40 | */ | ||
| 41 | size_t Archive_RomFS::GetSize() const { | ||
| 42 | ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); | ||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h new file mode 100644 index 000000000..60af8ff0d --- /dev/null +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 11 | #include "core/file_sys/archive.h" | ||
| 12 | #include "core/loader/loader.h" | ||
| 13 | |||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | // FileSys namespace | ||
| 16 | |||
| 17 | namespace FileSys { | ||
| 18 | |||
| 19 | /// File system interface to the RomFS archive | ||
| 20 | class Archive_RomFS : public Archive { | ||
| 21 | public: | ||
| 22 | Archive_RomFS(Loader::AppLoader& app_loader); | ||
| 23 | ~Archive_RomFS(); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | ||
| 27 | * @return IdCode of the archive | ||
| 28 | */ | ||
| 29 | IdCode GetIdCode() const { return IdCode::RomFS; }; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Read data from the archive | ||
| 33 | * @param offset Offset in bytes to start reading archive from | ||
| 34 | * @param length Length in bytes to read data from archive | ||
| 35 | * @param buffer Buffer to read data into | ||
| 36 | * @return Number of bytes read | ||
| 37 | */ | ||
| 38 | size_t Read(const u64 offset, const u32 length, u8* buffer) const; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Get the size of the archive in bytes | ||
| 42 | * @return Size of the archive in bytes | ||
| 43 | */ | ||
| 44 | size_t GetSize() const; | ||
| 45 | |||
| 46 | private: | ||
| 47 | std::vector<u8> raw_data; | ||
| 48 | }; | ||
| 49 | |||
| 50 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/file_sys.h b/src/core/file_sys/file_sys.h deleted file mode 100644 index bb8503e62..000000000 --- a/src/core/file_sys/file_sys.h +++ /dev/null | |||
| @@ -1,138 +0,0 @@ | |||
| 1 | // Copyright (c) 2012- PPSSPP Project. | ||
| 2 | |||
| 3 | // This program is free software: you can redistribute it and/or modify | ||
| 4 | // it under the terms of the GNU General Public License as published by | ||
| 5 | // the Free Software Foundation, version 2.0 or later versions. | ||
| 6 | |||
| 7 | // This program is distributed in the hope that it will be useful, | ||
| 8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | // GNU General Public License 2.0 for more details. | ||
| 11 | |||
| 12 | // A copy of the GPL 2.0 should have been included with the program. | ||
| 13 | // If not, see http://www.gnu.org/licenses/ | ||
| 14 | |||
| 15 | // Official git repository and contact information can be found at | ||
| 16 | // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include "common/common.h" | ||
| 21 | #include "common/chunk_file.h" | ||
| 22 | |||
| 23 | enum FileAccess { | ||
| 24 | FILEACCESS_NONE=0, | ||
| 25 | FILEACCESS_READ=1, | ||
| 26 | FILEACCESS_WRITE=2, | ||
| 27 | FILEACCESS_APPEND=4, | ||
| 28 | FILEACCESS_CREATE=8 | ||
| 29 | }; | ||
| 30 | |||
| 31 | enum FileMove { | ||
| 32 | FILEMOVE_BEGIN=0, | ||
| 33 | FILEMOVE_CURRENT=1, | ||
| 34 | FILEMOVE_END=2 | ||
| 35 | }; | ||
| 36 | |||
| 37 | enum FileType { | ||
| 38 | FILETYPE_NORMAL=1, | ||
| 39 | FILETYPE_DIRECTORY=2 | ||
| 40 | }; | ||
| 41 | |||
| 42 | |||
| 43 | class IHandleAllocator { | ||
| 44 | public: | ||
| 45 | virtual ~IHandleAllocator() {} | ||
| 46 | virtual u32 GetNewHandle() = 0; | ||
| 47 | virtual void FreeHandle(u32 handle) = 0; | ||
| 48 | }; | ||
| 49 | |||
| 50 | class SequentialHandleAllocator : public IHandleAllocator { | ||
| 51 | public: | ||
| 52 | SequentialHandleAllocator() : handle_(1) {} | ||
| 53 | virtual u32 GetNewHandle() { return handle_++; } | ||
| 54 | virtual void FreeHandle(u32 handle) {} | ||
| 55 | private: | ||
| 56 | int handle_; | ||
| 57 | }; | ||
| 58 | |||
| 59 | struct FileInfo { | ||
| 60 | FileInfo() | ||
| 61 | : size(0), access(0), exists(false), type(FILETYPE_NORMAL), isOnSectorSystem(false), startSector(0), numSectors(0) {} | ||
| 62 | |||
| 63 | void DoState(PointerWrap &p) { | ||
| 64 | auto s = p.Section("FileInfo", 1); | ||
| 65 | if (!s) | ||
| 66 | return; | ||
| 67 | |||
| 68 | p.Do(name); | ||
| 69 | p.Do(size); | ||
| 70 | p.Do(access); | ||
| 71 | p.Do(exists); | ||
| 72 | p.Do(type); | ||
| 73 | p.Do(atime); | ||
| 74 | p.Do(ctime); | ||
| 75 | p.Do(mtime); | ||
| 76 | p.Do(isOnSectorSystem); | ||
| 77 | p.Do(startSector); | ||
| 78 | p.Do(numSectors); | ||
| 79 | p.Do(sectorSize); | ||
| 80 | } | ||
| 81 | |||
| 82 | std::string name; | ||
| 83 | s64 size; | ||
| 84 | u32 access; //unix 777 | ||
| 85 | bool exists; | ||
| 86 | FileType type; | ||
| 87 | |||
| 88 | tm atime; | ||
| 89 | tm ctime; | ||
| 90 | tm mtime; | ||
| 91 | |||
| 92 | bool isOnSectorSystem; | ||
| 93 | u32 startSector; | ||
| 94 | u32 numSectors; | ||
| 95 | u32 sectorSize; | ||
| 96 | }; | ||
| 97 | |||
| 98 | |||
| 99 | class IFileSystem { | ||
| 100 | public: | ||
| 101 | virtual ~IFileSystem() {} | ||
| 102 | |||
| 103 | virtual void DoState(PointerWrap &p) = 0; | ||
| 104 | virtual std::vector<FileInfo> GetDirListing(std::string path) = 0; | ||
| 105 | virtual u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) = 0; | ||
| 106 | virtual void CloseFile(u32 handle) = 0; | ||
| 107 | virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size) = 0; | ||
| 108 | virtual size_t WriteFile(u32 handle, const u8 *pointer, s64 size) = 0; | ||
| 109 | virtual size_t SeekFile(u32 handle, s32 position, FileMove type) = 0; | ||
| 110 | virtual FileInfo GetFileInfo(std::string filename) = 0; | ||
| 111 | virtual bool OwnsHandle(u32 handle) = 0; | ||
| 112 | virtual bool MkDir(const std::string &dirname) = 0; | ||
| 113 | virtual bool RmDir(const std::string &dirname) = 0; | ||
| 114 | virtual int RenameFile(const std::string &from, const std::string &to) = 0; | ||
| 115 | virtual bool RemoveFile(const std::string &filename) = 0; | ||
| 116 | virtual bool GetHostPath(const std::string &inpath, std::string &outpath) = 0; | ||
| 117 | }; | ||
| 118 | |||
| 119 | |||
| 120 | class EmptyFileSystem : public IFileSystem { | ||
| 121 | public: | ||
| 122 | virtual void DoState(PointerWrap &p) {} | ||
| 123 | std::vector<FileInfo> GetDirListing(std::string path) {std::vector<FileInfo> vec; return vec;} | ||
| 124 | u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) {return 0;} | ||
| 125 | void CloseFile(u32 handle) {} | ||
| 126 | size_t ReadFile(u32 handle, u8 *pointer, s64 size) {return 0;} | ||
| 127 | size_t WriteFile(u32 handle, const u8 *pointer, s64 size) {return 0;} | ||
| 128 | size_t SeekFile(u32 handle, s32 position, FileMove type) {return 0;} | ||
| 129 | FileInfo GetFileInfo(std::string filename) {FileInfo f; return f;} | ||
| 130 | bool OwnsHandle(u32 handle) {return false;} | ||
| 131 | virtual bool MkDir(const std::string &dirname) {return false;} | ||
| 132 | virtual bool RmDir(const std::string &dirname) {return false;} | ||
| 133 | virtual int RenameFile(const std::string &from, const std::string &to) {return -1;} | ||
| 134 | virtual bool RemoveFile(const std::string &filename) {return false;} | ||
| 135 | virtual bool GetHostPath(const std::string &inpath, std::string &outpath) {return false;} | ||
| 136 | }; | ||
| 137 | |||
| 138 | |||