Hopefully fix all filename handling to support Unicode.
This commit is contained in:
parent
69f7671ee8
commit
65683ebc64
|
@ -82,7 +82,7 @@ bool Exists(const std::string &filename)
|
||||||
std::string copy(filename);
|
std::string copy(filename);
|
||||||
StripTailDirSlashes(copy);
|
StripTailDirSlashes(copy);
|
||||||
|
|
||||||
int result = stat64(copy.c_str(), &file_info);
|
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
|
||||||
|
|
||||||
return (result == 0);
|
return (result == 0);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ bool IsDirectory(const std::string &filename)
|
||||||
std::string copy(filename);
|
std::string copy(filename);
|
||||||
StripTailDirSlashes(copy);
|
StripTailDirSlashes(copy);
|
||||||
|
|
||||||
int result = stat64(copy.c_str(), &file_info);
|
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
||||||
|
@ -344,7 +344,7 @@ u64 GetSize(const std::string &filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct stat64 buf;
|
struct stat64 buf;
|
||||||
if (stat64(filename.c_str(), &buf) == 0)
|
if (_tstat64(UTF8ToTStr(filename).c_str(), &buf) == 0)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(COMMON, "GetSize: %s: %lld",
|
DEBUG_LOG(COMMON, "GetSize: %s: %lld",
|
||||||
filename.c_str(), (long long)buf.st_size);
|
filename.c_str(), (long long)buf.st_size);
|
||||||
|
@ -392,13 +392,13 @@ bool CreateEmptyFile(const std::string &filename)
|
||||||
{
|
{
|
||||||
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
||||||
|
|
||||||
FILE *pFile = fopen(filename.c_str(), "wb");
|
if (!File::IOFile(filename, "wb"))
|
||||||
if (!pFile) {
|
{
|
||||||
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fclose(pFile);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,14 +623,14 @@ std::string GetBundleDirectory()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::string &GetExeDirectory()
|
std::string& GetExeDirectory()
|
||||||
{
|
{
|
||||||
static std::string DolphinPath;
|
static std::string DolphinPath;
|
||||||
if (DolphinPath.empty())
|
if (DolphinPath.empty())
|
||||||
{
|
{
|
||||||
char Dolphin_exe_Path[2048];
|
TCHAR Dolphin_exe_Path[2048];
|
||||||
GetModuleFileNameA(NULL, Dolphin_exe_Path, 2048);
|
GetModuleFileName(NULL, Dolphin_exe_Path, 2048);
|
||||||
DolphinPath = Dolphin_exe_Path;
|
DolphinPath = TStrToUTF8(Dolphin_exe_Path);
|
||||||
DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
|
DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
|
||||||
}
|
}
|
||||||
return DolphinPath;
|
return DolphinPath;
|
||||||
|
@ -731,31 +731,19 @@ std::string &GetUserPath(const unsigned int DirIDX, const std::string &newPath)
|
||||||
|
|
||||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename, text_file ? "w" : "wb");
|
return File::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
|
||||||
if (!f)
|
|
||||||
return false;
|
|
||||||
size_t len = str.size();
|
|
||||||
if (len != fwrite(str.data(), 1, str.size(), f)) // TODO: string::data() may not be contiguous
|
|
||||||
{
|
|
||||||
fclose(f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename, text_file ? "r" : "rb");
|
File::IOFile file(filename, text_file ? "r" : "rb");
|
||||||
|
auto const f = file.GetHandle();
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return false;
|
||||||
size_t len = (size_t)GetSize(f);
|
|
||||||
char *buf = new char[len + 1];
|
str.resize(GetSize(f));
|
||||||
buf[fread(buf, 1, len, f)] = 0;
|
return file.ReadArray(&str[0], str.size());
|
||||||
str = std::string(buf, len);
|
|
||||||
fclose(f);
|
|
||||||
delete [] buf;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IOFile::IOFile()
|
IOFile::IOFile()
|
||||||
|
@ -799,7 +787,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fopen_s(&m_file, filename.c_str(), openmode);
|
_tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str());
|
||||||
#else
|
#else
|
||||||
m_file = fopen(filename.c_str(), openmode);
|
m_file = fopen(filename.c_str(), openmode);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
// Modified for Dolphin.
|
// Modified for Dolphin.
|
||||||
|
|
||||||
#include "SDCardUtil.h"
|
#include "SDCardUtil.h"
|
||||||
|
#include "FileUtil.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -190,7 +191,6 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
|
||||||
{
|
{
|
||||||
u32 sectors_per_fat;
|
u32 sectors_per_fat;
|
||||||
u32 sectors_per_disk;
|
u32 sectors_per_disk;
|
||||||
FILE* f;
|
|
||||||
|
|
||||||
// Convert MB to bytes
|
// Convert MB to bytes
|
||||||
disk_size *= 1024 * 1024;
|
disk_size *= 1024 * 1024;
|
||||||
|
@ -207,7 +207,8 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
|
||||||
boot_sector_init(s_boot_sector, s_fsinfo_sector, disk_size, nullptr);
|
boot_sector_init(s_boot_sector, s_fsinfo_sector, disk_size, nullptr);
|
||||||
fat_init(s_fat_head);
|
fat_init(s_fat_head);
|
||||||
|
|
||||||
f = fopen(filename, "wb");
|
File::IOFile file(filename, "wb");
|
||||||
|
FILE* const f = file.GetHandle();
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename);
|
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename);
|
||||||
|
@ -247,13 +248,11 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
|
||||||
|
|
||||||
if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2*sectors_per_fat)) goto FailWrite;
|
if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2*sectors_per_fat)) goto FailWrite;
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
FailWrite:
|
FailWrite:
|
||||||
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename);
|
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename);
|
||||||
if (unlink(filename) < 0)
|
if (unlink(filename) < 0)
|
||||||
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg());
|
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg());
|
||||||
fclose(f);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue