diff options
| author | 2014-11-10 14:36:32 -0800 | |
|---|---|---|
| committer | 2014-11-12 19:30:17 -0800 | |
| commit | 1f7c4ab7f6c5b65d6569a1981b04c1d2ac33b713 (patch) | |
| tree | 61693418f0cbfeddf4e416bae0d265691bf0dfa9 | |
| parent | Add support for UTF-16 strings for LowPaths in FS:USER (diff) | |
| download | yuzu-1f7c4ab7f6c5b65d6569a1981b04c1d2ac33b713.tar.gz yuzu-1f7c4ab7f6c5b65d6569a1981b04c1d2ac33b713.tar.xz yuzu-1f7c4ab7f6c5b65d6569a1981b04c1d2ac33b713.zip | |
Use std::u16string for conversion between UTF-8 and UTF-16, FS:USER functions
Diffstat (limited to '')
| -rw-r--r-- | src/common/string_util.cpp | 158 | ||||
| -rw-r--r-- | src/common/string_util.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive.h | 99 | ||||
| -rw-r--r-- | src/core/hle/service/fs_user.cpp | 149 | ||||
| -rw-r--r-- | src/core/hle/service/fs_user.h | 29 |
5 files changed, 254 insertions, 189 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 | ||
| 414 | std::string UTF16ToUTF8(const std::wstring& input) | 415 | std::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 | |||
| 421 | std::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 | |||
| 427 | static 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 | ||
| 427 | std::wstring CPToUTF16(u32 code_page, const std::string& input) | 440 | static 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 | ||
| 440 | std::wstring UTF8ToUTF16(const std::string& input) | 453 | std::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 | ||
| 457 | template <typename T> | 470 | template <typename T> |
| 458 | std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) | 471 | static 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 | |||
| 527 | std::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 | ||
| 583 | std::string UTF16ToUTF8(const std::u16string& input) | ||
| 584 | { | ||
| 585 | return CodeToUTF8("UTF-16", input); | ||
| 586 | } | ||
| 587 | |||
| 513 | std::string CP1252ToUTF8(const std::string& input) | 588 | std::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 | ||
| 526 | std::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 | |||
| 89 | std::string UriDecode(const std::string & sSrc); | 89 | std::string UriDecode(const std::string & sSrc); |
| 90 | std::string UriEncode(const std::string & sSrc); | 90 | std::string UriEncode(const std::string & sSrc); |
| 91 | 91 | ||
| 92 | std::string UTF16ToUTF8(const std::u16string& input); | ||
| 93 | std::u16string UTF8ToUTF16(const std::string& input); | ||
| 94 | |||
| 92 | std::string CP1252ToUTF8(const std::string& str); | 95 | std::string CP1252ToUTF8(const std::string& str); |
| 93 | std::string SHIFTJISToUTF8(const std::string& str); | 96 | std::string SHIFTJISToUTF8(const std::string& str); |
| 94 | std::string UTF16ToUTF8(const std::wstring& str); | ||
| 95 | 97 | ||
| 96 | #ifdef _WIN32 | 98 | #ifdef _WIN32 |
| 97 | 99 | ||
| 98 | std::wstring UTF8ToUTF16(const std::string& str); | 100 | std::wstring UTF8ToUTF16W(const std::string& str); |
| 99 | 101 | ||
| 100 | #ifdef _UNICODE | 102 | #ifdef _UNICODE |
| 101 | inline std::string TStrToUTF8(const std::wstring& str) | 103 | inline std::string TStrToUTF8(const std::wstring& str) |
| 102 | { return UTF16ToUTF8(str); } | 104 | { return UTF16ToUTF8(str); } |
| 103 | 105 | ||
| 104 | inline std::wstring UTF8ToTStr(const std::string& str) | 106 | inline std::wstring UTF8ToTStr(const std::string& str) |
| 105 | { return UTF8ToUTF16(str); } | 107 | { return UTF8ToUTF16W(str); } |
| 106 | #else | 108 | #else |
| 107 | inline std::string TStrToUTF8(const std::string& str) | 109 | inline 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 | ||
| 20 | namespace FileSys { | 22 | namespace FileSys { |
| 21 | 23 | ||
| 24 | // Path string type | ||
| 25 | enum LowPathType : u32 { | ||
| 26 | Invalid = 0, | ||
| 27 | Empty = 1, | ||
| 28 | Binary = 2, | ||
| 29 | Char = 3, | ||
| 30 | Wchar = 4 | ||
| 31 | }; | ||
| 32 | |||
| 22 | union Mode { | 33 | union 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 | ||
| 40 | class Path { | ||
| 41 | public: | ||
| 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 | |||
| 121 | private: | ||
| 122 | LowPathType type; | ||
| 123 | std::vector<u8> binary; | ||
| 124 | std::string string; | ||
| 125 | std::u16string u16str; | ||
| 126 | }; | ||
| 127 | |||
| 29 | class Archive : NonCopyable { | 128 | class Archive : NonCopyable { |
| 30 | public: | 129 | public: |
| 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 8093254ee..9dc83291d 100644 --- a/src/core/hle/service/fs_user.cpp +++ b/src/core/hle/service/fs_user.cpp | |||
| @@ -14,75 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | namespace FS_User { | 15 | namespace FS_User { |
| 16 | 16 | ||
| 17 | FS_Path::FS_Path(LowPathType type, u32 size, u32 pointer): | ||
| 18 | type(type) | ||
| 19 | { | ||
| 20 | switch (type) { | ||
| 21 | case Binary: | ||
| 22 | { | ||
| 23 | auto data = Memory::GetPointer(pointer); | ||
| 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 | |||
| 40 | FS_Path::LowPathType FS_Path::GetType() const { | ||
| 41 | return type; | ||
| 42 | } | ||
| 43 | |||
| 44 | const std::vector<u8>& FS_Path::GetBinary() const { | ||
| 45 | return binary; | ||
| 46 | } | ||
| 47 | |||
| 48 | const std::string& FS_Path::GetString() const { | ||
| 49 | _dbg_assert_msg_(KERNEL, type == Char, "LowPathType is not Char!"); | ||
| 50 | return string; | ||
| 51 | } | ||
| 52 | |||
| 53 | const std::u16string& FS_Path::GetU16Str() const { | ||
| 54 | _dbg_assert_msg_(KERNEL, type == Wchar, "LowPathType is not Wchar!"); | ||
| 55 | return u16str; | ||
| 56 | } | ||
| 57 | |||
| 58 | std::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 | |||
| 72 | std::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 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | // 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 |
| 87 | // 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 |
| 88 | // sure we don't mislead the application into thinking something worked. | 19 | // sure we don't mislead the application into thinking something worked. |
| @@ -103,22 +34,22 @@ void OpenFile(Service::Interface* self) { | |||
| 103 | // 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 |
| 104 | // 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. |
| 105 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); | 36 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); |
| 106 | auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]); | 37 | auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); |
| 107 | u32 filename_size = cmd_buff[5]; | 38 | u32 filename_size = cmd_buff[5]; |
| 108 | FileSys::Mode mode; mode.hex = cmd_buff[6]; | 39 | FileSys::Mode mode; mode.hex = cmd_buff[6]; |
| 109 | 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. |
| 110 | u32 filename_ptr = cmd_buff[9]; | 41 | u32 filename_ptr = cmd_buff[9]; |
| 111 | 42 | ||
| 112 | FS_Path file_path(filename_type, filename_size, filename_ptr); | 43 | FileSys::Path file_path(filename_type, filename_size, filename_ptr); |
| 113 | std::string file_string; | 44 | std::string file_string; |
| 114 | switch (file_path.GetType()) { | 45 | switch (file_path.GetType()) { |
| 115 | case FS_Path::Char: | 46 | case FileSys::Char: |
| 116 | case FS_Path::Wchar: | 47 | case FileSys::Wchar: |
| 117 | file_string = file_path.AsString(); | 48 | file_string = file_path.AsString(); |
| 118 | break; | 49 | break; |
| 119 | default: | 50 | default: |
| 120 | WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); | 51 | WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); |
| 121 | return; | 52 | return; |
| 122 | } | 53 | } |
| 123 | 54 | ||
| 124 | DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s", | 55 | DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s", |
| @@ -141,9 +72,9 @@ void OpenFileDirectly(Service::Interface* self) { | |||
| 141 | u32* cmd_buff = Service::GetCommandBuffer(); | 72 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 142 | 73 | ||
| 143 | auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); | 74 | auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); |
| 144 | auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]); | 75 | auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]); |
| 145 | u32 archivename_size = cmd_buff[4]; | 76 | u32 archivename_size = cmd_buff[4]; |
| 146 | auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[5]); | 77 | auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]); |
| 147 | u32 filename_size = cmd_buff[6]; | 78 | u32 filename_size = cmd_buff[6]; |
| 148 | FileSys::Mode mode; mode.hex = cmd_buff[7]; | 79 | FileSys::Mode mode; mode.hex = cmd_buff[7]; |
| 149 | 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. |
| @@ -153,7 +84,7 @@ void OpenFileDirectly(Service::Interface* self) { | |||
| 153 | DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d", | 84 | 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); | 85 | archivename_type, archivename_size, filename_type, filename_size, mode, attributes); |
| 155 | 86 | ||
| 156 | if (archivename_type != FS_Path::Empty) { | 87 | if (archivename_type != FileSys::Empty) { |
| 157 | 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"); |
| 158 | cmd_buff[1] = -1; | 89 | cmd_buff[1] = -1; |
| 159 | return; | 90 | return; |
| @@ -172,16 +103,16 @@ void OpenFileDirectly(Service::Interface* self) { | |||
| 172 | return; | 103 | return; |
| 173 | } | 104 | } |
| 174 | 105 | ||
| 175 | FS_Path file_path(filename_type, filename_size, filename_ptr); | 106 | FileSys::Path file_path(filename_type, filename_size, filename_ptr); |
| 176 | std::string file_string; | 107 | std::string file_string; |
| 177 | switch (file_path.GetType()) { | 108 | switch (file_path.GetType()) { |
| 178 | case FS_Path::Char: | 109 | case FileSys::Char: |
| 179 | case FS_Path::Wchar: | 110 | case FileSys::Wchar: |
| 180 | file_string = file_path.AsString(); | 111 | file_string = file_path.AsString(); |
| 181 | break; | 112 | break; |
| 182 | default: | 113 | default: |
| 183 | WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); | 114 | WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); |
| 184 | return; | 115 | return; |
| 185 | } | 116 | } |
| 186 | 117 | ||
| 187 | Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode); | 118 | Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode); |
| @@ -214,20 +145,20 @@ void CreateDirectory(Service::Interface* self) { | |||
| 214 | // 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 |
| 215 | // 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. |
| 216 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); | 147 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); |
| 217 | auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]); | 148 | auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); |
| 218 | u32 dirname_size = cmd_buff[5]; | 149 | u32 dirname_size = cmd_buff[5]; |
| 219 | u32 dirname_ptr = cmd_buff[8]; | 150 | u32 dirname_ptr = cmd_buff[8]; |
| 220 | 151 | ||
| 221 | FS_Path dir_path(dirname_type, dirname_size, dirname_ptr); | 152 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); |
| 222 | std::string dir_string; | 153 | std::string dir_string; |
| 223 | switch (dir_path.GetType()) { | 154 | switch (dir_path.GetType()) { |
| 224 | case FS_Path::Char: | 155 | case FileSys::Char: |
| 225 | case FS_Path::Wchar: | 156 | case FileSys::Wchar: |
| 226 | dir_string = dir_path.AsString(); | 157 | dir_string = dir_path.AsString(); |
| 227 | break; | 158 | break; |
| 228 | default: | 159 | default: |
| 229 | cmd_buff[1] = -1; | 160 | cmd_buff[1] = -1; |
| 230 | return; | 161 | return; |
| 231 | } | 162 | } |
| 232 | 163 | ||
| 233 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); | 164 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); |
| @@ -243,20 +174,20 @@ void OpenDirectory(Service::Interface* self) { | |||
| 243 | // 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 |
| 244 | // 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. |
| 245 | Handle archive_handle = static_cast<Handle>(cmd_buff[2]); | 176 | Handle archive_handle = static_cast<Handle>(cmd_buff[2]); |
| 246 | auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]); | 177 | auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[3]); |
| 247 | u32 dirname_size = cmd_buff[4]; | 178 | u32 dirname_size = cmd_buff[4]; |
| 248 | u32 dirname_ptr = cmd_buff[6]; | 179 | u32 dirname_ptr = cmd_buff[6]; |
| 249 | 180 | ||
| 250 | FS_Path dir_path(dirname_type, dirname_size, dirname_ptr); | 181 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); |
| 251 | std::string dir_string; | 182 | std::string dir_string; |
| 252 | switch (dir_path.GetType()) { | 183 | switch (dir_path.GetType()) { |
| 253 | case FS_Path::Char: | 184 | case FileSys::Char: |
| 254 | case FS_Path::Wchar: | 185 | case FileSys::Wchar: |
| 255 | dir_string = dir_path.AsString(); | 186 | dir_string = dir_path.AsString(); |
| 256 | break; | 187 | break; |
| 257 | default: | 188 | default: |
| 258 | cmd_buff[1] = -1; | 189 | cmd_buff[1] = -1; |
| 259 | return; | 190 | return; |
| 260 | } | 191 | } |
| 261 | 192 | ||
| 262 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); | 193 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); |
| @@ -278,13 +209,13 @@ void OpenArchive(Service::Interface* self) { | |||
| 278 | u32* cmd_buff = Service::GetCommandBuffer(); | 209 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 279 | 210 | ||
| 280 | auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); | 211 | auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); |
| 281 | auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[2]); | 212 | auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); |
| 282 | u32 archivename_size = cmd_buff[3]; | 213 | u32 archivename_size = cmd_buff[3]; |
| 283 | u32 archivename_ptr = cmd_buff[5]; | 214 | u32 archivename_ptr = cmd_buff[5]; |
| 284 | 215 | ||
| 285 | DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size); | 216 | DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size); |
| 286 | 217 | ||
| 287 | if (archivename_type != FS_Path::Empty) { | 218 | if (archivename_type != FileSys::Empty) { |
| 288 | 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"); |
| 289 | cmd_buff[1] = -1; | 220 | cmd_buff[1] = -1; |
| 290 | return; | 221 | return; |
diff --git a/src/core/hle/service/fs_user.h b/src/core/hle/service/fs_user.h index 44f89ef4a..005382540 100644 --- a/src/core/hle/service/fs_user.h +++ b/src/core/hle/service/fs_user.h | |||
| @@ -11,35 +11,6 @@ | |||
| 11 | 11 | ||
| 12 | namespace FS_User { | 12 | namespace FS_User { |
| 13 | 13 | ||
| 14 | class FS_Path { | ||
| 15 | public: | ||
| 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 | |||
| 36 | private: | ||
| 37 | LowPathType type; | ||
| 38 | std::vector<u8> binary; | ||
| 39 | std::string string; | ||
| 40 | std::u16string u16str; | ||
| 41 | }; | ||
| 42 | |||
| 43 | /// Interface to "fs:USER" service | 14 | /// Interface to "fs:USER" service |
| 44 | class Interface : public Service::Interface { | 15 | class Interface : public Service::Interface { |
| 45 | public: | 16 | public: |