summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-07 11:45:45 -0700
committerGravatar Yuri Kunde Schlesner2015-05-07 11:45:45 -0700
commit4f4d230dac936f32cceb8be35fe09822d85bb2b6 (patch)
treea180a736708834708e0e5b95fd1720f37722b429 /src/core/file_sys
parentMerge pull request #695 from Subv/crash_f (diff)
parentFix printf format warning (diff)
downloadyuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.tar.gz
yuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.tar.xz
yuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.zip
Merge pull request #721 from yuriks/more-cleanups
More cleanups
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.cpp127
-rw-r--r--src/core/file_sys/archive_backend.h147
-rw-r--r--src/core/file_sys/archive_extsavedata.cpp1
-rw-r--r--src/core/file_sys/archive_romfs.cpp1
-rw-r--r--src/core/file_sys/archive_savedata.cpp1
-rw-r--r--src/core/file_sys/archive_savedatacheck.cpp1
-rw-r--r--src/core/file_sys/archive_sdmc.cpp1
-rw-r--r--src/core/file_sys/directory_backend.h3
-rw-r--r--src/core/file_sys/disk_archive.cpp1
-rw-r--r--src/core/file_sys/disk_archive.h2
-rw-r--r--src/core/file_sys/file_backend.h2
-rw-r--r--src/core/file_sys/ivfc_archive.cpp1
-rw-r--r--src/core/file_sys/ivfc_archive.h2
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 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <sstream>
6
7#include "common/logging/log.h"
8#include "common/string_util.h"
9
10#include "core/file_sys/archive_backend.h"
11#include "core/mem_map.h"
12
13
14namespace FileSys {
15
16Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) {
17 switch (type) {
18 case Binary:
19 {
20 u8* data = Memory::GetPointer(pointer);
21 binary = std::vector<u8>(data, data + size);
22 break;
23 }
24
25 case Char:
26 {
27 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
28 string = std::string(data, size - 1); // Data is always null-terminated.
29 break;
30 }
31
32 case Wchar:
33 {
34 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
35 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
36 break;
37 }
38
39 default:
40 break;
41 }
42}
43
44const std::string Path::DebugStr() const {
45 switch (GetType()) {
46 case Invalid:
47 default:
48 return "[Invalid]";
49 case Empty:
50 return "[Empty]";
51 case Binary:
52 {
53 std::stringstream res;
54 res << "[Binary: ";
55 for (unsigned byte : binary)
56 res << std::hex << std::setw(2) << std::setfill('0') << byte;
57 res << ']';
58 return res.str();
59 }
60 case Char:
61 return "[Char: " + AsString() + ']';
62 case Wchar:
63 return "[Wchar: " + AsString() + ']';
64 }
65}
66
67const std::string Path::AsString() const {
68 switch (GetType()) {
69 case Char:
70 return string;
71 case Wchar:
72 return Common::UTF16ToUTF8(u16str);
73 case Empty:
74 return{};
75 case Invalid:
76 case Binary:
77 default:
78 // TODO(yuriks): Add assert
79 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
80 return{};
81 }
82}
83
84const std::u16string Path::AsU16Str() const {
85 switch (GetType()) {
86 case Char:
87 return Common::UTF8ToUTF16(string);
88 case Wchar:
89 return u16str;
90 case Empty:
91 return{};
92 case Invalid:
93 case Binary:
94 // TODO(yuriks): Add assert
95 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
96 return{};
97 }
98}
99
100const std::vector<u8> Path::AsBinary() const {
101 switch (GetType()) {
102 case Binary:
103 return binary;
104 case Char:
105 return std::vector<u8>(string.begin(), string.end());
106 case Wchar:
107 {
108 // use two u8 for each character of u16str
109 std::vector<u8> to_return(u16str.size() * 2);
110 for (size_t i = 0; i < u16str.size(); ++i) {
111 u16 tmp_char = u16str.at(i);
112 to_return[i*2] = (tmp_char & 0xFF00) >> 8;
113 to_return[i*2 + 1] = (tmp_char & 0x00FF);
114 }
115 return to_return;
116 }
117 case Empty:
118 return{};
119 case Invalid:
120 default:
121 // TODO(yuriks): Add assert
122 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
123 return{};
124 }
125}
126
127}
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 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <string>
9#include <utility>
10#include <vector>
8 11
9#include "common/common_types.h"
10#include "common/string_util.h"
11#include "common/bit_field.h" 12#include "common/bit_field.h"
13#include "common/common_types.h"
12 14
13#include "core/file_sys/file_backend.h" 15#include "core/hle/result.h"
14#include "core/file_sys/directory_backend.h"
15
16#include "core/mem_map.h"
17#include "core/hle/kernel/kernel.h"
18 16
19////////////////////////////////////////////////////////////////////////////////////////////////////
20// FileSys namespace
21 17
22namespace FileSys { 18namespace FileSys {
23 19
20class FileBackend;
21class DirectoryBackend;
22
24// Path string type 23// Path string type
25enum LowPathType : u32 { 24enum LowPathType : u32 {
26 Invalid = 0, 25 Invalid = 0,
@@ -39,134 +38,22 @@ union Mode {
39 38
40class Path { 39class Path {
41public: 40public:
41 Path() : type(Invalid) {}
42 Path(const char* path) : type(Char), string(path) {}
43 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {}
44 Path(LowPathType type, u32 size, u32 pointer);
42 45
43 Path() : type(Invalid) { 46 LowPathType GetType() const { return type; }
44 }
45
46 Path(const char* path) : type(Char), string(path) {
47 }
48
49 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {
50 }
51
52 Path(LowPathType type, u32 size, u32 pointer) : type(type) {
53 switch (type) {
54 case Binary:
55 {
56 u8* data = Memory::GetPointer(pointer);
57 binary = std::vector<u8>(data, data + size);
58 break;
59 }
60
61 case Char:
62 {
63 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
64 string = std::string(data, size - 1); // Data is always null-terminated.
65 break;
66 }
67
68 case Wchar:
69 {
70 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
71 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
72 break;
73 }
74
75 default:
76 break;
77 }
78 }
79
80 LowPathType GetType() const {
81 return type;
82 }
83 47
84 /** 48 /**
85 * Gets the string representation of the path for debugging 49 * Gets the string representation of the path for debugging
86 * @return String representation of the path for debugging 50 * @return String representation of the path for debugging
87 */ 51 */
88 const std::string DebugStr() const { 52 const std::string DebugStr() const;
89 switch (GetType()) {
90 case Invalid:
91 default:
92 return "[Invalid]";
93 case Empty:
94 return "[Empty]";
95 case Binary:
96 {
97 std::stringstream res;
98 res << "[Binary: ";
99 for (unsigned byte : binary)
100 res << std::hex << std::setw(2) << std::setfill('0') << byte;
101 res << ']';
102 return res.str();
103 }
104 case Char:
105 return "[Char: " + AsString() + ']';
106 case Wchar:
107 return "[Wchar: " + AsString() + ']';
108 }
109 }
110 53
111 const std::string AsString() const { 54 const std::string AsString() const;
112 switch (GetType()) { 55 const std::u16string AsU16Str() const;
113 case Char: 56 const std::vector<u8> AsBinary() const;
114 return string;
115 case Wchar:
116 return Common::UTF16ToUTF8(u16str);
117 case Empty:
118 return {};
119 case Invalid:
120 case Binary:
121 default:
122 // TODO(yuriks): Add assert
123 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
124 return {};
125 }
126 }
127
128 const std::u16string AsU16Str() const {
129 switch (GetType()) {
130 case Char:
131 return Common::UTF8ToUTF16(string);
132 case Wchar:
133 return u16str;
134 case Empty:
135 return {};
136 case Invalid:
137 case Binary:
138 // TODO(yuriks): Add assert
139 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
140 return {};
141 }
142 }
143
144 const std::vector<u8> AsBinary() const {
145 switch (GetType()) {
146 case Binary:
147 return binary;
148 case Char:
149 return std::vector<u8>(string.begin(), string.end());
150 case Wchar:
151 {
152 // use two u8 for each character of u16str
153 std::vector<u8> to_return(u16str.size() * 2);
154 for (size_t i = 0; i < u16str.size(); ++i) {
155 u16 tmp_char = u16str.at(i);
156 to_return[i*2] = (tmp_char & 0xFF00) >> 8;
157 to_return[i*2 + 1] = (tmp_char & 0x00FF);
158 }
159 return to_return;
160 }
161 case Empty:
162 return {};
163 case Invalid:
164 default:
165 // TODO(yuriks): Add assert
166 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
167 return {};
168 }
169 }
170 57
171private: 58private:
172 LowPathType type; 59 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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/archive_extsavedata.h" 12#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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/archive_romfs.h" 12#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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/archive_savedata.h" 12#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 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/file_util.h" 5#include "common/file_util.h"
6#include "common/logging/log.h"
6#include "common/make_unique.h" 7#include "common/make_unique.h"
7 8
8#include "core/file_sys/archive_savedatacheck.h" 9#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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/archive_sdmc.h" 12#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 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
7#include <cstddef> 8#include <cstddef>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11
11#include "core/hle/kernel/kernel.h"
12
13//////////////////////////////////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////////////////////////////////
14// FileSys namespace 13// FileSys namespace
15 14
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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/disk_archive.h" 12#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 @@
8#include "common/file_util.h" 8#include "common/file_util.h"
9 9
10#include "core/file_sys/archive_backend.h" 10#include "core/file_sys/archive_backend.h"
11#include "core/file_sys/directory_backend.h"
12#include "core/file_sys/file_backend.h"
11#include "core/loader/loader.h" 13#include "core/loader/loader.h"
12 14
13//////////////////////////////////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////////////////////////////////
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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8 8
9#include "core/hle/kernel/kernel.h"
10
11//////////////////////////////////////////////////////////////////////////////////////////////////// 9////////////////////////////////////////////////////////////////////////////////////////////////////
12// FileSys namespace 10// FileSys namespace
13 11
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 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
9#include "common/make_unique.h" 10#include "common/make_unique.h"
10 11
11#include "core/file_sys/ivfc_archive.h" 12#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 @@
10#include "common/common_types.h" 10#include "common/common_types.h"
11 11
12#include "core/file_sys/archive_backend.h" 12#include "core/file_sys/archive_backend.h"
13#include "core/file_sys/directory_backend.h"
14#include "core/file_sys/file_backend.h"
13#include "core/loader/loader.h" 15#include "core/loader/loader.h"
14 16
15//////////////////////////////////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////////////////////////////////