diff options
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c3ae03052..89eac1380 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -192,7 +192,7 @@ bool CreateFullPath(const std::string &fullPath) | |||
| 192 | { | 192 | { |
| 193 | int panicCounter = 100; | 193 | int panicCounter = 100; |
| 194 | LOG_TRACE(Common_Filesystem, "path %s", fullPath.c_str()); | 194 | LOG_TRACE(Common_Filesystem, "path %s", fullPath.c_str()); |
| 195 | 195 | LOG_WARNING(Common_Filesystem, "path %s", fullPath.c_str()); | |
| 196 | if (FileUtil::Exists(fullPath)) | 196 | if (FileUtil::Exists(fullPath)) |
| 197 | { | 197 | { |
| 198 | LOG_WARNING(Common_Filesystem, "path exists %s", fullPath.c_str()); | 198 | LOG_WARNING(Common_Filesystem, "path exists %s", fullPath.c_str()); |
| @@ -577,15 +577,23 @@ void CopyDir(const std::string &source_path, const std::string &dest_path) | |||
| 577 | // Returns the current directory | 577 | // Returns the current directory |
| 578 | std::string GetCurrentDir() | 578 | std::string GetCurrentDir() |
| 579 | { | 579 | { |
| 580 | char *dir; | ||
| 581 | // 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; | ||
| 582 | if (!(dir = getcwd(nullptr, 0))) { | 586 | if (!(dir = getcwd(nullptr, 0))) { |
| 583 | 587 | #endif | |
| 584 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", | 588 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", |
| 585 | GetLastErrorMsg()); | 589 | GetLastErrorMsg()); |
| 586 | return nullptr; | 590 | return nullptr; |
| 587 | } | 591 | } |
| 592 | #ifdef _WIN32 | ||
| 593 | std::string strDir = Common::UTF16ToUTF8(dir); | ||
| 594 | #else | ||
| 588 | std::string strDir = dir; | 595 | std::string strDir = dir; |
| 596 | #endif | ||
| 589 | free(dir); | 597 | free(dir); |
| 590 | return strDir; | 598 | return strDir; |
| 591 | } | 599 | } |
| @@ -593,7 +601,11 @@ std::string GetCurrentDir() | |||
| 593 | // Sets the current directory to the given directory | 601 | // Sets the current directory to the given directory |
| 594 | bool SetCurrentDir(const std::string &directory) | 602 | bool SetCurrentDir(const std::string &directory) |
| 595 | { | 603 | { |
| 604 | #ifdef _WIN32 | ||
| 605 | return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0; | ||
| 606 | #else | ||
| 596 | return chdir(directory.c_str()) == 0; | 607 | return chdir(directory.c_str()) == 0; |
| 608 | #endif | ||
| 597 | } | 609 | } |
| 598 | 610 | ||
| 599 | #if defined(__APPLE__) | 611 | #if defined(__APPLE__) |
| @@ -618,9 +630,9 @@ std::string& GetExeDirectory() | |||
| 618 | static std::string exe_path; | 630 | static std::string exe_path; |
| 619 | if (exe_path.empty()) | 631 | if (exe_path.empty()) |
| 620 | { | 632 | { |
| 621 | TCHAR tchar_exe_path[2048]; | 633 | wchar_t wchar_exe_path[2048]; |
| 622 | GetModuleFileName(nullptr, tchar_exe_path, 2048); | 634 | GetModuleFileNameW(nullptr, wchar_exe_path, 2048); |
| 623 | exe_path = Common::TStrToUTF8(tchar_exe_path); | 635 | exe_path = Common::UTF16ToUTF8(wchar_exe_path); |
| 624 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); | 636 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); |
| 625 | } | 637 | } |
| 626 | return exe_path; | 638 | return exe_path; |