diff options
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 407ed047a..8a8ff3092 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | #define stat _stat64 | 26 | #define stat _stat64 |
| 27 | #define fstat _fstat64 | 27 | #define fstat _fstat64 |
| 28 | #define fileno _fileno | 28 | #define fileno _fileno |
| 29 | // Windows version, at least Vista is required to obtain AppData Path | ||
| 30 | #define WINVER 0x0600 | ||
| 31 | #define _WIN32_WINNT 0x0600 | ||
| 29 | #else | 32 | #else |
| 30 | #ifdef __APPLE__ | 33 | #ifdef __APPLE__ |
| 31 | #include <sys/param.h> | 34 | #include <sys/param.h> |
| @@ -594,6 +597,21 @@ std::string& GetExeDirectory() { | |||
| 594 | } | 597 | } |
| 595 | return exe_path; | 598 | return exe_path; |
| 596 | } | 599 | } |
| 600 | |||
| 601 | std::string& AppDataLocalDirectory() { | ||
| 602 | // Windows Vista or later only | ||
| 603 | static std::string local_path; | ||
| 604 | if (local_path.empty()) { | ||
| 605 | PWSTR pw_local_path = 0; | ||
| 606 | wchar_t* wchar_local_path; | ||
| 607 | SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pw_local_path); | ||
| 608 | wchar_local_path = pw_local_path; | ||
| 609 | local_path = Common::UTF16ToUTF8(wchar_local_path); | ||
| 610 | // Freeing memory | ||
| 611 | CoTaskMemFree(static_cast<void*>(pw_local_path)); | ||
| 612 | } | ||
| 613 | return local_path; | ||
| 614 | } | ||
| 597 | #else | 615 | #else |
| 598 | /** | 616 | /** |
| 599 | * @return The user’s home directory on POSIX systems | 617 | * @return The user’s home directory on POSIX systems |
| @@ -671,6 +689,11 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new | |||
| 671 | if (paths[D_USER_IDX].empty()) { | 689 | if (paths[D_USER_IDX].empty()) { |
| 672 | #ifdef _WIN32 | 690 | #ifdef _WIN32 |
| 673 | paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; | 691 | paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; |
| 692 | if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { | ||
| 693 | paths[D_USER_IDX] = | ||
| 694 | AppDataLocalDirectory() + DIR_SEP + EMU_DATA_DIR DIR_SEP USERDATA_DIR DIR_SEP; | ||
| 695 | } | ||
| 696 | |||
| 674 | paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; | 697 | paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; |
| 675 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; | 698 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; |
| 676 | #else | 699 | #else |