diff options
Diffstat (limited to 'src/core/file_sys/archive.h')
| -rw-r--r-- | src/core/file_sys/archive.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h index aeabf09ac..38145eed8 100644 --- a/src/core/file_sys/archive.h +++ b/src/core/file_sys/archive.h | |||
| @@ -7,11 +7,13 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/string_util.h" | ||
| 10 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 11 | 12 | ||
| 12 | #include "core/file_sys/file.h" | 13 | #include "core/file_sys/file.h" |
| 13 | #include "core/file_sys/directory.h" | 14 | #include "core/file_sys/directory.h" |
| 14 | 15 | ||
| 16 | #include "core/mem_map.h" | ||
| 15 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 16 | 18 | ||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 19 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -19,6 +21,15 @@ | |||
| 19 | 21 | ||
| 20 | namespace FileSys { | 22 | namespace FileSys { |
| 21 | 23 | ||
| 24 | // Path string type | ||
| 25 | enum LowPathType : u32 { | ||
| 26 | Invalid = 0, | ||
| 27 | Empty = 1, | ||
| 28 | Binary = 2, | ||
| 29 | Char = 3, | ||
| 30 | Wchar = 4 | ||
| 31 | }; | ||
| 32 | |||
| 22 | union Mode { | 33 | union Mode { |
| 23 | u32 hex; | 34 | u32 hex; |
| 24 | BitField<0, 1, u32> read_flag; | 35 | BitField<0, 1, u32> read_flag; |
| @@ -26,6 +37,94 @@ union Mode { | |||
| 26 | BitField<2, 1, u32> create_flag; | 37 | BitField<2, 1, u32> create_flag; |
| 27 | }; | 38 | }; |
| 28 | 39 | ||
| 40 | class Path { | ||
| 41 | public: | ||
| 42 | |||
| 43 | Path(): | ||
| 44 | type(Invalid) | ||
| 45 | { | ||
| 46 | } | ||
| 47 | |||
| 48 | Path(LowPathType type, u32 size, u32 pointer): | ||
| 49 | type(type) | ||
| 50 | { | ||
| 51 | switch (type) { | ||
| 52 | case Binary: | ||
| 53 | { | ||
| 54 | u8* data = Memory::GetPointer(pointer); | ||
| 55 | binary = std::vector<u8>(data, data + size); | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | case Char: | ||
| 59 | { | ||
| 60 | const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer)); | ||
| 61 | string = std::string(data, size - 1); // Data is always null-terminated. | ||
| 62 | break; | ||
| 63 | } | ||
| 64 | case Wchar: | ||
| 65 | { | ||
| 66 | const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer)); | ||
| 67 | u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | LowPathType GetType() const { | ||
| 74 | return type; | ||
| 75 | } | ||
| 76 | |||
| 77 | const std::string AsString() const { | ||
| 78 | switch (GetType()) { | ||
| 79 | case Char: | ||
| 80 | return string; | ||
| 81 | case Wchar: | ||
| 82 | return Common::UTF16ToUTF8(u16str); | ||
| 83 | case Empty: | ||
| 84 | return {}; | ||
| 85 | default: | ||
| 86 | ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!"); | ||
| 87 | return {}; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | const std::u16string AsU16Str() const { | ||
| 92 | switch (GetType()) { | ||
| 93 | case Char: | ||
| 94 | return Common::UTF8ToUTF16(string); | ||
| 95 | case Wchar: | ||
| 96 | return u16str; | ||
| 97 | case Empty: | ||
| 98 | return {}; | ||
| 99 | default: | ||
| 100 | ERROR_LOG(KERNEL, "LowPathType cannot be converted to u16string!"); | ||
| 101 | return {}; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | const std::vector<u8> AsBinary() const { | ||
| 106 | switch (GetType()) { | ||
| 107 | case Binary: | ||
| 108 | return binary; | ||
| 109 | case Char: | ||
| 110 | return std::vector<u8>(string.begin(), string.end()); | ||
| 111 | case Wchar: | ||
| 112 | return std::vector<u8>(u16str.begin(), u16str.end()); | ||
| 113 | case Empty: | ||
| 114 | return {}; | ||
| 115 | default: | ||
| 116 | ERROR_LOG(KERNEL, "LowPathType cannot be converted to binary!"); | ||
| 117 | return {}; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | private: | ||
| 122 | LowPathType type; | ||
| 123 | std::vector<u8> binary; | ||
| 124 | std::string string; | ||
| 125 | std::u16string u16str; | ||
| 126 | }; | ||
| 127 | |||
| 29 | class Archive : NonCopyable { | 128 | class Archive : NonCopyable { |
| 30 | public: | 129 | public: |
| 31 | /// Supported archive types | 130 | /// Supported archive types |