mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-25 00:04:49 +02:00
Introduce Path, start using it all over the place.
Still lots left to convert! Convert GetSysDirectory to return Path. More buildfixing Remove unnecessary Path( constructors
This commit is contained in:
@@ -163,7 +163,7 @@ bool FixPathCase(const std::string &basePath, std::string &path, FixPathCaseBeha
|
||||
|
||||
#endif
|
||||
|
||||
DirectoryFileSystem::DirectoryFileSystem(IHandleAllocator *_hAlloc, std::string _basePath, FileSystemFlags _flags) : basePath(_basePath), flags(_flags) {
|
||||
DirectoryFileSystem::DirectoryFileSystem(IHandleAllocator *_hAlloc, const Path & _basePath, FileSystemFlags _flags) : basePath(_basePath), flags(_flags) {
|
||||
File::CreateFullPath(basePath);
|
||||
hAlloc = _hAlloc;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ DirectoryFileSystem::~DirectoryFileSystem() {
|
||||
CloseAll();
|
||||
}
|
||||
|
||||
std::string DirectoryFileHandle::GetLocalPath(const std::string &basePath, std::string localpath)
|
||||
Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string localpath)
|
||||
{
|
||||
if (localpath.empty())
|
||||
return basePath;
|
||||
@@ -180,23 +180,18 @@ std::string DirectoryFileHandle::GetLocalPath(const std::string &basePath, std::
|
||||
if (localpath[0] == '/')
|
||||
localpath.erase(0, 1);
|
||||
|
||||
std::string result = basePath + localpath;
|
||||
#ifdef _WIN32
|
||||
for (char &c : result) {
|
||||
if (c == '/')
|
||||
c = '\\';
|
||||
}
|
||||
#endif
|
||||
Path result = basePath / localpath;
|
||||
// TODO?: Windows used to translate to backslashes here.
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileName, FileAccess access, u32 &error) {
|
||||
bool DirectoryFileHandle::Open(const Path &basePath, std::string &fileName, FileAccess access, u32 &error) {
|
||||
error = 0;
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
if (access & (FILEACCESS_APPEND|FILEACCESS_CREATE|FILEACCESS_WRITE)) {
|
||||
DEBUG_LOG(FILESYS, "Checking case for path %s", fileName.c_str());
|
||||
if (!FixPathCase(basePath, fileName, FPC_PATH_MUST_EXIST)) {
|
||||
if (!FixPathCase(basePath.ToString(), fileName, FPC_PATH_MUST_EXIST)) {
|
||||
error = SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
return false; // or go on and attempt (for a better error code than just 0?)
|
||||
}
|
||||
@@ -204,8 +199,8 @@ bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileNam
|
||||
// else we try fopen first (in case we're lucky) before simulating case insensitivity
|
||||
#endif
|
||||
|
||||
std::string fullName = GetLocalPath(basePath, fileName);
|
||||
VERBOSE_LOG(FILESYS,"Actually opening %s", fullName.c_str());
|
||||
Path fullName = GetLocalPath(basePath, fileName);
|
||||
VERBOSE_LOG(FILESYS, "Actually opening %s", fullName.c_str());
|
||||
|
||||
// On the PSP, truncating doesn't lose data. If you seek later, you'll recover it.
|
||||
// This is abnormal, so we deviate from the PSP's behavior and truncate on write/close.
|
||||
@@ -240,9 +235,9 @@ bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileNam
|
||||
|
||||
// Let's do it!
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
hFile = CreateFile2(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, openmode, nullptr);
|
||||
hFile = CreateFile2(fullName.ToWString().c_str(), desired, sharemode, openmode, nullptr);
|
||||
#else
|
||||
hFile = CreateFile(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, 0, openmode, 0, 0);
|
||||
hFile = CreateFile(fullName.ToWString().c_str(), desired, sharemode, 0, openmode, 0, 0);
|
||||
#endif
|
||||
bool success = hFile != INVALID_HANDLE_VALUE;
|
||||
if (!success) {
|
||||
@@ -252,9 +247,9 @@ bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileNam
|
||||
// Sometimes, the file is locked for write, let's try again.
|
||||
sharemode |= FILE_SHARE_WRITE;
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
hFile = CreateFile2(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, openmode, nullptr);
|
||||
hFile = CreateFile2(fullName.ToWString().c_str(), desired, sharemode, openmode, nullptr);
|
||||
#else
|
||||
hFile = CreateFile(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, 0, openmode, 0, 0);
|
||||
hFile = CreateFile(fullName.ToWString().c_str(), desired, sharemode, 0, openmode, 0, 0);
|
||||
#endif
|
||||
success = hFile != INVALID_HANDLE_VALUE;
|
||||
if (!success) {
|
||||
@@ -296,11 +291,11 @@ bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileNam
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
if (!success && !(access & FILEACCESS_CREATE)) {
|
||||
if (!FixPathCase(basePath, fileName, FPC_PATH_MUST_EXIST)) {
|
||||
if (!FixPathCase(basePath.ToString(), fileName, FPC_PATH_MUST_EXIST)) {
|
||||
error = SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
return false;
|
||||
}
|
||||
fullName = GetLocalPath(basePath,fileName);
|
||||
fullName = GetLocalPath(basePath, fileName);
|
||||
const char *fullNameC = fullName.c_str();
|
||||
|
||||
DEBUG_LOG(FILESYS, "Case may have been incorrect, second try opening %s (%s)", fullNameC, fileName.c_str());
|
||||
@@ -337,7 +332,7 @@ bool DirectoryFileHandle::Open(const std::string &basePath, std::string &fileNam
|
||||
#endif
|
||||
|
||||
// Try to detect reads/writes to PSP/GAME to avoid them in replays.
|
||||
if (fullName.find("PSP/GAME/") != fullName.npos || fullName.find("PSP\\GAME\\") != fullName.npos) {
|
||||
if (fullName.FilePathContains("PSP/GAME/")) {
|
||||
inGameDir_ = true;
|
||||
}
|
||||
|
||||
@@ -479,20 +474,20 @@ void DirectoryFileSystem::CloseAll() {
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
std::string DirectoryFileSystem::GetLocalPath(std::string localpath) {
|
||||
if (localpath.empty())
|
||||
Path DirectoryFileSystem::GetLocalPath(std::string internalPath) {
|
||||
if (internalPath.empty())
|
||||
return basePath;
|
||||
|
||||
if (localpath[0] == '/')
|
||||
localpath.erase(0,1);
|
||||
if (internalPath[0] == '/')
|
||||
internalPath.erase(0, 1);
|
||||
//Convert slashes
|
||||
#ifdef _WIN32
|
||||
for (size_t i = 0; i < localpath.size(); i++) {
|
||||
if (localpath[i] == '/')
|
||||
localpath[i] = '\\';
|
||||
for (size_t i = 0; i < internalPath.size(); i++) {
|
||||
if (internalPath[i] == '/')
|
||||
internalPath[i] = '\\';
|
||||
}
|
||||
#endif
|
||||
return basePath + localpath;
|
||||
return basePath / internalPath;
|
||||
}
|
||||
|
||||
bool DirectoryFileSystem::MkDir(const std::string &dirname) {
|
||||
@@ -502,7 +497,7 @@ bool DirectoryFileSystem::MkDir(const std::string &dirname) {
|
||||
// duplicate (different case) directories
|
||||
|
||||
std::string fixedCase = dirname;
|
||||
if (!FixPathCase(basePath,fixedCase, FPC_PARTIAL_ALLOWED))
|
||||
if (!FixPathCase(basePath.ToString(), fixedCase, FPC_PARTIAL_ALLOWED))
|
||||
result = false;
|
||||
else
|
||||
result = File::CreateFullPath(GetLocalPath(fixedCase));
|
||||
@@ -513,19 +508,19 @@ bool DirectoryFileSystem::MkDir(const std::string &dirname) {
|
||||
}
|
||||
|
||||
bool DirectoryFileSystem::RmDir(const std::string &dirname) {
|
||||
std::string fullName = GetLocalPath(dirname);
|
||||
Path fullName = GetLocalPath(dirname);
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
// Maybe we're lucky?
|
||||
if (File::DeleteDirRecursively(fullName))
|
||||
if (File::DeleteDirRecursively(fullName.ToString()))
|
||||
return (bool)ReplayApplyDisk(ReplayAction::RMDIR, true, CoreTiming::GetGlobalTimeUs());
|
||||
|
||||
// Nope, fix case and try again. Should we try again?
|
||||
fullName = dirname;
|
||||
if (!FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST))
|
||||
std::string fullPath = dirname;
|
||||
if (!FixPathCase(basePath.ToString(), fullPath, FPC_FILE_MUST_EXIST))
|
||||
return (bool)ReplayApplyDisk(ReplayAction::RMDIR, false, CoreTiming::GetGlobalTimeUs());
|
||||
|
||||
fullName = GetLocalPath(fullName);
|
||||
fullName = GetLocalPath(fullPath);
|
||||
#endif
|
||||
|
||||
/*#ifdef _WIN32
|
||||
@@ -533,7 +528,7 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname) {
|
||||
#else
|
||||
return 0 == rmdir(fullName.c_str());
|
||||
#endif*/
|
||||
bool result = File::DeleteDirRecursively(fullName);
|
||||
bool result = File::DeleteDirRecursively(fullName.ToString());
|
||||
return ReplayApplyDisk(ReplayAction::RMDIR, result, CoreTiming::GetGlobalTimeUs()) != 0;
|
||||
}
|
||||
|
||||
@@ -554,36 +549,35 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
|
||||
if (from == fullTo)
|
||||
return ReplayApplyDisk(ReplayAction::FILE_RENAME, SCE_KERNEL_ERROR_ERRNO_FILE_ALREADY_EXISTS, CoreTiming::GetGlobalTimeUs());
|
||||
|
||||
std::string fullFrom = GetLocalPath(from);
|
||||
Path fullFrom = GetLocalPath(from);
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
// In case TO should overwrite a file with different case. Check error code?
|
||||
if (!FixPathCase(basePath,fullTo, FPC_PATH_MUST_EXIST))
|
||||
if (!FixPathCase(basePath.ToString(), fullTo, FPC_PATH_MUST_EXIST))
|
||||
return ReplayApplyDisk(ReplayAction::FILE_RENAME, -1, CoreTiming::GetGlobalTimeUs());
|
||||
#endif
|
||||
|
||||
fullTo = GetLocalPath(fullTo);
|
||||
const char * fullToC = fullTo.c_str();
|
||||
Path fullToPath = GetLocalPath(fullTo);
|
||||
|
||||
#ifdef _WIN32
|
||||
bool retValue = (MoveFileEx(ConvertUTF8ToWString(fullFrom).c_str(), ConvertUTF8ToWString(fullToC).c_str(), 0) == TRUE);
|
||||
bool retValue = (MoveFileEx(fullFrom.ToWString().c_str(), fullToPath.ToWString().c_str(), 0) == TRUE);
|
||||
#else
|
||||
bool retValue = (0 == rename(fullFrom.c_str(), fullToC));
|
||||
bool retValue = (0 == rename(fullFrom.c_str(), fullToPath.c_str()));
|
||||
#endif
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
if (! retValue)
|
||||
{
|
||||
// May have failed due to case sensitivity on FROM, so try again. Check error code?
|
||||
fullFrom = from;
|
||||
if (!FixPathCase(basePath,fullFrom, FPC_FILE_MUST_EXIST))
|
||||
std::string fullFromPath = from;
|
||||
if (!FixPathCase(basePath.ToString(), fullFromPath, FPC_FILE_MUST_EXIST))
|
||||
return ReplayApplyDisk(ReplayAction::FILE_RENAME, -1, CoreTiming::GetGlobalTimeUs());
|
||||
fullFrom = GetLocalPath(fullFrom);
|
||||
fullFrom = GetLocalPath(fullFromPath);
|
||||
|
||||
#ifdef _WIN32
|
||||
retValue = (MoveFile(fullFrom.c_str(), fullToC) == TRUE);
|
||||
retValue = (MoveFile(fullFrom.c_str(), fullToPath.c_str()) == TRUE);
|
||||
#else
|
||||
retValue = (0 == rename(fullFrom.c_str(), fullToC));
|
||||
retValue = (0 == rename(fullFrom.c_str(), fullToPath.c_str()));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -594,7 +588,7 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
|
||||
}
|
||||
|
||||
bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
Path fullName = GetLocalPath(filename);
|
||||
#ifdef _WIN32
|
||||
bool retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
|
||||
#else
|
||||
@@ -605,10 +599,10 @@ bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
|
||||
if (! retValue)
|
||||
{
|
||||
// May have failed due to case sensitivity, so try again. Try even if it fails?
|
||||
fullName = filename;
|
||||
if (!FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST))
|
||||
std::string fullNamePath = filename;
|
||||
if (!FixPathCase(basePath.ToString(), fullNamePath, FPC_FILE_MUST_EXIST))
|
||||
return (bool)ReplayApplyDisk(ReplayAction::FILE_REMOVE, false, CoreTiming::GetGlobalTimeUs());
|
||||
fullName = GetLocalPath(fullName);
|
||||
fullName = GetLocalPath(fullNamePath);
|
||||
|
||||
#ifdef _WIN32
|
||||
retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
|
||||
@@ -736,10 +730,10 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
||||
PSPFileInfo x;
|
||||
x.name = filename;
|
||||
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
Path fullName = GetLocalPath(filename);
|
||||
if (!File::Exists(fullName)) {
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
if (! FixPathCase(basePath,filename, FPC_FILE_MUST_EXIST))
|
||||
if (! FixPathCase(basePath.ToString(), filename, FPC_FILE_MUST_EXIST))
|
||||
return ReplayApplyDiskFileInfo(x, CoreTiming::GetGlobalTimeUs());
|
||||
fullName = GetLocalPath(filename);
|
||||
|
||||
@@ -754,7 +748,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
||||
|
||||
if (x.type != FILETYPE_DIRECTORY) {
|
||||
File::FileInfo info;
|
||||
if (!File::GetFileInfo(fullName.c_str(), &info)) {
|
||||
if (!File::GetFileInfo(fullName, &info)) {
|
||||
ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: GetFileInfo failed: %s", fullName.c_str());
|
||||
} else {
|
||||
x.size = info.size;
|
||||
@@ -772,7 +766,8 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
||||
return ReplayApplyDiskFileInfo(x, CoreTiming::GetGlobalTimeUs());
|
||||
}
|
||||
|
||||
bool DirectoryFileSystem::GetHostPath(const std::string &inpath, std::string &outpath) {
|
||||
// Same as GetLocalPath. Confusing.
|
||||
bool DirectoryFileSystem::GetHostPath(const std::string &inpath, Path &outpath) {
|
||||
outpath = GetLocalPath(inpath);
|
||||
return true;
|
||||
}
|
||||
@@ -858,9 +853,9 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
WIN32_FIND_DATA findData;
|
||||
HANDLE hFind;
|
||||
|
||||
std::string w32path = GetLocalPath(path) + "\\*.*";
|
||||
std::wstring w32path = GetLocalPath(path).ToWString() + L"\\*.*";
|
||||
|
||||
hFind = FindFirstFileEx(ConvertUTF8ToWString(w32path).c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0);
|
||||
hFind = FindFirstFileEx(w32path.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
// Just return the empty array.
|
||||
@@ -905,11 +900,11 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
FindClose(hFind);
|
||||
#else
|
||||
dirent *dirp;
|
||||
std::string localPath = GetLocalPath(path);
|
||||
Path localPath = GetLocalPath(path);
|
||||
DIR *dp = opendir(localPath.c_str());
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
if (dp == NULL && FixPathCase(basePath,path, FPC_FILE_MUST_EXIST)) {
|
||||
if (dp == NULL && FixPathCase(basePath.ToString(), path, FPC_FILE_MUST_EXIST)) {
|
||||
// May have failed due to case sensitivity, try again
|
||||
localPath = GetLocalPath(path);
|
||||
dp = opendir(localPath.c_str());
|
||||
@@ -925,7 +920,7 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
while ((dirp = readdir(dp)) != NULL) {
|
||||
PSPFileInfo entry;
|
||||
struct stat s;
|
||||
std::string fullName = GetLocalPath(path) + "/"+dirp->d_name;
|
||||
Path fullName = GetLocalPath(path) / std::string(dirp->d_name);
|
||||
stat(fullName.c_str(), &s);
|
||||
if (S_ISDIR(s.st_mode))
|
||||
entry.type = FILETYPE_DIRECTORY;
|
||||
@@ -957,15 +952,15 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
|
||||
u64 DirectoryFileSystem::FreeSpace(const std::string &path) {
|
||||
uint64_t result = 0;
|
||||
if (free_disk_space(GetLocalPath(path), result)) {
|
||||
if (free_disk_space(GetLocalPath(path).ToString(), result)) {
|
||||
return ReplayApplyDisk64(ReplayAction::FREESPACE, result, CoreTiming::GetGlobalTimeUs());
|
||||
}
|
||||
|
||||
#if HOST_IS_CASE_SENSITIVE
|
||||
std::string fixedCase = path;
|
||||
if (FixPathCase(basePath, fixedCase, FPC_FILE_MUST_EXIST)) {
|
||||
if (FixPathCase(basePath.ToString(), fixedCase, FPC_FILE_MUST_EXIST)) {
|
||||
// May have failed due to case sensitivity, try again.
|
||||
if (free_disk_space(GetLocalPath(fixedCase), result)) {
|
||||
if (free_disk_space(GetLocalPath(fixedCase).ToString(), result)) {
|
||||
return ReplayApplyDisk64(ReplayAction::FREESPACE, result, CoreTiming::GetGlobalTimeUs());
|
||||
}
|
||||
}
|
||||
@@ -1182,7 +1177,7 @@ size_t VFSFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
|
||||
}
|
||||
|
||||
|
||||
bool VFSFileSystem::GetHostPath(const std::string &inpath, std::string &outpath) {
|
||||
bool VFSFileSystem::GetHostPath(const std::string &inpath, Path &outpath) {
|
||||
// NOT SUPPORTED
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user