summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/string_util.cpp158
-rw-r--r--src/common/string_util.h8
-rw-r--r--src/core/file_sys/archive.h99
-rw-r--r--src/core/hle/service/fs_user.cpp164
4 files changed, 295 insertions, 134 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 61f0939c4..54943d306 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -9,6 +9,7 @@
9 9
10#ifdef _WIN32 10#ifdef _WIN32
11 #include <Windows.h> 11 #include <Windows.h>
12 #include <codecvt>
12#else 13#else
13 #include <iconv.h> 14 #include <iconv.h>
14#endif 15#endif
@@ -411,7 +412,19 @@ std::string UriEncode(const std::string & sSrc)
411 412
412#ifdef _WIN32 413#ifdef _WIN32
413 414
414std::string UTF16ToUTF8(const std::wstring& input) 415std::string UTF16ToUTF8(const std::u16string& input)
416{
417 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
418 return convert.to_bytes(input);
419}
420
421std::u16string UTF8ToUTF16(const std::string& input)
422{
423 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
424 return convert.from_bytes(input);
425}
426
427static std::string UTF16ToUTF8(const std::wstring& input)
415{ 428{
416 auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), nullptr, 0, nullptr, nullptr); 429 auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), nullptr, 0, nullptr, nullptr);
417 430
@@ -424,7 +437,7 @@ std::string UTF16ToUTF8(const std::wstring& input)
424 return output; 437 return output;
425} 438}
426 439
427std::wstring CPToUTF16(u32 code_page, const std::string& input) 440static std::wstring CPToUTF16(u32 code_page, const std::string& input)
428{ 441{
429 auto const size = MultiByteToWideChar(code_page, 0, input.data(), input.size(), nullptr, 0); 442 auto const size = MultiByteToWideChar(code_page, 0, input.data(), input.size(), nullptr, 0);
430 443
@@ -437,7 +450,7 @@ std::wstring CPToUTF16(u32 code_page, const std::string& input)
437 return output; 450 return output;
438} 451}
439 452
440std::wstring UTF8ToUTF16(const std::string& input) 453std::wstring UTF8ToUTF16W(const std::string &input)
441{ 454{
442 return CPToUTF16(CP_UTF8, input); 455 return CPToUTF16(CP_UTF8, input);
443} 456}
@@ -455,61 +468,123 @@ std::string CP1252ToUTF8(const std::string& input)
455#else 468#else
456 469
457template <typename T> 470template <typename T>
458std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) 471static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input)
459{ 472{
460 std::string result; 473 std::string result;
461 474
462 iconv_t const conv_desc = iconv_open("UTF-8", fromcode); 475 iconv_t const conv_desc = iconv_open("UTF-8", fromcode);
463 if ((iconv_t)-1 == conv_desc) 476 if ((iconv_t)(-1) == conv_desc)
464 { 477 {
465 ERROR_LOG(COMMON, "Iconv initialization failure [%s]: %s", fromcode, strerror(errno)); 478 ERROR_LOG(COMMON, "Iconv initialization failure [%s]: %s", fromcode, strerror(errno));
479 iconv_close(conv_desc);
480 return {};
466 } 481 }
467 else
468 {
469 size_t const in_bytes = sizeof(T) * input.size();
470 size_t const out_buffer_size = 4 * in_bytes;
471 482
472 std::string out_buffer; 483 const size_t in_bytes = sizeof(T) * input.size();
473 out_buffer.resize(out_buffer_size); 484 // Multiply by 4, which is the max number of bytes to encode a codepoint
485 const size_t out_buffer_size = 4 * in_bytes;
474 486
475 auto src_buffer = &input[0]; 487 std::string out_buffer;
476 size_t src_bytes = in_bytes; 488 out_buffer.resize(out_buffer_size);
477 auto dst_buffer = &out_buffer[0];
478 size_t dst_bytes = out_buffer.size();
479 489
480 while (src_bytes != 0) 490 auto src_buffer = &input[0];
481 { 491 size_t src_bytes = in_bytes;
482 size_t const iconv_result = iconv(conv_desc, (char**)(&src_buffer), &src_bytes, 492 auto dst_buffer = &out_buffer[0];
483 &dst_buffer, &dst_bytes); 493 size_t dst_bytes = out_buffer.size();
484 494
485 if ((size_t)-1 == iconv_result) 495 while (0 != src_bytes)
496 {
497 size_t const iconv_result = iconv(conv_desc, (char**)(&src_buffer), &src_bytes,
498 &dst_buffer, &dst_bytes);
499
500 if (static_cast<size_t>(-1) == iconv_result)
501 {
502 if (EILSEQ == errno || EINVAL == errno)
486 { 503 {
487 if (EILSEQ == errno || EINVAL == errno) 504 // Try to skip the bad character
505 if (0 != src_bytes)
488 { 506 {
489 // Try to skip the bad character 507 --src_bytes;
490 if (src_bytes != 0) 508 ++src_buffer;
491 {
492 --src_bytes;
493 ++src_buffer;
494 }
495 }
496 else
497 {
498 ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno));
499 break;
500 } 509 }
501 } 510 }
511 else
512 {
513 ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno));
514 break;
515 }
502 } 516 }
517 }
503 518
504 out_buffer.resize(out_buffer_size - dst_bytes); 519 out_buffer.resize(out_buffer_size - dst_bytes);
505 out_buffer.swap(result); 520 out_buffer.swap(result);
506 521
522 iconv_close(conv_desc);
523
524 return result;
525}
526
527std::u16string UTF8ToUTF16(const std::string& input)
528{
529 std::u16string result;
530
531 iconv_t const conv_desc = iconv_open("UTF-16", "UTF-8");
532 if ((iconv_t)(-1) == conv_desc)
533 {
534 ERROR_LOG(COMMON, "Iconv initialization failure [UTF-8]: %s", strerror(errno));
507 iconv_close(conv_desc); 535 iconv_close(conv_desc);
536 return {};
508 } 537 }
538
539 const size_t in_bytes = sizeof(char) * input.size();
540 // Multiply by 4, which is the max number of bytes to encode a codepoint
541 const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes;
542
543 std::u16string out_buffer;
544 out_buffer.resize(out_buffer_size);
545
546 char* src_buffer = const_cast<char*>(&input[0]);
547 size_t src_bytes = in_bytes;
548 char* dst_buffer = (char*)(&out_buffer[0]);
549 size_t dst_bytes = out_buffer.size();
550
551 while (0 != src_bytes)
552 {
553 size_t const iconv_result = iconv(conv_desc, &src_buffer, &src_bytes,
554 &dst_buffer, &dst_bytes);
555
556 if (static_cast<size_t>(-1) == iconv_result)
557 {
558 if (EILSEQ == errno || EINVAL == errno)
559 {
560 // Try to skip the bad character
561 if (0 != src_bytes)
562 {
563 --src_bytes;
564 ++src_buffer;
565 }
566 }
567 else
568 {
569 ERROR_LOG(COMMON, "iconv failure [UTF-8]: %s", strerror(errno));
570 break;
571 }
572 }
573 }
574
575 out_buffer.resize(out_buffer_size - dst_bytes);
576 out_buffer.swap(result);
577
578 iconv_close(conv_desc);
509 579
510 return result; 580 return result;
511} 581}
512 582
583std::string UTF16ToUTF8(const std::u16string& input)
584{
585 return CodeToUTF8("UTF-16", input);
586}
587
513std::string CP1252ToUTF8(const std::string& input) 588std::string CP1252ToUTF8(const std::string& input)
514{ 589{
515 //return CodeToUTF8("CP1252//TRANSLIT", input); 590 //return CodeToUTF8("CP1252//TRANSLIT", input);
@@ -523,19 +598,6 @@ std::string SHIFTJISToUTF8(const std::string& input)
523 return CodeToUTF8("SJIS", input); 598 return CodeToUTF8("SJIS", input);
524} 599}
525 600
526std::string UTF16ToUTF8(const std::wstring& input)
527{
528 std::string result =
529 // CodeToUTF8("UCS-2", input);
530 // CodeToUTF8("UCS-2LE", input);
531 // CodeToUTF8("UTF-16", input);
532 CodeToUTF8("UTF-16LE", input);
533
534 // TODO: why is this needed?
535 result.erase(std::remove(result.begin(), result.end(), 0x00), result.end());
536 return result;
537}
538
539#endif 601#endif
540 602
541} 603}
diff --git a/src/common/string_util.h b/src/common/string_util.h
index a41ccc691..787a5663f 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -89,20 +89,22 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
89std::string UriDecode(const std::string & sSrc); 89std::string UriDecode(const std::string & sSrc);
90std::string UriEncode(const std::string & sSrc); 90std::string UriEncode(const std::string & sSrc);
91 91
92std::string UTF16ToUTF8(const std::u16string& input);
93std::u16string UTF8ToUTF16(const std::string& input);
94
92std::string CP1252ToUTF8(const std::string& str); 95std::string CP1252ToUTF8(const std::string& str);
93std::string SHIFTJISToUTF8(const std::string& str); 96std::string SHIFTJISToUTF8(const std::string& str);
94std::string UTF16ToUTF8(const std::wstring& str);
95 97
96#ifdef _WIN32 98#ifdef _WIN32
97 99
98std::wstring UTF8ToUTF16(const std::string& str); 100std::wstring UTF8ToUTF16W(const std::string& str);
99 101
100#ifdef _UNICODE 102#ifdef _UNICODE
101inline std::string TStrToUTF8(const std::wstring& str) 103inline std::string TStrToUTF8(const std::wstring& str)
102{ return UTF16ToUTF8(str); } 104{ return UTF16ToUTF8(str); }
103 105
104inline std::wstring UTF8ToTStr(const std::string& str) 106inline std::wstring UTF8ToTStr(const std::string& str)
105{ return UTF8ToUTF16(str); } 107{ return UTF8ToUTF16W(str); }
106#else 108#else
107inline std::string TStrToUTF8(const std::string& str) 109inline std::string TStrToUTF8(const std::string& str)
108{ return str; } 110{ return str; }
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index aeabf09ac..38145eed8 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -7,11 +7,13 @@
7#include <memory> 7#include <memory>
8 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/string_util.h"
10#include "common/bit_field.h" 11#include "common/bit_field.h"
11 12
12#include "core/file_sys/file.h" 13#include "core/file_sys/file.h"
13#include "core/file_sys/directory.h" 14#include "core/file_sys/directory.h"
14 15
16#include "core/mem_map.h"
15#include "core/hle/kernel/kernel.h" 17#include "core/hle/kernel/kernel.h"
16 18
17//////////////////////////////////////////////////////////////////////////////////////////////////// 19////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -19,6 +21,15 @@
19 21
20namespace FileSys { 22namespace FileSys {
21 23
24// Path string type
25enum LowPathType : u32 {
26 Invalid = 0,
27 Empty = 1,
28 Binary = 2,
29 Char = 3,
30 Wchar = 4
31};
32
22union Mode { 33union Mode {
23 u32 hex; 34 u32 hex;
24 BitField<0, 1, u32> read_flag; 35 BitField<0, 1, u32> read_flag;
@@ -26,6 +37,94 @@ union Mode {
26 BitField<2, 1, u32> create_flag; 37 BitField<2, 1, u32> create_flag;
27}; 38};
28 39
40class Path {
41public:
42
43 Path():
44 type(Invalid)
45 {
46 }
47
48 Path(LowPathType type, u32 size, u32 pointer):
49 type(type)
50 {
51 switch (type) {
52 case Binary:
53 {
54 u8* data = Memory::GetPointer(pointer);
55 binary = std::vector<u8>(data, data + size);
56 break;
57 }
58 case Char:
59 {
60 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
61 string = std::string(data, size - 1); // Data is always null-terminated.
62 break;
63 }
64 case Wchar:
65 {
66 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
67 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
68 break;
69 }
70 }
71 }
72
73 LowPathType GetType() const {
74 return type;
75 }
76
77 const std::string AsString() const {
78 switch (GetType()) {
79 case Char:
80 return string;
81 case Wchar:
82 return Common::UTF16ToUTF8(u16str);
83 case Empty:
84 return {};
85 default:
86 ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!");
87 return {};
88 }
89 }
90
91 const std::u16string AsU16Str() const {
92 switch (GetType()) {
93 case Char:
94 return Common::UTF8ToUTF16(string);
95 case Wchar:
96 return u16str;
97 case Empty:
98 return {};
99 default:
100 ERROR_LOG(KERNEL, "LowPathType cannot be converted to u16string!");
101 return {};
102 }
103 }
104
105 const std::vector<u8> AsBinary() const {
106 switch (GetType()) {
107 case Binary:
108 return binary;
109 case Char:
110 return std::vector<u8>(string.begin(), string.end());
111 case Wchar:
112 return std::vector<u8>(u16str.begin(), u16str.end());
113 case Empty:
114 return {};
115 default:
116 ERROR_LOG(KERNEL, "LowPathType cannot be converted to binary!");
117 return {};
118 }
119 }
120
121private:
122 LowPathType type;
123 std::vector<u8> binary;
124 std::string string;
125 std::u16string u16str;
126};
127
29class Archive : NonCopyable { 128class Archive : NonCopyable {
30public: 129public:
31 /// Supported archive types 130 /// Supported archive types
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 48d806e2f..9dc83291d 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,20 +14,6 @@
13 14
14namespace FS_User { 15namespace FS_User {
15 16
16// Command to access archive file
17enum class LowPathType : u32 {
18 Invalid = 0,
19 Empty = 1,
20 Binary = 2,
21 Char = 3,
22 Wchar = 4
23};
24
25std::string GetStringFromCmdBuff(const u32 pointer, const u32 size) {
26 auto data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
27 return std::string(data, size - 1);
28}
29
30// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it 17// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it
31// puts all the sections of the http://3dbrew.org/wiki/Error_codes to something non-zero, to make 18// puts all the sections of the http://3dbrew.org/wiki/Error_codes to something non-zero, to make
32// sure we don't mislead the application into thinking something worked. 19// sure we don't mislead the application into thinking something worked.
@@ -44,32 +31,36 @@ void Initialize(Service::Interface* self) {
44void OpenFile(Service::Interface* self) { 31void OpenFile(Service::Interface* self) {
45 u32* cmd_buff = Service::GetCommandBuffer(); 32 u32* cmd_buff = Service::GetCommandBuffer();
46 33
47 u32 transaction = cmd_buff[1];
48 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 34 // 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. 35 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
50 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 36 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
51 LowPathType type = static_cast<LowPathType>(cmd_buff[4]); 37 auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
52 u32 size = cmd_buff[5]; 38 u32 filename_size = cmd_buff[5];
53 FileSys::Mode mode; mode.hex = cmd_buff[6]; 39 FileSys::Mode mode; mode.hex = cmd_buff[6];
54 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes. 40 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes.
55 u32 pointer = cmd_buff[9]; 41 u32 filename_ptr = cmd_buff[9];
56 42
57 if (type != LowPathType::Char) { 43 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
58 ERROR_LOG(KERNEL, "file LowPath type other than char is currently unsupported"); 44 std::string file_string;
59 cmd_buff[1] = -1; 45 switch (file_path.GetType()) {
46 case FileSys::Char:
47 case FileSys::Wchar:
48 file_string = file_path.AsString();
49 break;
50 default:
51 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
60 return; 52 return;
61 } 53 }
62 54
63 std::string file_name = GetStringFromCmdBuff(pointer, size); 55 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s",
64 56 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 57
67 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_name, mode); 58 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
68 if (handle) { 59 if (handle) {
69 cmd_buff[1] = 0; 60 cmd_buff[1] = 0;
70 cmd_buff[3] = handle; 61 cmd_buff[3] = handle;
71 } else { 62 } else {
72 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_name.c_str()); 63 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. 64 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
74 cmd_buff[1] = -1; 65 cmd_buff[1] = -1;
75 } 66 }
@@ -80,31 +71,25 @@ void OpenFile(Service::Interface* self) {
80void OpenFileDirectly(Service::Interface* self) { 71void OpenFileDirectly(Service::Interface* self) {
81 u32* cmd_buff = Service::GetCommandBuffer(); 72 u32* cmd_buff = Service::GetCommandBuffer();
82 73
83 u32 transaction = cmd_buff[1]; 74 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]);
84 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); 75 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
85 LowPathType archive_type = static_cast<LowPathType>(cmd_buff[3]); 76 u32 archivename_size = cmd_buff[4];
86 u32 archive_size = cmd_buff[4]; 77 auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]);
87 LowPathType file_type = static_cast<LowPathType>(cmd_buff[5]); 78 u32 filename_size = cmd_buff[6];
88 u32 size = cmd_buff[6];
89 FileSys::Mode mode; mode.hex = cmd_buff[7]; 79 FileSys::Mode mode; mode.hex = cmd_buff[7];
90 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes. 80 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
91 u32 archive_pointer = cmd_buff[10]; 81 u32 archivename_ptr = cmd_buff[10];
92 u32 pointer = cmd_buff[12]; 82 u32 filename_ptr = cmd_buff[12];
93 83
94 if (archive_type != LowPathType::Empty) { 84 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d",
85 archivename_type, archivename_size, filename_type, filename_size, mode, attributes);
86
87 if (archivename_type != FileSys::Empty) {
95 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 88 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
96 cmd_buff[1] = -1; 89 cmd_buff[1] = -1;
97 return; 90 return;
98 } 91 }
99 92
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. 93 // 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); 94 Handle archive_handle = Kernel::OpenArchive(archive_id);
110 if (archive_handle) { 95 if (archive_handle) {
@@ -112,23 +97,30 @@ void OpenFileDirectly(Service::Interface* self) {
112 // cmd_buff[2] isn't used according to 3dmoo's implementation. 97 // cmd_buff[2] isn't used according to 3dmoo's implementation.
113 cmd_buff[3] = archive_handle; 98 cmd_buff[3] = archive_handle;
114 } else { 99 } else {
115 ERROR_LOG(KERNEL, "failed to get a handle for archive %s", archive_name.c_str()); 100 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. 101 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
117 cmd_buff[1] = -1; 102 cmd_buff[1] = -1;
118 return; 103 return;
119 } 104 }
120 105
121 if (file_type != LowPathType::Char) { 106 FileSys::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"); 107 std::string file_string;
108 switch (file_path.GetType()) {
109 case FileSys::Char:
110 case FileSys::Wchar:
111 file_string = file_path.AsString();
112 break;
113 default:
114 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
123 return; 115 return;
124 } 116 }
125 117
126 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_name, mode); 118 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
127 if (handle) { 119 if (handle) {
128 cmd_buff[1] = 0; 120 cmd_buff[1] = 0;
129 cmd_buff[3] = handle; 121 cmd_buff[3] = handle;
130 } else { 122 } else {
131 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_name.c_str()); 123 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. 124 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
133 cmd_buff[1] = -1; 125 cmd_buff[1] = -1;
134 } 126 }
@@ -153,21 +145,25 @@ void CreateDirectory(Service::Interface* self) {
153 // TODO: cmd_buff[2], aka archive handle lower word, isn't used according to 145 // 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. 146 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
155 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 147 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
156 LowPathType type = static_cast<LowPathType>(cmd_buff[4]); 148 auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
157 u32 name_size = cmd_buff[5]; 149 u32 dirname_size = cmd_buff[5];
158 u32 name_offset = cmd_buff[8]; 150 u32 dirname_ptr = cmd_buff[8];
159 151
160 if (type != LowPathType::Char) { 152 FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
161 ERROR_LOG(KERNEL, "directory LowPath type other than char is currently unsupported"); 153 std::string dir_string;
154 switch (dir_path.GetType()) {
155 case FileSys::Char:
156 case FileSys::Wchar:
157 dir_string = dir_path.AsString();
158 break;
159 default:
162 cmd_buff[1] = -1; 160 cmd_buff[1] = -1;
163 return; 161 return;
164 } 162 }
165 163
166 std::string dir_name = GetStringFromCmdBuff(name_offset, name_size); 164 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
167 165
168 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", type, name_size, dir_name.c_str()); 166 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_string);
169
170 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_name);
171 167
172 DEBUG_LOG(KERNEL, "called"); 168 DEBUG_LOG(KERNEL, "called");
173} 169}
@@ -178,26 +174,30 @@ void OpenDirectory(Service::Interface* self) {
178 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 174 // 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. 175 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
180 Handle archive_handle = static_cast<Handle>(cmd_buff[2]); 176 Handle archive_handle = static_cast<Handle>(cmd_buff[2]);
181 LowPathType type = static_cast<LowPathType>(cmd_buff[3]); 177 auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
182 u32 size = cmd_buff[4]; 178 u32 dirname_size = cmd_buff[4];
183 u32 pointer = cmd_buff[6]; 179 u32 dirname_ptr = cmd_buff[6];
184 180
185 if (type != LowPathType::Char) { 181 FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
186 ERROR_LOG(KERNEL, "directory LowPath type other than char is currently unsupported"); 182 std::string dir_string;
183 switch (dir_path.GetType()) {
184 case FileSys::Char:
185 case FileSys::Wchar:
186 dir_string = dir_path.AsString();
187 break;
188 default:
187 cmd_buff[1] = -1; 189 cmd_buff[1] = -1;
188 return; 190 return;
189 } 191 }
190 192
191 std::string dir_name = GetStringFromCmdBuff(pointer, size); 193 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
192 194
193 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", type, size, dir_name.c_str()); 195 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_string);
194
195 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_name);
196 if (handle) { 196 if (handle) {
197 cmd_buff[1] = 0; 197 cmd_buff[1] = 0;
198 cmd_buff[3] = handle; 198 cmd_buff[3] = handle;
199 } else { 199 } else {
200 ERROR_LOG(KERNEL, "failed to get a handle for directory %s", dir_name.c_str()); 200 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. 201 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
202 cmd_buff[1] = -1; 202 cmd_buff[1] = -1;
203 } 203 }
@@ -208,28 +208,26 @@ void OpenDirectory(Service::Interface* self) {
208void OpenArchive(Service::Interface* self) { 208void OpenArchive(Service::Interface* self) {
209 u32* cmd_buff = Service::GetCommandBuffer(); 209 u32* cmd_buff = Service::GetCommandBuffer();
210 210
211 auto arch_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); 211 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
212 LowPathType type = static_cast<LowPathType>(cmd_buff[2]); 212 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
213 u32 size = cmd_buff[3]; 213 u32 archivename_size = cmd_buff[3];
214 u32 pointer = cmd_buff[5]; 214 u32 archivename_ptr = cmd_buff[5];
215
216 DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size);
215 217
216 if (type != LowPathType::Empty) { 218 if (archivename_type != FileSys::Empty) {
217 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 219 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
218 cmd_buff[1] = -1; 220 cmd_buff[1] = -1;
219 return; 221 return;
220 } 222 }
221 223
222 std::string archive_name = GetStringFromCmdBuff(pointer, size); 224 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) { 225 if (handle) {
228 cmd_buff[1] = 0; 226 cmd_buff[1] = 0;
229 // cmd_buff[2] isn't used according to 3dmoo's implementation. 227 // cmd_buff[2] isn't used according to 3dmoo's implementation.
230 cmd_buff[3] = handle; 228 cmd_buff[3] = handle;
231 } else { 229 } else {
232 ERROR_LOG(KERNEL, "failed to get a handle for archive %s", archive_name.c_str()); 230 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. 231 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
234 cmd_buff[1] = -1; 232 cmd_buff[1] = -1;
235 } 233 }