|
|
@ -85,7 +85,7 @@ bool Exists(const std::string &filename) |
|
|
StripTailDirSlashes(copy); |
|
|
StripTailDirSlashes(copy); |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); |
|
|
|
|
|
|
|
|
int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
|
|
#else
|
|
|
#else
|
|
|
int result = stat64(copy.c_str(), &file_info); |
|
|
int result = stat64(copy.c_str(), &file_info); |
|
|
#endif
|
|
|
#endif
|
|
|
@ -102,7 +102,7 @@ bool IsDirectory(const std::string &filename) |
|
|
StripTailDirSlashes(copy); |
|
|
StripTailDirSlashes(copy); |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); |
|
|
|
|
|
|
|
|
int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
|
|
#else
|
|
|
#else
|
|
|
int result = stat64(copy.c_str(), &file_info); |
|
|
int result = stat64(copy.c_str(), &file_info); |
|
|
#endif
|
|
|
#endif
|
|
|
@ -138,7 +138,7 @@ bool Delete(const std::string &filename) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) |
|
|
|
|
|
|
|
|
if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) |
|
|
{ |
|
|
{ |
|
|
LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", |
|
|
LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", |
|
|
filename.c_str(), GetLastErrorMsg()); |
|
|
filename.c_str(), GetLastErrorMsg()); |
|
|
@ -160,7 +160,7 @@ bool CreateDir(const std::string &path) |
|
|
{ |
|
|
{ |
|
|
LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
|
|
LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr)) |
|
|
|
|
|
|
|
|
if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) |
|
|
return true; |
|
|
return true; |
|
|
DWORD error = GetLastError(); |
|
|
DWORD error = GetLastError(); |
|
|
if (error == ERROR_ALREADY_EXISTS) |
|
|
if (error == ERROR_ALREADY_EXISTS) |
|
|
@ -241,7 +241,7 @@ bool DeleteDir(const std::string &filename) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (::RemoveDirectory(Common::UTF8ToTStr(filename).c_str())) |
|
|
|
|
|
|
|
|
if (::RemoveDirectoryW(Common::UTF8ToUTF16W(filename).c_str())) |
|
|
return true; |
|
|
return true; |
|
|
#else
|
|
|
#else
|
|
|
if (rmdir(filename.c_str()) == 0) |
|
|
if (rmdir(filename.c_str()) == 0) |
|
|
@ -257,8 +257,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename) |
|
|
{ |
|
|
{ |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", |
|
|
srcFilename.c_str(), destFilename.c_str()); |
|
|
srcFilename.c_str(), destFilename.c_str()); |
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str()) == 0) |
|
|
|
|
|
return true; |
|
|
|
|
|
#else
|
|
|
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
|
|
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
#endif
|
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
@ -270,7 +275,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", |
|
|
srcFilename.c_str(), destFilename.c_str()); |
|
|
srcFilename.c_str(), destFilename.c_str()); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) |
|
|
|
|
|
|
|
|
if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
|
|
@ -358,7 +363,7 @@ u64 GetSize(const std::string &filename) |
|
|
|
|
|
|
|
|
struct stat64 buf; |
|
|
struct stat64 buf; |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) |
|
|
|
|
|
|
|
|
if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0) |
|
|
#else
|
|
|
#else
|
|
|
if (stat64(filename.c_str(), &buf) == 0) |
|
|
if (stat64(filename.c_str(), &buf) == 0) |
|
|
#endif
|
|
|
#endif
|
|
|
@ -432,16 +437,16 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
// Find the first file in the directory.
|
|
|
// Find the first file in the directory.
|
|
|
WIN32_FIND_DATA ffd; |
|
|
|
|
|
|
|
|
WIN32_FIND_DATAW ffd; |
|
|
|
|
|
|
|
|
HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); |
|
|
|
|
|
|
|
|
HANDLE handle_find = FindFirstFileW(Common::UTF8ToUTF16W(directory + "\\*").c_str(), &ffd); |
|
|
if (handle_find == INVALID_HANDLE_VALUE) { |
|
|
if (handle_find == INVALID_HANDLE_VALUE) { |
|
|
FindClose(handle_find); |
|
|
FindClose(handle_find); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
// windows loop
|
|
|
// windows loop
|
|
|
do { |
|
|
do { |
|
|
const std::string virtual_name(Common::TStrToUTF8(ffd.cFileName)); |
|
|
|
|
|
|
|
|
const std::string virtual_name(Common::UTF16ToUTF8(ffd.cFileName)); |
|
|
#else
|
|
|
#else
|
|
|
struct dirent dirent, *result = nullptr; |
|
|
struct dirent dirent, *result = nullptr; |
|
|
|
|
|
|
|
|
@ -465,7 +470,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo |
|
|
found_entries += ret_entries; |
|
|
found_entries += ret_entries; |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
} while (FindNextFile(handle_find, &ffd) != 0); |
|
|
|
|
|
|
|
|
} while (FindNextFileW(handle_find, &ffd) != 0); |
|
|
FindClose(handle_find); |
|
|
FindClose(handle_find); |
|
|
#else
|
|
|
#else
|
|
|
} |
|
|
} |
|
|
@ -900,7 +905,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) |
|
|
{ |
|
|
{ |
|
|
Close(); |
|
|
Close(); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
_tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str()); |
|
|
|
|
|
|
|
|
_wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); |
|
|
#else
|
|
|
#else
|
|
|
m_file = fopen(filename.c_str(), openmode); |
|
|
m_file = fopen(filename.c_str(), openmode); |
|
|
#endif
|
|
|
#endif
|
|
|
|