diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/file_sys/archive_backend.cpp | 127 | ||||
-rw-r--r-- | src/core/file_sys/archive_backend.h | 147 | ||||
-rw-r--r-- | src/core/file_sys/archive_extsavedata.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedata.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedatacheck.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/directory_backend.h | 3 | ||||
-rw-r--r-- | src/core/file_sys/disk_archive.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/disk_archive.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/file_backend.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/ivfc_archive.cpp | 1 | ||||
-rw-r--r-- | src/core/file_sys/ivfc_archive.h | 2 |
13 files changed, 156 insertions, 134 deletions
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp new file mode 100644 index 000000000..0439868ab --- /dev/null +++ b/src/core/file_sys/archive_backend.cpp @@ -0,0 +1,127 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <sstream> + +#include "common/logging/log.h" +#include "common/string_util.h" + +#include "core/file_sys/archive_backend.h" +#include "core/mem_map.h" + + +namespace FileSys { + +Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) { + switch (type) { + case Binary: + { + u8* data = Memory::GetPointer(pointer); + binary = std::vector<u8>(data, data + size); + break; + } + + case Char: + { + const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer)); + string = std::string(data, size - 1); // Data is always null-terminated. + break; + } + + case Wchar: + { + const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer)); + u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. + break; + } + + default: + break; + } +} + +const std::string Path::DebugStr() const { + switch (GetType()) { + case Invalid: + default: + return "[Invalid]"; + case Empty: + return "[Empty]"; + case Binary: + { + std::stringstream res; + res << "[Binary: "; + for (unsigned byte : binary) + res << std::hex << std::setw(2) << std::setfill('0') << byte; + res << ']'; + return res.str(); + } + case Char: + return "[Char: " + AsString() + ']'; + case Wchar: + return "[Wchar: " + AsString() + ']'; + } +} + +const std::string Path::AsString() const { + switch (GetType()) { + case Char: + return string; + case Wchar: + return Common::UTF16ToUTF8(u16str); + case Empty: + return{}; + case Invalid: + case Binary: + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); + return{}; + } +} + +const std::u16string Path::AsU16Str() const { + switch (GetType()) { + case Char: + return Common::UTF8ToUTF16(string); + case Wchar: + return u16str; + case Empty: + return{}; + case Invalid: + case Binary: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); + return{}; + } +} + +const std::vector<u8> Path::AsBinary() const { + switch (GetType()) { + case Binary: + return binary; + case Char: + return std::vector<u8>(string.begin(), string.end()); + case Wchar: + { + // use two u8 for each character of u16str + std::vector<u8> to_return(u16str.size() * 2); + for (size_t i = 0; i < u16str.size(); ++i) { + u16 tmp_char = u16str.at(i); + to_return[i*2] = (tmp_char & 0xFF00) >> 8; + to_return[i*2 + 1] = (tmp_char & 0x00FF); + } + return to_return; + } + case Empty: + return{}; + case Invalid: + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); + return{}; + } +} + +} diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 43a106549..c6a1be79d 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -5,22 +5,21 @@ #pragma once #include <memory> +#include <string> +#include <utility> +#include <vector> -#include "common/common_types.h" -#include "common/string_util.h" #include "common/bit_field.h" +#include "common/common_types.h" -#include "core/file_sys/file_backend.h" -#include "core/file_sys/directory_backend.h" - -#include "core/mem_map.h" -#include "core/hle/kernel/kernel.h" +#include "core/hle/result.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// FileSys namespace namespace FileSys { +class FileBackend; +class DirectoryBackend; + // Path string type enum LowPathType : u32 { Invalid = 0, @@ -39,134 +38,22 @@ union Mode { class Path { public: + Path() : type(Invalid) {} + Path(const char* path) : type(Char), string(path) {} + Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {} + Path(LowPathType type, u32 size, u32 pointer); - Path() : type(Invalid) { - } - - Path(const char* path) : type(Char), string(path) { - } - - Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) { - } - - Path(LowPathType type, u32 size, u32 pointer) : type(type) { - switch (type) { - case Binary: - { - u8* data = Memory::GetPointer(pointer); - binary = std::vector<u8>(data, data + size); - break; - } - - case Char: - { - const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer)); - string = std::string(data, size - 1); // Data is always null-terminated. - break; - } - - case Wchar: - { - const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer)); - u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. - break; - } - - default: - break; - } - } - - LowPathType GetType() const { - return type; - } + LowPathType GetType() const { return type; } /** * Gets the string representation of the path for debugging * @return String representation of the path for debugging */ - const std::string DebugStr() const { - switch (GetType()) { - case Invalid: - default: - return "[Invalid]"; - case Empty: - return "[Empty]"; - case Binary: - { - std::stringstream res; - res << "[Binary: "; - for (unsigned byte : binary) - res << std::hex << std::setw(2) << std::setfill('0') << byte; - res << ']'; - return res.str(); - } - case Char: - return "[Char: " + AsString() + ']'; - case Wchar: - return "[Wchar: " + AsString() + ']'; - } - } + const std::string DebugStr() const; - const std::string AsString() const { - switch (GetType()) { - case Char: - return string; - case Wchar: - return Common::UTF16ToUTF8(u16str); - case Empty: - return {}; - case Invalid: - case Binary: - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); - return {}; - } - } - - const std::u16string AsU16Str() const { - switch (GetType()) { - case Char: - return Common::UTF8ToUTF16(string); - case Wchar: - return u16str; - case Empty: - return {}; - case Invalid: - case Binary: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); - return {}; - } - } - - const std::vector<u8> AsBinary() const { - switch (GetType()) { - case Binary: - return binary; - case Char: - return std::vector<u8>(string.begin(), string.end()); - case Wchar: - { - // use two u8 for each character of u16str - std::vector<u8> to_return(u16str.size() * 2); - for (size_t i = 0; i < u16str.size(); ++i) { - u16 tmp_char = u16str.at(i); - to_return[i*2] = (tmp_char & 0xFF00) >> 8; - to_return[i*2 + 1] = (tmp_char & 0x00FF); - } - return to_return; - } - case Empty: - return {}; - case Invalid: - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); - return {}; - } - } + const std::string AsString() const; + const std::u16string AsU16Str() const; + const std::vector<u8> AsBinary() const; private: LowPathType type; diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 3076fa263..38d498d0e 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/archive_extsavedata.h" diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index bf54a3866..d4a12ed10 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/archive_romfs.h" diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index 8496e06f3..12624fa31 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/archive_savedata.h" diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index 47d8a9d25..e7e4fbf1d 100644 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ b/src/core/file_sys/archive_savedatacheck.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/archive_savedatacheck.h" diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 92b20c7f6..c1234a186 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/archive_sdmc.h" diff --git a/src/core/file_sys/directory_backend.h b/src/core/file_sys/directory_backend.h index 7f327dc42..a25dc0cfa 100644 --- a/src/core/file_sys/directory_backend.h +++ b/src/core/file_sys/directory_backend.h @@ -4,12 +4,11 @@ #pragma once +#include <array> #include <cstddef> #include "common/common_types.h" -#include "core/hle/kernel/kernel.h" - //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index f53fd57db..9980cced1 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/disk_archive.h" diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h index 770bd715e..a22d3837a 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h @@ -8,6 +8,8 @@ #include "common/file_util.h" #include "core/file_sys/archive_backend.h" +#include "core/file_sys/directory_backend.h" +#include "core/file_sys/file_backend.h" #include "core/loader/loader.h" //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index 35890af1f..0fcff1845 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h @@ -6,8 +6,6 @@ #include "common/common_types.h" -#include "core/hle/kernel/kernel.h" - //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index 35aca54fa..2d2509d16 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/logging/log.h" #include "common/make_unique.h" #include "core/file_sys/ivfc_archive.h" diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index 1aff9e0a4..10415798d 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h @@ -10,6 +10,8 @@ #include "common/common_types.h" #include "core/file_sys/archive_backend.h" +#include "core/file_sys/directory_backend.h" +#include "core/file_sys/file_backend.h" #include "core/loader/loader.h" //////////////////////////////////////////////////////////////////////////////////////////////////// |