Fix assorted path issues

This commit is contained in:
Henrik Rydgård 2021-07-19 09:38:04 +02:00
parent a341eb6c32
commit bea9f67c02
8 changed files with 36 additions and 47 deletions

View File

@ -16,20 +16,29 @@
#include <ctype.h>
#include <fcntl.h>
#endif
#include <inttypes.h>
#include "Common/Log.h"
#include "Common/File/Path.h"
#include "Common/File/AndroidStorage.h"
#include "Common/Data/Encoding/Utf8.h"
bool free_disk_space(const std::string &dir, uint64_t &space) {
bool free_disk_space(const Path &path, uint64_t &space) {
#ifdef _WIN32
const std::wstring w32path = ConvertUTF8ToWString(dir);
ULARGE_INTEGER free;
if (GetDiskFreeSpaceExW(w32path.c_str(), &free, nullptr, nullptr)) {
if (GetDiskFreeSpaceExW(path.ToWString().c_str(), &free, nullptr, nullptr)) {
space = free.QuadPart;
return true;
}
#else
if (path.Type() == PathType::CONTENT_URI) {
space = Android_GetFreeSpaceByContentUri(path.ToString());
INFO_LOG(COMMON, "Free space at '%s': %" PRIu64, path.c_str(), space);
return space >= 0;
}
struct statvfs diskstat;
int res = statvfs(dir.c_str(), &diskstat);
int res = statvfs(path.c_str(), &diskstat);
if (res == 0) {
#ifndef __ANDROID__

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <cstdint>
bool free_disk_space(const std::string &dir, uint64_t &space);
#include "Common/File/Path.h"
bool free_disk_space(const Path &path, uint64_t &space);

View File

@ -70,7 +70,8 @@ bool SymbolMap::LoadSymbolMap(const Path &filename) {
std::lock_guard<std::recursive_mutex> guard(lock_);
// TODO(scoped): We're screwed here
// TODO(scoped): Use gzdopen instead.
#if defined(_WIN32) && defined(UNICODE)
gzFile f = gzopen_w(filename.ToWString().c_str(), "r");
#else
@ -195,10 +196,10 @@ void SymbolMap::SaveSymbolMap(const Path &filename) const {
return;
}
// TODO(scoped): Use gzdopen
#if defined(_WIN32) && defined(UNICODE)
gzFile f = gzopen_w(filename.ToWString().c_str(), "w9");
#else
// TODO(scoped): Use gzdopen? If we care, otherwise just compress into a buffer.
gzFile f = gzopen(filename.c_str(), "w9");
#endif

View File

@ -754,9 +754,8 @@ u64 DiskCachingFileLoaderCache::FreeDiskSpace() {
dir = GetSysDirectory(DIRECTORY_CACHE);
}
// TODO(scoped):
uint64_t result = 0;
if (free_disk_space(dir.ToString(), result)) {
if (free_disk_space(dir, result)) {
return result;
}

View File

@ -546,11 +546,6 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname) {
fullName = GetLocalPath(fullPath);
#endif
/*#ifdef _WIN32
return RemoveDirectory(fullName.c_str()) == TRUE;
#else
return 0 == rmdir(fullName.c_str());
#endif*/
bool result = File::DeleteDirRecursively(fullName);
return ReplayApplyDisk(ReplayAction::RMDIR, result, CoreTiming::GetGlobalTimeUs()) != 0;
}
@ -582,14 +577,10 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
Path fullToPath = GetLocalPath(fullTo);
#ifdef _WIN32
bool retValue = (MoveFileEx(fullFrom.ToWString().c_str(), fullToPath.ToWString().c_str(), 0) == TRUE);
#else
bool retValue = (0 == rename(fullFrom.c_str(), fullToPath.c_str()));
#endif
bool retValue = File::Rename(fullFrom, fullToPath);
#if HOST_IS_CASE_SENSITIVE
if (! retValue)
if (!retValue)
{
// May have failed due to case sensitivity on FROM, so try again. Check error code?
std::string fullFromPath = from;
@ -597,11 +588,7 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
return ReplayApplyDisk(ReplayAction::FILE_RENAME, -1, CoreTiming::GetGlobalTimeUs());
fullFrom = GetLocalPath(fullFromPath);
#ifdef _WIN32
retValue = (MoveFile(fullFrom.c_str(), fullToPath.c_str()) == TRUE);
#else
retValue = (0 == rename(fullFrom.c_str(), fullToPath.c_str()));
#endif
retValue = File::Rename(fullFrom, fullToPath);
}
#endif
@ -611,27 +598,20 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
}
bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
Path fullName = GetLocalPath(filename);
#ifdef _WIN32
bool retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
#else
bool retValue = (0 == unlink(fullName.c_str()));
#endif
Path localPath = GetLocalPath(filename);
bool retValue = File::Delete(localPath);
#if HOST_IS_CASE_SENSITIVE
if (! retValue)
if (!retValue)
{
// May have failed due to case sensitivity, so try again. Try even if it fails?
std::string fullNamePath = filename;
if (!FixPathCase(basePath.ToString(), fullNamePath, FPC_FILE_MUST_EXIST))
return (bool)ReplayApplyDisk(ReplayAction::FILE_REMOVE, false, CoreTiming::GetGlobalTimeUs());
fullName = GetLocalPath(fullNamePath);
localPath = GetLocalPath(fullNamePath);
#ifdef _WIN32
retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
#else
retValue = (0 == unlink(fullName.c_str()));
#endif
retValue = File::Delete(localPath);
}
#endif
@ -657,7 +637,7 @@ int DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const
#else
logError = (int)errno;
#endif
ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile(%s): FAILED, %i - access = %d '%s'", filename.c_str(), logError, (int)access, errorString.c_str());
ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile('%s'): FAILED, %d - access = %d '%s'", filename.c_str(), logError, (int)access, errorString.c_str());
return err;
} else {
#ifdef _WIN32
@ -718,7 +698,7 @@ size_t DirectoryFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &use
size_t bytesRead = iter->second.hFile.Read(pointer,size);
return bytesRead;
} else {
//This shouldn't happen...
// This shouldn't happen...
ERROR_LOG(FILESYS,"Cannot read file that hasn't been opened: %08x", handle);
return 0;
}
@ -731,8 +711,7 @@ size_t DirectoryFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
size_t DirectoryFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) {
EntryMap::iterator iter = entries.find(handle);
if (iter != entries.end())
{
if (iter != entries.end()) {
size_t bytesWritten = iter->second.hFile.Write(pointer,size);
return bytesWritten;
} else {
@ -770,6 +749,9 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
return ReplayApplyDiskFileInfo(x, CoreTiming::GetGlobalTimeUs());
#endif
}
// TODO: Consolidate to just a File::GetFileInfo call.
x.type = File::IsDirectory(fullName) ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
x.exists = true;
@ -973,7 +955,7 @@ 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).ToString(), result)) {
if (free_disk_space(GetLocalPath(path), result)) {
return ReplayApplyDisk64(ReplayAction::FREESPACE, result, CoreTiming::GetGlobalTimeUs());
}

View File

@ -863,7 +863,6 @@ namespace SaveState
case SAVESTATE_SAVE_SCREENSHOT:
{
int maxRes = g_Config.iInternalResolution > 2 ? 2 : -1;
// TODO(scoped): Pass the path properly into TakeGameScreenshot.
tempResult = TakeGameScreenshot(op.filename, ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, nullptr, nullptr, maxRes);
callbackResult = tempResult ? Status::SUCCESS : Status::FAILURE;
if (!tempResult) {

View File

@ -203,7 +203,6 @@ void PresentationCommon::CalculatePostShaderUniforms(int bufferWidth, int buffer
static std::string ReadShaderSrc(const Path &filename) {
size_t sz = 0;
// TODO(scoped): VFS paths not handled well.
char *data = (char *)VFSReadFile(filename.c_str(), &sz);
if (!data) {
return "";

View File

@ -786,7 +786,6 @@ void GameBrowser::Refresh() {
// Add any pinned paths before other directories.
auto pinnedPaths = GetPinnedPaths();
for (auto it = pinnedPaths.begin(), end = pinnedPaths.end(); it != end; ++it) {
// TODO(scoped): Hmm
gameList_->Add(new DirButton(*it, GetBaseName((*it).ToString()), *gridStyle_, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT)))->
OnClick.Handle(this, &GameBrowser::NavigateClick);
}