summaryrefslogtreecommitdiff
path: root/src/core/file_sys/filesystem.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-01-19 22:34:48 -0500
committerGravatar bunnei2018-01-21 15:39:26 -0500
commit00851a5ef442947c4237f32e063c37e7751db3ed (patch)
treefbdd26c6239a74a89da198f5f807cee81055e0fb /src/core/file_sys/filesystem.cpp
parentfile_sys: Remove disk_archive, savedata_archive, and title_metadata. (diff)
downloadyuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.gz
yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.tar.xz
yuzu-00851a5ef442947c4237f32e063c37e7751db3ed.zip
file_sys: Cleanup to better match Switch file system constructs.
file_sys: Add factory class for RomFS file system.
Diffstat (limited to 'src/core/file_sys/filesystem.cpp')
-rw-r--r--src/core/file_sys/filesystem.cpp122
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 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstddef>
6#include <iomanip>
7#include <sstream>
8#include "common/logging/log.h"
9#include "common/string_util.h"
10#include "core/file_sys/filesystem.h"
11#include "core/memory.h"
12
13namespace FileSys {
14
15Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) {
16 switch (type) {
17 case Binary: {
18 binary.resize(size);
19 Memory::ReadBlock(pointer, binary.data(), binary.size());
20 break;
21 }
22
23 case Char: {
24 string.resize(size - 1); // Data is always null-terminated.
25 Memory::ReadBlock(pointer, &string[0], string.size());
26 break;
27 }
28
29 case Wchar: {
30 u16str.resize(size / 2 - 1); // Data is always null-terminated.
31 Memory::ReadBlock(pointer, &u16str[0], u16str.size() * sizeof(char16_t));
32 break;
33 }
34
35 default:
36 break;
37 }
38}
39
40std::string Path::DebugStr() const {
41 switch (GetType()) {
42 case Invalid:
43 default:
44 return "[Invalid]";
45 case Empty:
46 return "[Empty]";
47 case Binary: {
48 std::stringstream res;
49 res << "[Binary: ";
50 for (unsigned byte : binary)
51 res << std::hex << std::setw(2) << std::setfill('0') << byte;
52 res << ']';
53 return res.str();
54 }
55 case Char:
56 return "[Char: " + AsString() + ']';
57 case Wchar:
58 return "[Wchar: " + AsString() + ']';
59 }
60}
61
62std::string Path::AsString() const {
63 switch (GetType()) {
64 case Char:
65 return string;
66 case Wchar:
67 return Common::UTF16ToUTF8(u16str);
68 case Empty:
69 return {};
70 case Invalid:
71 case Binary:
72 default:
73 // TODO(yuriks): Add assert
74 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
75 return {};
76 }
77}
78
79std::u16string Path::AsU16Str() const {
80 switch (GetType()) {
81 case Char:
82 return Common::UTF8ToUTF16(string);
83 case Wchar:
84 return u16str;
85 case Empty:
86 return {};
87 case Invalid:
88 case Binary:
89 // TODO(yuriks): Add assert
90 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
91 return {};
92 }
93
94 UNREACHABLE();
95}
96
97std::vector<u8> Path::AsBinary() const {
98 switch (GetType()) {
99 case Binary:
100 return binary;
101 case Char:
102 return std::vector<u8>(string.begin(), string.end());
103 case Wchar: {
104 // use two u8 for each character of u16str
105 std::vector<u8> to_return(u16str.size() * 2);
106 for (size_t i = 0; i < u16str.size(); ++i) {
107 u16 tmp_char = u16str.at(i);
108 to_return[i * 2] = (tmp_char & 0xFF00) >> 8;
109 to_return[i * 2 + 1] = (tmp_char & 0x00FF);
110 }
111 return to_return;
112 }
113 case Empty:
114 return {};
115 case Invalid:
116 default:
117 // TODO(yuriks): Add assert
118 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
119 return {};
120 }
121}
122} // namespace FileSys