summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar archshift2014-11-04 00:04:25 -0800
committerGravatar archshift2014-11-10 10:53:26 -0800
commit0ad5964c8b6d7141c6f2a542901a97a280edc545 (patch)
tree81e8d962ef0f84faac9c9a63152953b881183c5f
parentMerge pull request #169 from archshift/autoplay (diff)
downloadyuzu-0ad5964c8b6d7141c6f2a542901a97a280edc545.tar.gz
yuzu-0ad5964c8b6d7141c6f2a542901a97a280edc545.tar.xz
yuzu-0ad5964c8b6d7141c6f2a542901a97a280edc545.zip
Add support for UTF-16 strings for LowPaths in FS:USER
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/fs_user.cpp239
-rw-r--r--src/core/hle/service/fs_user.h29
2 files changed, 182 insertions, 86 deletions
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 48d806e2f..8093254ee 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -5,6 +5,7 @@
5#include "common/common.h" 5#include "common/common.h"
6 6
7#include "fs_user.h" 7#include "fs_user.h"
8#include "common/string_util.h"
8#include "core/settings.h" 9#include "core/settings.h"
9#include "core/hle/kernel/archive.h" 10#include "core/hle/kernel/archive.h"
10 11
@@ -13,18 +14,73 @@
13 14
14namespace FS_User { 15namespace FS_User {
15 16
16// Command to access archive file 17FS_Path::FS_Path(LowPathType type, u32 size, u32 pointer):
17enum class LowPathType : u32 { 18 type(type)
18 Invalid = 0, 19{
19 Empty = 1, 20 switch (type) {
20 Binary = 2, 21 case Binary:
21 Char = 3, 22 {
22 Wchar = 4 23 auto data = Memory::GetPointer(pointer);
23}; 24 binary = std::vector<u8>(data, data + size);
25 break;
26 }
27 case Char:
28 {
29 auto data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
30 string = std::string(data, size - 1);
31 }
32 case Wchar:
33 {
34 auto data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
35 u16str = std::u16string(data, size/2 - 1);
36 }
37 }
38}
39
40FS_Path::LowPathType FS_Path::GetType() const {
41 return type;
42}
43
44const std::vector<u8>& FS_Path::GetBinary() const {
45 return binary;
46}
47
48const std::string& FS_Path::GetString() const {
49 _dbg_assert_msg_(KERNEL, type == Char, "LowPathType is not Char!");
50 return string;
51}
24 52
25std::string GetStringFromCmdBuff(const u32 pointer, const u32 size) { 53const std::u16string& FS_Path::GetU16Str() const {
26 auto data = reinterpret_cast<const char*>(Memory::GetPointer(pointer)); 54 _dbg_assert_msg_(KERNEL, type == Wchar, "LowPathType is not Wchar!");
27 return std::string(data, size - 1); 55 return u16str;
56}
57
58std::string FS_Path::AsString() {
59 switch (GetType()) {
60 case FS_Path::Char:
61 return GetString();
62 case FS_Path::Empty:
63 return {};
64 case FS_Path::Wchar:
65 {
66 auto str16 = GetU16Str();
67 return Common::UTF16ToUTF8(std::wstring(str16.cbegin(), str16.cend()));
68 }
69 }
70}
71
72std::u16string FS_Path::AsU16Str() {
73 switch (GetType()) {
74 case FS_Path::Wchar:
75 return GetU16Str();
76 case FS_Path::Empty:
77 return {};
78 case FS_Path::Char:
79 {
80 auto str = GetString();
81 return std::u16string(str.cbegin(), str.cend());
82 }
83 }
28} 84}
29 85
30// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it 86// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it
@@ -44,32 +100,36 @@ void Initialize(Service::Interface* self) {
44void OpenFile(Service::Interface* self) { 100void OpenFile(Service::Interface* self) {
45 u32* cmd_buff = Service::GetCommandBuffer(); 101 u32* cmd_buff = Service::GetCommandBuffer();
46 102
47 u32 transaction = cmd_buff[1];
48 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 103 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
49 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 104 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
50 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 105 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
51 LowPathType type = static_cast<LowPathType>(cmd_buff[4]); 106 auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]);
52 u32 size = cmd_buff[5]; 107 u32 filename_size = cmd_buff[5];
53 FileSys::Mode mode; mode.hex = cmd_buff[6]; 108 FileSys::Mode mode; mode.hex = cmd_buff[6];
54 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes. 109 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes.
55 u32 pointer = cmd_buff[9]; 110 u32 filename_ptr = cmd_buff[9];
56 111
57 if (type != LowPathType::Char) { 112 FS_Path file_path(filename_type, filename_size, filename_ptr);
58 ERROR_LOG(KERNEL, "file LowPath type other than char is currently unsupported"); 113 std::string file_string;
59 cmd_buff[1] = -1; 114 switch (file_path.GetType()) {
60 return; 115 case FS_Path::Char:
116 case FS_Path::Wchar:
117 file_string = file_path.AsString();
118 break;
119 default:
120 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
121 return;
61 } 122 }
62 123
63 std::string file_name = GetStringFromCmdBuff(pointer, size); 124 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s",
64 125 filename_type, filename_size, mode, attributes, file_string.c_str());
65 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s", type, size, mode, attributes, file_name.c_str());
66 126
67 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_name, mode); 127 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
68 if (handle) { 128 if (handle) {
69 cmd_buff[1] = 0; 129 cmd_buff[1] = 0;
70 cmd_buff[3] = handle; 130 cmd_buff[3] = handle;
71 } else { 131 } else {
72 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_name.c_str()); 132 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_string.c_str());
73 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 133 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
74 cmd_buff[1] = -1; 134 cmd_buff[1] = -1;
75 } 135 }
@@ -80,31 +140,25 @@ void OpenFile(Service::Interface* self) {
80void OpenFileDirectly(Service::Interface* self) { 140void OpenFileDirectly(Service::Interface* self) {
81 u32* cmd_buff = Service::GetCommandBuffer(); 141 u32* cmd_buff = Service::GetCommandBuffer();
82 142
83 u32 transaction = cmd_buff[1]; 143 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]);
84 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); 144 auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]);
85 LowPathType archive_type = static_cast<LowPathType>(cmd_buff[3]); 145 u32 archivename_size = cmd_buff[4];
86 u32 archive_size = cmd_buff[4]; 146 auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[5]);
87 LowPathType file_type = static_cast<LowPathType>(cmd_buff[5]); 147 u32 filename_size = cmd_buff[6];
88 u32 size = cmd_buff[6];
89 FileSys::Mode mode; mode.hex = cmd_buff[7]; 148 FileSys::Mode mode; mode.hex = cmd_buff[7];
90 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes. 149 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
91 u32 archive_pointer = cmd_buff[10]; 150 u32 archivename_ptr = cmd_buff[10];
92 u32 pointer = cmd_buff[12]; 151 u32 filename_ptr = cmd_buff[12];
152
153 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d",
154 archivename_type, archivename_size, filename_type, filename_size, mode, attributes);
93 155
94 if (archive_type != LowPathType::Empty) { 156 if (archivename_type != FS_Path::Empty) {
95 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 157 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
96 cmd_buff[1] = -1; 158 cmd_buff[1] = -1;
97 return; 159 return;
98 } 160 }
99 161
100 std::string archive_name = GetStringFromCmdBuff(archive_pointer, archive_size);
101 std::string file_name = GetStringFromCmdBuff(pointer, size);
102
103 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d archive_data=%s "
104 "file_type=%d file_size=%d file_mode=%d file_attrs=%d file_data=%s",
105 archive_type, archive_size, archive_name.c_str(),
106 file_type, size, mode, attributes, file_name.c_str());
107
108 // TODO(Link Mauve): check if we should even get a handle for the archive, and don't leak it. 162 // TODO(Link Mauve): check if we should even get a handle for the archive, and don't leak it.
109 Handle archive_handle = Kernel::OpenArchive(archive_id); 163 Handle archive_handle = Kernel::OpenArchive(archive_id);
110 if (archive_handle) { 164 if (archive_handle) {
@@ -112,23 +166,30 @@ void OpenFileDirectly(Service::Interface* self) {
112 // cmd_buff[2] isn't used according to 3dmoo's implementation. 166 // cmd_buff[2] isn't used according to 3dmoo's implementation.
113 cmd_buff[3] = archive_handle; 167 cmd_buff[3] = archive_handle;
114 } else { 168 } else {
115 ERROR_LOG(KERNEL, "failed to get a handle for archive %s", archive_name.c_str()); 169 ERROR_LOG(KERNEL, "failed to get a handle for archive");
116 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 170 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
117 cmd_buff[1] = -1; 171 cmd_buff[1] = -1;
118 return; 172 return;
119 } 173 }
120 174
121 if (file_type != LowPathType::Char) { 175 FS_Path file_path(filename_type, filename_size, filename_ptr);
122 WARN_LOG(KERNEL, "file LowPath type other than char is currently unsupported; returning archive handle instead"); 176 std::string file_string;
123 return; 177 switch (file_path.GetType()) {
178 case FS_Path::Char:
179 case FS_Path::Wchar:
180 file_string = file_path.AsString();
181 break;
182 default:
183 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
184 return;
124 } 185 }
125 186
126 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_name, mode); 187 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
127 if (handle) { 188 if (handle) {
128 cmd_buff[1] = 0; 189 cmd_buff[1] = 0;
129 cmd_buff[3] = handle; 190 cmd_buff[3] = handle;
130 } else { 191 } else {
131 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_name.c_str()); 192 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_string.c_str());
132 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 193 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
133 cmd_buff[1] = -1; 194 cmd_buff[1] = -1;
134 } 195 }
@@ -153,21 +214,25 @@ void CreateDirectory(Service::Interface* self) {
153 // TODO: cmd_buff[2], aka archive handle lower word, isn't used according to 214 // TODO: cmd_buff[2], aka archive handle lower word, isn't used according to
154 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 215 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
155 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 216 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
156 LowPathType type = static_cast<LowPathType>(cmd_buff[4]); 217 auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]);
157 u32 name_size = cmd_buff[5]; 218 u32 dirname_size = cmd_buff[5];
158 u32 name_offset = cmd_buff[8]; 219 u32 dirname_ptr = cmd_buff[8];
159 220
160 if (type != LowPathType::Char) { 221 FS_Path dir_path(dirname_type, dirname_size, dirname_ptr);
161 ERROR_LOG(KERNEL, "directory LowPath type other than char is currently unsupported"); 222 std::string dir_string;
162 cmd_buff[1] = -1; 223 switch (dir_path.GetType()) {
163 return; 224 case FS_Path::Char:
225 case FS_Path::Wchar:
226 dir_string = dir_path.AsString();
227 break;
228 default:
229 cmd_buff[1] = -1;
230 return;
164 } 231 }
165 232
166 std::string dir_name = GetStringFromCmdBuff(name_offset, name_size); 233 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
167 234
168 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", type, name_size, dir_name.c_str()); 235 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_string);
169
170 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_name);
171 236
172 DEBUG_LOG(KERNEL, "called"); 237 DEBUG_LOG(KERNEL, "called");
173} 238}
@@ -178,26 +243,30 @@ void OpenDirectory(Service::Interface* self) {
178 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 243 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
179 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 244 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
180 Handle archive_handle = static_cast<Handle>(cmd_buff[2]); 245 Handle archive_handle = static_cast<Handle>(cmd_buff[2]);
181 LowPathType type = static_cast<LowPathType>(cmd_buff[3]); 246 auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]);
182 u32 size = cmd_buff[4]; 247 u32 dirname_size = cmd_buff[4];
183 u32 pointer = cmd_buff[6]; 248 u32 dirname_ptr = cmd_buff[6];
184 249
185 if (type != LowPathType::Char) { 250 FS_Path dir_path(dirname_type, dirname_size, dirname_ptr);
186 ERROR_LOG(KERNEL, "directory LowPath type other than char is currently unsupported"); 251 std::string dir_string;
187 cmd_buff[1] = -1; 252 switch (dir_path.GetType()) {
188 return; 253 case FS_Path::Char:
254 case FS_Path::Wchar:
255 dir_string = dir_path.AsString();
256 break;
257 default:
258 cmd_buff[1] = -1;
259 return;
189 } 260 }
190 261
191 std::string dir_name = GetStringFromCmdBuff(pointer, size); 262 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
192 263
193 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", type, size, dir_name.c_str()); 264 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_string);
194
195 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_name);
196 if (handle) { 265 if (handle) {
197 cmd_buff[1] = 0; 266 cmd_buff[1] = 0;
198 cmd_buff[3] = handle; 267 cmd_buff[3] = handle;
199 } else { 268 } else {
200 ERROR_LOG(KERNEL, "failed to get a handle for directory %s", dir_name.c_str()); 269 ERROR_LOG(KERNEL, "failed to get a handle for directory %s", dir_string.c_str());
201 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 270 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
202 cmd_buff[1] = -1; 271 cmd_buff[1] = -1;
203 } 272 }
@@ -208,28 +277,26 @@ void OpenDirectory(Service::Interface* self) {
208void OpenArchive(Service::Interface* self) { 277void OpenArchive(Service::Interface* self) {
209 u32* cmd_buff = Service::GetCommandBuffer(); 278 u32* cmd_buff = Service::GetCommandBuffer();
210 279
211 auto arch_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); 280 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
212 LowPathType type = static_cast<LowPathType>(cmd_buff[2]); 281 auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[2]);
213 u32 size = cmd_buff[3]; 282 u32 archivename_size = cmd_buff[3];
214 u32 pointer = cmd_buff[5]; 283 u32 archivename_ptr = cmd_buff[5];
284
285 DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size);
215 286
216 if (type != LowPathType::Empty) { 287 if (archivename_type != FS_Path::Empty) {
217 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 288 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
218 cmd_buff[1] = -1; 289 cmd_buff[1] = -1;
219 return; 290 return;
220 } 291 }
221 292
222 std::string archive_name = GetStringFromCmdBuff(pointer, size); 293 Handle handle = Kernel::OpenArchive(archive_id);
223
224 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", type, size, archive_name.c_str());
225
226 Handle handle = Kernel::OpenArchive(arch_id);
227 if (handle) { 294 if (handle) {
228 cmd_buff[1] = 0; 295 cmd_buff[1] = 0;
229 // cmd_buff[2] isn't used according to 3dmoo's implementation. 296 // cmd_buff[2] isn't used according to 3dmoo's implementation.
230 cmd_buff[3] = handle; 297 cmd_buff[3] = handle;
231 } else { 298 } else {
232 ERROR_LOG(KERNEL, "failed to get a handle for archive %s", archive_name.c_str()); 299 ERROR_LOG(KERNEL, "failed to get a handle for archive");
233 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 300 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
234 cmd_buff[1] = -1; 301 cmd_buff[1] = -1;
235 } 302 }
diff --git a/src/core/hle/service/fs_user.h b/src/core/hle/service/fs_user.h
index 005382540..44f89ef4a 100644
--- a/src/core/hle/service/fs_user.h
+++ b/src/core/hle/service/fs_user.h
@@ -11,6 +11,35 @@
11 11
12namespace FS_User { 12namespace FS_User {
13 13
14class FS_Path {
15public:
16 // Command to access archive file
17 enum LowPathType : u32 {
18 Invalid = 0,
19 Empty = 1,
20 Binary = 2,
21 Char = 3,
22 Wchar = 4
23 };
24
25 FS_Path(LowPathType type, u32 size, u32 pointer);
26
27 LowPathType GetType() const;
28
29 const std::vector<u8>& GetBinary() const;
30 const std::string& GetString() const;
31 const std::u16string& GetU16Str() const;
32
33 std::string AsString();
34 std::u16string AsU16Str();
35
36private:
37 LowPathType type;
38 std::vector<u8> binary;
39 std::string string;
40 std::u16string u16str;
41};
42
14/// Interface to "fs:USER" service 43/// Interface to "fs:USER" service
15class Interface : public Service::Interface { 44class Interface : public Service::Interface {
16public: 45public: