diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/file_util.cpp | 51 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 2 | ||||
| -rw-r--r-- | src/common/logging/log.h | 2 | ||||
| -rw-r--r-- | src/common/make_unique.h | 17 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 16 | ||||
| -rw-r--r-- | src/common/string_util.h | 2 |
7 files changed, 47 insertions, 44 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1c9be718f..c839ce173 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -42,7 +42,6 @@ set(HEADERS | |||
| 42 | logging/filter.h | 42 | logging/filter.h |
| 43 | logging/log.h | 43 | logging/log.h |
| 44 | logging/backend.h | 44 | logging/backend.h |
| 45 | make_unique.h | ||
| 46 | math_util.h | 45 | math_util.h |
| 47 | memory_util.h | 46 | memory_util.h |
| 48 | microprofile.h | 47 | microprofile.h |
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c3061479a..9ada09f8a 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -85,7 +85,7 @@ bool Exists(const std::string &filename) | |||
| 85 | StripTailDirSlashes(copy); | 85 | StripTailDirSlashes(copy); |
| 86 | 86 | ||
| 87 | #ifdef _WIN32 | 87 | #ifdef _WIN32 |
| 88 | int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); | 88 | int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
| 89 | #else | 89 | #else |
| 90 | int result = stat64(copy.c_str(), &file_info); | 90 | int result = stat64(copy.c_str(), &file_info); |
| 91 | #endif | 91 | #endif |
| @@ -102,7 +102,7 @@ bool IsDirectory(const std::string &filename) | |||
| 102 | StripTailDirSlashes(copy); | 102 | StripTailDirSlashes(copy); |
| 103 | 103 | ||
| 104 | #ifdef _WIN32 | 104 | #ifdef _WIN32 |
| 105 | int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); | 105 | int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
| 106 | #else | 106 | #else |
| 107 | int result = stat64(copy.c_str(), &file_info); | 107 | int result = stat64(copy.c_str(), &file_info); |
| 108 | #endif | 108 | #endif |
| @@ -138,7 +138,7 @@ bool Delete(const std::string &filename) | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | #ifdef _WIN32 | 140 | #ifdef _WIN32 |
| 141 | if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) | 141 | if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) |
| 142 | { | 142 | { |
| 143 | LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", | 143 | LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", |
| 144 | filename.c_str(), GetLastErrorMsg()); | 144 | filename.c_str(), GetLastErrorMsg()); |
| @@ -160,7 +160,7 @@ bool CreateDir(const std::string &path) | |||
| 160 | { | 160 | { |
| 161 | LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); | 161 | LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
| 162 | #ifdef _WIN32 | 162 | #ifdef _WIN32 |
| 163 | if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr)) | 163 | if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) |
| 164 | return true; | 164 | return true; |
| 165 | DWORD error = GetLastError(); | 165 | DWORD error = GetLastError(); |
| 166 | if (error == ERROR_ALREADY_EXISTS) | 166 | if (error == ERROR_ALREADY_EXISTS) |
| @@ -241,7 +241,7 @@ bool DeleteDir(const std::string &filename) | |||
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | #ifdef _WIN32 | 243 | #ifdef _WIN32 |
| 244 | if (::RemoveDirectory(Common::UTF8ToTStr(filename).c_str())) | 244 | if (::RemoveDirectoryW(Common::UTF8ToUTF16W(filename).c_str())) |
| 245 | return true; | 245 | return true; |
| 246 | #else | 246 | #else |
| 247 | if (rmdir(filename.c_str()) == 0) | 247 | if (rmdir(filename.c_str()) == 0) |
| @@ -257,8 +257,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename) | |||
| 257 | { | 257 | { |
| 258 | LOG_TRACE(Common_Filesystem, "%s --> %s", | 258 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 259 | srcFilename.c_str(), destFilename.c_str()); | 259 | srcFilename.c_str(), destFilename.c_str()); |
| 260 | #ifdef _WIN32 | ||
| 261 | if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str()) == 0) | ||
| 262 | return true; | ||
| 263 | #else | ||
| 260 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) | 264 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
| 261 | return true; | 265 | return true; |
| 266 | #endif | ||
| 262 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", | 267 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| 263 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 268 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 264 | return false; | 269 | return false; |
| @@ -270,7 +275,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 270 | LOG_TRACE(Common_Filesystem, "%s --> %s", | 275 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 271 | srcFilename.c_str(), destFilename.c_str()); | 276 | srcFilename.c_str(), destFilename.c_str()); |
| 272 | #ifdef _WIN32 | 277 | #ifdef _WIN32 |
| 273 | if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) | 278 | if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) |
| 274 | return true; | 279 | return true; |
| 275 | 280 | ||
| 276 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", | 281 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| @@ -358,7 +363,7 @@ u64 GetSize(const std::string &filename) | |||
| 358 | 363 | ||
| 359 | struct stat64 buf; | 364 | struct stat64 buf; |
| 360 | #ifdef _WIN32 | 365 | #ifdef _WIN32 |
| 361 | if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) | 366 | if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0) |
| 362 | #else | 367 | #else |
| 363 | if (stat64(filename.c_str(), &buf) == 0) | 368 | if (stat64(filename.c_str(), &buf) == 0) |
| 364 | #endif | 369 | #endif |
| @@ -432,16 +437,16 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 432 | 437 | ||
| 433 | #ifdef _WIN32 | 438 | #ifdef _WIN32 |
| 434 | // Find the first file in the directory. | 439 | // Find the first file in the directory. |
| 435 | WIN32_FIND_DATA ffd; | 440 | WIN32_FIND_DATAW ffd; |
| 436 | 441 | ||
| 437 | HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); | 442 | HANDLE handle_find = FindFirstFileW(Common::UTF8ToUTF16W(directory + "\\*").c_str(), &ffd); |
| 438 | if (handle_find == INVALID_HANDLE_VALUE) { | 443 | if (handle_find == INVALID_HANDLE_VALUE) { |
| 439 | FindClose(handle_find); | 444 | FindClose(handle_find); |
| 440 | return false; | 445 | return false; |
| 441 | } | 446 | } |
| 442 | // windows loop | 447 | // windows loop |
| 443 | do { | 448 | do { |
| 444 | const std::string virtual_name(Common::TStrToUTF8(ffd.cFileName)); | 449 | const std::string virtual_name(Common::UTF16ToUTF8(ffd.cFileName)); |
| 445 | #else | 450 | #else |
| 446 | struct dirent dirent, *result = nullptr; | 451 | struct dirent dirent, *result = nullptr; |
| 447 | 452 | ||
| @@ -465,7 +470,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 465 | found_entries += ret_entries; | 470 | found_entries += ret_entries; |
| 466 | 471 | ||
| 467 | #ifdef _WIN32 | 472 | #ifdef _WIN32 |
| 468 | } while (FindNextFile(handle_find, &ffd) != 0); | 473 | } while (FindNextFileW(handle_find, &ffd) != 0); |
| 469 | FindClose(handle_find); | 474 | FindClose(handle_find); |
| 470 | #else | 475 | #else |
| 471 | } | 476 | } |
| @@ -572,15 +577,23 @@ void CopyDir(const std::string &source_path, const std::string &dest_path) | |||
| 572 | // Returns the current directory | 577 | // Returns the current directory |
| 573 | std::string GetCurrentDir() | 578 | std::string GetCurrentDir() |
| 574 | { | 579 | { |
| 575 | char *dir; | ||
| 576 | // Get the current working directory (getcwd uses malloc) | 580 | // Get the current working directory (getcwd uses malloc) |
| 581 | #ifdef _WIN32 | ||
| 582 | wchar_t *dir; | ||
| 583 | if (!(dir = _wgetcwd(nullptr, 0))) { | ||
| 584 | #else | ||
| 585 | char *dir; | ||
| 577 | if (!(dir = getcwd(nullptr, 0))) { | 586 | if (!(dir = getcwd(nullptr, 0))) { |
| 578 | 587 | #endif | |
| 579 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", | 588 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", |
| 580 | GetLastErrorMsg()); | 589 | GetLastErrorMsg()); |
| 581 | return nullptr; | 590 | return nullptr; |
| 582 | } | 591 | } |
| 592 | #ifdef _WIN32 | ||
| 593 | std::string strDir = Common::UTF16ToUTF8(dir); | ||
| 594 | #else | ||
| 583 | std::string strDir = dir; | 595 | std::string strDir = dir; |
| 596 | #endif | ||
| 584 | free(dir); | 597 | free(dir); |
| 585 | return strDir; | 598 | return strDir; |
| 586 | } | 599 | } |
| @@ -588,7 +601,11 @@ std::string GetCurrentDir() | |||
| 588 | // Sets the current directory to the given directory | 601 | // Sets the current directory to the given directory |
| 589 | bool SetCurrentDir(const std::string &directory) | 602 | bool SetCurrentDir(const std::string &directory) |
| 590 | { | 603 | { |
| 604 | #ifdef _WIN32 | ||
| 605 | return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0; | ||
| 606 | #else | ||
| 591 | return chdir(directory.c_str()) == 0; | 607 | return chdir(directory.c_str()) == 0; |
| 608 | #endif | ||
| 592 | } | 609 | } |
| 593 | 610 | ||
| 594 | #if defined(__APPLE__) | 611 | #if defined(__APPLE__) |
| @@ -613,9 +630,9 @@ std::string& GetExeDirectory() | |||
| 613 | static std::string exe_path; | 630 | static std::string exe_path; |
| 614 | if (exe_path.empty()) | 631 | if (exe_path.empty()) |
| 615 | { | 632 | { |
| 616 | TCHAR tchar_exe_path[2048]; | 633 | wchar_t wchar_exe_path[2048]; |
| 617 | GetModuleFileName(nullptr, tchar_exe_path, 2048); | 634 | GetModuleFileNameW(nullptr, wchar_exe_path, 2048); |
| 618 | exe_path = Common::TStrToUTF8(tchar_exe_path); | 635 | exe_path = Common::UTF16ToUTF8(wchar_exe_path); |
| 619 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); | 636 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); |
| 620 | } | 637 | } |
| 621 | return exe_path; | 638 | return exe_path; |
| @@ -900,7 +917,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) | |||
| 900 | { | 917 | { |
| 901 | Close(); | 918 | Close(); |
| 902 | #ifdef _WIN32 | 919 | #ifdef _WIN32 |
| 903 | _tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str()); | 920 | _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); |
| 904 | #else | 921 | #else |
| 905 | m_file = fopen(filename.c_str(), openmode); | 922 | m_file = fopen(filename.c_str(), openmode); |
| 906 | #endif | 923 | #endif |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 757e0cf47..3d39f94d5 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -47,8 +47,10 @@ namespace Log { | |||
| 47 | SUB(Service, NIM) \ | 47 | SUB(Service, NIM) \ |
| 48 | SUB(Service, NWM) \ | 48 | SUB(Service, NWM) \ |
| 49 | SUB(Service, CAM) \ | 49 | SUB(Service, CAM) \ |
| 50 | SUB(Service, CECD) \ | ||
| 50 | SUB(Service, CFG) \ | 51 | SUB(Service, CFG) \ |
| 51 | SUB(Service, DSP) \ | 52 | SUB(Service, DSP) \ |
| 53 | SUB(Service, DLP) \ | ||
| 52 | SUB(Service, HID) \ | 54 | SUB(Service, HID) \ |
| 53 | SUB(Service, SOC) \ | 55 | SUB(Service, SOC) \ |
| 54 | SUB(Service, IR) \ | 56 | SUB(Service, IR) \ |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 4da4831c3..b8eede3b8 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -62,8 +62,10 @@ enum class Class : ClassType { | |||
| 62 | Service_NIM, ///< The NIM (Network interface manager) service | 62 | Service_NIM, ///< The NIM (Network interface manager) service |
| 63 | Service_NWM, ///< The NWM (Network wlan manager) service | 63 | Service_NWM, ///< The NWM (Network wlan manager) service |
| 64 | Service_CAM, ///< The CAM (Camera) service | 64 | Service_CAM, ///< The CAM (Camera) service |
| 65 | Service_CECD, ///< The CECD service | ||
| 65 | Service_CFG, ///< The CFG (Configuration) service | 66 | Service_CFG, ///< The CFG (Configuration) service |
| 66 | Service_DSP, ///< The DSP (DSP control) service | 67 | Service_DSP, ///< The DSP (DSP control) service |
| 68 | Service_DLP, ///< The DLP (Download Play) service | ||
| 67 | Service_HID, ///< The HID (Human interface device) service | 69 | Service_HID, ///< The HID (Human interface device) service |
| 68 | Service_SOC, ///< The SOC (Socket) service | 70 | Service_SOC, ///< The SOC (Socket) service |
| 69 | Service_IR, ///< The IR service | 71 | Service_IR, ///< The IR service |
diff --git a/src/common/make_unique.h b/src/common/make_unique.h deleted file mode 100644 index f6e7f017c..000000000 --- a/src/common/make_unique.h +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <memory> | ||
| 9 | |||
| 10 | namespace Common { | ||
| 11 | |||
| 12 | template <typename T, typename... Args> | ||
| 13 | std::unique_ptr<T> make_unique(Args&&... args) { | ||
| 14 | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | ||
| 15 | } | ||
| 16 | |||
| 17 | } // namespace | ||
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 6d6fc591f..f0aa072db 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -320,27 +320,27 @@ std::u16string UTF8ToUTF16(const std::string& input) | |||
| 320 | #endif | 320 | #endif |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | static std::string UTF16ToUTF8(const std::wstring& input) | 323 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) |
| 324 | { | 324 | { |
| 325 | auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); | 325 | auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); |
| 326 | 326 | ||
| 327 | std::string output; | 327 | std::wstring output; |
| 328 | output.resize(size); | 328 | output.resize(size); |
| 329 | 329 | ||
| 330 | if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) | 330 | if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) |
| 331 | output.clear(); | 331 | output.clear(); |
| 332 | 332 | ||
| 333 | return output; | 333 | return output; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) | 336 | std::string UTF16ToUTF8(const std::wstring& input) |
| 337 | { | 337 | { |
| 338 | auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); | 338 | auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); |
| 339 | 339 | ||
| 340 | std::wstring output; | 340 | std::string output; |
| 341 | output.resize(size); | 341 | output.resize(size); |
| 342 | 342 | ||
| 343 | if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) | 343 | if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) |
| 344 | output.clear(); | 344 | output.clear(); |
| 345 | 345 | ||
| 346 | return output; | 346 | return output; |
diff --git a/src/common/string_util.h b/src/common/string_util.h index c5c474c6f..89d9f133e 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -95,7 +95,7 @@ std::string CP1252ToUTF8(const std::string& str); | |||
| 95 | std::string SHIFTJISToUTF8(const std::string& str); | 95 | std::string SHIFTJISToUTF8(const std::string& str); |
| 96 | 96 | ||
| 97 | #ifdef _WIN32 | 97 | #ifdef _WIN32 |
| 98 | 98 | std::string UTF16ToUTF8(const std::wstring& input); | |
| 99 | std::wstring UTF8ToUTF16W(const std::string& str); | 99 | std::wstring UTF8ToUTF16W(const std::string& str); |
| 100 | 100 | ||
| 101 | #ifdef _UNICODE | 101 | #ifdef _UNICODE |