diff options
author | bunnei <bunneidev@gmail.com> | 2018-01-20 04:34:48 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-01-21 21:39:26 +0100 |
commit | 00851a5ef442947c4237f32e063c37e7751db3ed (patch) | |
tree | fbdd26c6239a74a89da198f5f807cee81055e0fb /src/core/file_sys/filesystem.cpp | |
parent | file_sys: Remove disk_archive, savedata_archive, and title_metadata. (diff) | |
download | yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.gz yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.bz2 yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.lz yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.xz yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.zst yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.zip |
Diffstat (limited to 'src/core/file_sys/filesystem.cpp')
-rw-r--r-- | src/core/file_sys/filesystem.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/core/file_sys/filesystem.cpp b/src/core/file_sys/filesystem.cpp new file mode 100644 index 000000000..82fdb3c46 --- /dev/null +++ b/src/core/file_sys/filesystem.cpp @@ -0,0 +1,122 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <cstddef> +#include <iomanip> +#include <sstream> +#include "common/logging/log.h" +#include "common/string_util.h" +#include "core/file_sys/filesystem.h" +#include "core/memory.h" + +namespace FileSys { + +Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) { + switch (type) { + case Binary: { + binary.resize(size); + Memory::ReadBlock(pointer, binary.data(), binary.size()); + break; + } + + case Char: { + string.resize(size - 1); // Data is always null-terminated. + Memory::ReadBlock(pointer, &string[0], string.size()); + break; + } + + case Wchar: { + u16str.resize(size / 2 - 1); // Data is always null-terminated. + Memory::ReadBlock(pointer, &u16str[0], u16str.size() * sizeof(char16_t)); + break; + } + + default: + break; + } +} + +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() + ']'; + } +} + +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 {}; + } +} + +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 {}; + } + + UNREACHABLE(); +} + +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 {}; + } +} +} // namespace FileSys |