summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar LFsWang2016-03-31 18:58:37 +0800
committerGravatar LFsWang2016-03-31 18:58:37 +0800
commitacfa76aa381f7220606962777510809fa55a6a04 (patch)
treeac53fbf9d105f913c87ca1acf4ba2595bfe4e598 /src/common/file_util.cpp
parentMerge pull request #1611 from ObsidianX/cfg-common-fix (diff)
downloadyuzu-acfa76aa381f7220606962777510809fa55a6a04.tar.gz
yuzu-acfa76aa381f7220606962777510809fa55a6a04.tar.xz
yuzu-acfa76aa381f7220606962777510809fa55a6a04.zip
Fix encode problem On Windows
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index c3061479a..c3ae03052 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 }
@@ -900,7 +905,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
900{ 905{
901 Close(); 906 Close();
902#ifdef _WIN32 907#ifdef _WIN32
903 _tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str()); 908 _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str());
904#else 909#else
905 m_file = fopen(filename.c_str(), openmode); 910 m_file = fopen(filename.c_str(), openmode);
906#endif 911#endif