Change Copy, Rename to use Path. Remove std::string version of Exists().

Buildfixes

Buildfix
This commit is contained in:
Henrik Rydgård 2021-05-09 15:02:46 +02:00
parent 0d80362c30
commit ae06499a0c
24 changed files with 176 additions and 128 deletions

View File

@ -75,7 +75,7 @@ const char syscpupresentfile[] = "/sys/devices/system/cpu/present";
std::string GetCPUString() {
std::string procdata;
bool readSuccess = File::ReadFileToString(true, procfile, procdata);
bool readSuccess = File::ReadFileToString(true, Path(procfile), procdata);
std::istringstream file(procdata);
std::string cpu_string;
@ -98,7 +98,7 @@ std::string GetCPUString() {
std::string GetCPUBrandString() {
std::string procdata;
bool readSuccess = File::ReadFileToString(true, procfile, procdata);
bool readSuccess = File::ReadFileToString(true, Path(procfile), procdata);
std::istringstream file(procdata);
std::string brand_string;
@ -128,7 +128,7 @@ unsigned char GetCPUImplementer()
unsigned char implementer = 0;
std::string procdata;
if (!File::ReadFileToString(true, procfile, procdata))
if (!File::ReadFileToString(true, Path(procfile), procdata))
return 0;
std::istringstream file(procdata);
@ -151,7 +151,7 @@ unsigned short GetCPUPart()
unsigned short part = 0;
std::string procdata;
if (!File::ReadFileToString(true, procfile, procdata))
if (!File::ReadFileToString(true, Path(procfile), procdata))
return 0;
std::istringstream file(procdata);
@ -173,7 +173,7 @@ bool CheckCPUFeature(const std::string& feature)
std::string line, marker = "Features\t: ";
std::string procdata;
if (!File::ReadFileToString(true, procfile, procdata))
if (!File::ReadFileToString(true, Path(procfile), procdata))
return false;
std::istringstream file(procdata);
while (std::getline(file, line))
@ -199,7 +199,7 @@ int GetCoreCount()
int cores = 1;
std::string presentData;
bool presentSuccess = File::ReadFileToString(true, syscpupresentfile, presentData);
bool presentSuccess = File::ReadFileToString(true, Path(syscpupresentfile), presentData);
std::istringstream presentFile(presentData);
if (presentSuccess) {
@ -213,7 +213,7 @@ int GetCoreCount()
}
std::string procdata;
if (!File::ReadFileToString(true, procfile, procdata))
if (!File::ReadFileToString(true, Path(procfile), procdata))
return 1;
std::istringstream file(procdata);

View File

@ -524,7 +524,7 @@ bool IniFile::Load(const Path &path)
// Open file
std::string data;
if (!File::ReadFileToString(true, path.ToString().c_str(), data)) {
if (!File::ReadFileToString(true, path, data)) {
return false;
}
std::stringstream sstream(data);

View File

@ -434,36 +434,60 @@ bool DeleteDir(const Path &path) {
}
// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string &srcFilename, const std::string &destFilename)
bool Rename(const Path &srcFilename, const Path &destFilename)
{
INFO_LOG(COMMON, "Rename: %s --> %s",
srcFilename.c_str(), destFilename.c_str());
if (srcFilename.Type() != destFilename.Type()) {
// Impossible.
return false;
}
switch (srcFilename.Type()) {
case PathType::NATIVE:
break; // OK
default:
return false;
}
INFO_LOG(COMMON, "Rename: %s --> %s", srcFilename.c_str(), destFilename.c_str());
#if defined(_WIN32) && defined(UNICODE)
std::wstring srcw = ConvertUTF8ToWString(srcFilename);
std::wstring destw = ConvertUTF8ToWString(destFilename);
std::wstring srcw = srcFilename.ToWString();
std::wstring destw = destFilename.ToWString();
if (_wrename(srcw.c_str(), destw.c_str()) == 0)
return true;
#else
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
return true;
#endif
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
return false;
}
// copies file srcFilename to destFilename, returns true on success
bool Copy(const std::string &srcFilename, const std::string &destFilename)
bool Copy(const Path &srcFilename, const Path &destFilename)
{
INFO_LOG(COMMON, "Copy: %s --> %s",
srcFilename.c_str(), destFilename.c_str());
switch (srcFilename.Type()) {
case PathType::NATIVE:
break; // OK
default:
return false;
}
switch (destFilename.Type()) {
case PathType::NATIVE:
break; // OK
default:
return false;
}
INFO_LOG(COMMON, "Copy: %s --> %s", srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
if (CopyFile2(ConvertUTF8ToWString(srcFilename).c_str(), ConvertUTF8ToWString(destFilename).c_str(), nullptr))
if (CopyFile2(srcFilename.ToWString().c_str(), destFilename.ToWString().c_str(), nullptr))
return true;
return false;
#else
if (CopyFile(ConvertUTF8ToWString(srcFilename).c_str(), ConvertUTF8ToWString(destFilename).c_str(), FALSE))
if (CopyFile(srcFilename.ToWString().c_str(), destFilename.ToWString().c_str(), FALSE))
return true;
#endif
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
@ -472,23 +496,21 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
#else
// buffer size
#define BSIZE 1024
#define BSIZE 4096
char buffer[BSIZE];
// Open input file
FILE *input = fopen(srcFilename.c_str(), "rb");
if (!input)
{
FILE *input = OpenCFile(srcFilename, "rb");
if (!input) {
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
return false;
}
// open output file
FILE *output = fopen(destFilename.c_str(), "wb");
if (!output)
{
FILE *output = OpenCFile(destFilename, "wb");
if (!output) {
fclose(input);
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
@ -496,14 +518,11 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
}
// copy loop
while (!feof(input))
{
while (!feof(input)) {
// read input
int rnum = fread(buffer, sizeof(char), BSIZE, input);
if (rnum != BSIZE)
{
if (ferror(input) != 0)
{
if (rnum != BSIZE) {
if (ferror(input) != 0) {
ERROR_LOG(COMMON,
"Copy: failed reading from source, %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
@ -515,8 +534,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
// write output
int wnum = fwrite(buffer, sizeof(char), rnum, output);
if (wnum != rnum)
{
if (wnum != rnum) {
ERROR_LOG(COMMON,
"Copy: failed writing to output, %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
@ -525,13 +543,23 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
return false;
}
}
// close flushs
// close flushes
fclose(input);
fclose(output);
return true;
#endif
}
bool Move(const Path &srcFilename, const Path &destFilename) {
if (Rename(srcFilename, destFilename)) {
return true;
} else if (Copy(srcFilename, destFilename)) {
return Delete(srcFilename);
} else {
return false;
}
}
std::string GetDir(const std::string &path) {
if (path == "/")
return path;
@ -654,8 +682,7 @@ bool CreateEmptyFile(const Path &filename) {
}
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
bool DeleteDirRecursively(const Path &directory) {
//Removed check, it prevents the UWP from deleting store downloads
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
@ -663,16 +690,13 @@ bool DeleteDirRecursively(const std::string &directory)
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(ConvertUTF8ToWString(directory + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
HANDLE hFind = FindFirstFile((directory.ToWString() + L"\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
return false;
}
// windows loop
do
{
do {
const std::string virtualName = ConvertWStringToUTF8(ffd.cFileName);
#else
struct dirent *result = NULL;
@ -681,8 +705,7 @@ bool DeleteDirRecursively(const std::string &directory)
return false;
// non windows loop
while ((result = readdir(dirp)))
{
while ((result = readdir(dirp))) {
const std::string virtualName = result->d_name;
#endif
// check for "." and ".."
@ -691,11 +714,9 @@ bool DeleteDirRecursively(const std::string &directory)
(virtualName[2] == '\0')))
continue;
std::string newPath = directory + DIR_SEP + virtualName;
if (IsDirectory(Path(newPath)))
{
if (!DeleteDirRecursively(newPath))
{
Path newPath = directory / virtualName;
if (IsDirectory(Path(newPath))) {
if (!DeleteDirRecursively(newPath)) {
#ifndef _WIN32
closedir(dirp);
#else
@ -704,10 +725,8 @@ bool DeleteDirRecursively(const std::string &directory)
return false;
}
}
else
{
if (!File::Delete(Path(newPath)))
{
else {
if (!File::Delete(Path(newPath))) {
#ifndef _WIN32
closedir(dirp);
#else
@ -959,6 +978,8 @@ bool ReadFileToString(bool text_file, const Path &filename, std::string &str) {
return success;
}
// This is an odd one, mainly used for asset reading, so doesn't really
// need to support Path.
uint8_t *ReadLocalFile(const char *filename, size_t * size) {
FILE *file = File::OpenCFile(Path(filename), "rb");
if (!file) {

View File

@ -44,7 +44,6 @@ FILE *OpenCFile(const Path &filename, const char *mode);
std::string ResolvePath(const std::string &path);
// Returns true if file filename exists
bool Exists(const std::string &path);
bool Exists(const Path &path);
// Returns true if file filename exists in directory path.
@ -89,11 +88,18 @@ bool DeleteDir(const Path &filename);
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const Path &directory);
// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string &srcFilename, const std::string &destFilename);
// Renames file srcFilename to destFilename, returns true on success
// Will usually only work with in the same partition or other unit of storage,
// so you might have to fall back to copy/delete.
bool Rename(const Path &srcFilename, const Path &destFilename);
// copies file srcFilename to destFilename, returns true on success
bool Copy(const std::string &srcFilename, const std::string &destFilename);
bool Copy(const Path &srcFilename, const Path &destFilename);
// Tries to rename srcFilename to destFilename, if that fails,
// it tries to copy and delete the src if succeeded. If that fails too,
// returns false, otherwise returns true.
bool Move(const Path &srcFilename, const Path &destFilename);
// creates an empty file filename, returns true on success
bool CreateEmptyFile(const Path &filename);

View File

@ -4,7 +4,9 @@
#include "Common/Data/Encoding/Utf8.h"
Path::Path(const std::string &str) {
if (startsWith(str, "http://") || startsWith(str, "https://")) {
if (str.empty()) {
type_ = PathType::UNDEFINED;
} else if (startsWith(str, "http://") || startsWith(str, "https://")) {
type_ = PathType::HTTP;
} else {
type_ = PathType::NATIVE;
@ -51,6 +53,15 @@ Path Path::WithExtraExtension(const std::string &ext) const {
return Path(path_ + "." + ext);
}
Path Path::WithReplacedExtension(const std::string &oldExtension, const std::string &newExtension) const {
if (endsWithNoCase(path_, "." + oldExtension)) {
std::string newPath = path_.substr(path_.size() - oldExtension.size() - 1);
return Path(newPath + "." + newExtension);
} else {
return Path(*this);
}
}
std::string Path::GetFileExtension() const {
size_t pos = path_.rfind(".");
if (pos == std::string::npos) {

View File

@ -39,6 +39,10 @@ public:
type_ = PathType::UNDEFINED;
path_.clear();
}
size_t size() const {
return path_.size();
}
// WARNING: Unsafe usage.
const char *c_str() const {
return path_.c_str();
@ -54,6 +58,7 @@ public:
// File extension manipulation.
Path WithExtraExtension(const std::string &ext) const;
Path WithReplacedExtension(const std::string &oldExtension, const std::string &newExtension) const;
// Removes the last component.
Path Directory() const;

View File

@ -1212,7 +1212,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
});
iRunCount++;
if (!File::Exists(currentDirectory))
if (!File::Exists(Path(currentDirectory)))
currentDirectory = "";
Section *log = iniFile.GetOrCreateSection(logSectionName);
@ -1249,7 +1249,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
for (auto it = pinnedPaths.begin(), end = pinnedPaths.end(); it != end; ++it) {
// Unpin paths that are deleted automatically.
const std::string &path = it->second;
if (startsWith(path, "http://") || startsWith(path, "https://") || File::Exists(path)) {
if (startsWith(path, "http://") || startsWith(path, "https://") || File::Exists(Path(path))) {
vPinnedPaths.push_back(File::ResolvePath(path));
}
}

View File

@ -70,7 +70,7 @@
static bool FixFilenameCase(const std::string &path, std::string &filename)
{
// Are we lucky?
if (File::Exists(path + filename))
if (File::Exists(Path(path + filename)))
return true;
size_t filenameSize = filename.size(); // size in bytes, not characters
@ -512,7 +512,7 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname) {
#if HOST_IS_CASE_SENSITIVE
// Maybe we're lucky?
if (File::DeleteDirRecursively(fullName.ToString()))
if (File::DeleteDirRecursively(fullName))
return (bool)ReplayApplyDisk(ReplayAction::RMDIR, true, CoreTiming::GetGlobalTimeUs());
// Nope, fix case and try again. Should we try again?

View File

@ -87,12 +87,13 @@ static std::vector<PluginInfo> FindPlugins(const std::string &gameID, const std:
std::vector<PluginInfo> found;
for (auto subdir : pluginDirs) {
if (!subdir.isDirectory || !File::Exists(subdir.fullName + "/plugin.ini"))
Path subdirFullName(subdir.fullName);
if (!subdir.isDirectory || !File::Exists(subdirFullName / "plugin.ini"))
continue;
IniFile ini;
if (!ini.Load(subdir.fullName + "/plugin.ini")) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/plugin.ini", subdir.fullName.c_str());
if (!ini.Load(subdirFullName / "plugin.ini")) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/plugin.ini", subdirFullName.c_str());
continue;
}
@ -117,8 +118,8 @@ static std::vector<PluginInfo> FindPlugins(const std::string &gameID, const std:
std::set<std::string> langMatches;
for (const std::string &subini : matches) {
if (!ini.Load(subdir.fullName + "/" + subini)) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/%s", subdir.fullName.c_str(), subini.c_str());
if (!ini.Load(subdirFullName / subini)) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/%s", subdirFullName.c_str(), subini.c_str());
continue;
}
@ -132,8 +133,8 @@ static std::vector<PluginInfo> FindPlugins(const std::string &gameID, const std:
}
for (const std::string &subini : langMatches) {
if (!ini.Load(subdir.fullName + "/" + subini)) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/%s", subdir.fullName.c_str(), subini.c_str());
if (!ini.Load(subdirFullName / subini)) {
ERROR_LOG(SYSTEM, "Failed to load plugin ini: %s/%s", subdirFullName.c_str(), subini.c_str());
continue;
}

View File

@ -19,6 +19,7 @@
#include <cstdio>
#include "Common/File/FileUtil.h"
#include "Common/File/Path.h"
#include "Common/StringUtils.h"
#include "Core/FileLoaders/CachingFileLoader.h"
#include "Core/FileLoaders/DiskCachingFileLoader.h"
@ -101,20 +102,20 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) {
// First, check if it's a directory with an EBOOT.PBP in it.
if (fileLoader->IsDirectory()) {
std::string filename = fileLoader->GetPath();
Path filename = Path(fileLoader->GetPath());
if (filename.size() > 4) {
// Check for existence of EBOOT.PBP, as required for "Directory games".
if (File::Exists((filename + "/EBOOT.PBP").c_str())) {
if (File::Exists(filename / "EBOOT.PBP")) {
return IdentifiedFileType::PSP_PBP_DIRECTORY;
}
// check if it's a disc directory
if (File::Exists((filename + "/PSP_GAME").c_str())) {
if (File::Exists(filename / "PSP_GAME")) {
return IdentifiedFileType::PSP_DISC_DIRECTORY;
}
// Not that, okay, let's guess it's a savedata directory if it has a param.sfo...
if (File::Exists((filename + "/PARAM.SFO").c_str())) {
if (File::Exists(filename / "PARAM.SFO")) {
return IdentifiedFileType::PSP_SAVEDATA_DIRECTORY;
}
}

View File

@ -449,15 +449,14 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
Path oldNamePrefix = savestateDir / StringFromFormat("%s_%d", homebrewName.c_str(), i);
Path oldIDPrefix = savestateDir / StringFromFormat("%s_1.00_%d", madeUpID.c_str(), i);
// TODO(scoped): ...
if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix.ToString() + ".ppst"))
File::Rename(oldIDPrefix.ToString() + ".ppst", newPrefix.ToString() + ".ppst");
else if (File::Exists(oldNamePrefix.ToString() + ".ppst"))
File::Rename(oldNamePrefix.ToString() + ".ppst", newPrefix.ToString() + ".ppst");
if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix.ToString() + ".jpg"))
File::Rename(oldIDPrefix.ToString() + ".jpg", newPrefix.ToString() + ".jpg");
else if (File::Exists(oldNamePrefix.ToString() + ".jpg"))
File::Rename(oldNamePrefix.ToString() + ".jpg", newPrefix.ToString() + ".jpg");
if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix.WithExtraExtension("ppst")))
File::Rename(oldIDPrefix.WithExtraExtension("ppst"), newPrefix.WithExtraExtension("ppst"));
else if (File::Exists(oldNamePrefix.WithExtraExtension("ppst")))
File::Rename(oldNamePrefix.WithExtraExtension("ppst"), newPrefix.WithExtraExtension("ppst"));
if (oldIDPrefix != newPrefix && File::Exists(oldIDPrefix.WithExtraExtension("jpg")))
File::Rename(oldIDPrefix.WithExtraExtension("jpg"), newPrefix.WithExtraExtension("jpg"));
else if (File::Exists(oldNamePrefix.WithExtraExtension("jpg")))
File::Rename(oldNamePrefix.WithExtraExtension("jpg"), newPrefix.WithExtraExtension("jpg"));
}
PSPLoaders_Shutdown();

View File

@ -458,16 +458,16 @@ namespace SaveState
static void RenameIfExists(const Path &from, const Path &to) {
if (File::Exists(from)) {
File::Rename(from.ToString(), to.ToString());
File::Rename(from, to);
}
}
static void SwapIfExists(const Path &from, const Path &to) {
std::string temp = from.ToString() + ".tmp";
Path temp = from.WithExtraExtension("tmp");
if (File::Exists(from)) {
File::Rename(from.ToString(), temp);
File::Rename(to.ToString(), from.ToString());
File::Rename(temp, to.ToString());
File::Rename(from, temp);
File::Rename(to, from);
File::Rename(temp, to);
}
}
@ -486,7 +486,7 @@ namespace SaveState
} else {
DeleteIfExists(fn);
}
File::Rename(fn.WithExtraExtension("tmp").ToString(), fn.ToString());
File::Rename(fn.WithExtraExtension("tmp"), fn);
}
if (callback) {
callback(status, message, data);

View File

@ -57,10 +57,12 @@ void TextureReplacer::NotifyConfigChanged() {
if (enabled_) {
basePath_ = Path(GetSysDirectory(DIRECTORY_TEXTURES)) / gameID_;
Path newTextureDir = basePath_ / NEW_TEXTURE_DIR;
// If we're saving, auto-create the directory.
if (g_Config.bSaveNewTextures && !File::Exists((basePath_ / NEW_TEXTURE_DIR).ToString())) {
File::CreateFullPath(basePath_ / NEW_TEXTURE_DIR);
File::CreateEmptyFile(basePath_ / NEW_TEXTURE_DIR / ".nomedia");
if (g_Config.bSaveNewTextures && !File::Exists(newTextureDir)) {
File::CreateFullPath(newTextureDir);
File::CreateEmptyFile(newTextureDir / ".nomedia");
}
enabled_ = File::Exists(basePath_) && File::IsDirectory(basePath_);

View File

@ -260,7 +260,7 @@ bool GameManager::InstallGame(const std::string &url, const std::string &fileNam
return false;
}
if (!File::Exists(fileName)) {
if (!File::Exists(Path(fileName))) {
ERROR_LOG(HLE, "Game file '%s' doesn't exist", fileName.c_str());
return false;
}
@ -634,9 +634,9 @@ bool GameManager::InstallGameOnThread(std::string url, std::string fileName, boo
}
bool GameManager::InstallRawISO(const std::string &file, const std::string &originalName, bool deleteAfter) {
std::string destPath = g_Config.currentDirectory + "/" + originalName;
Path destPath = Path(g_Config.currentDirectory) / originalName;
// TODO: To save disk space, we should probably attempt a move first.
if (File::Copy(file, destPath)) {
if (File::Copy(Path(file), destPath)) {
if (deleteAfter) {
File::Delete(Path(file));
}

View File

@ -63,7 +63,7 @@ void CwCheatScreen::LoadCheatInfo() {
// We won't parse this, just using it to detect changes to the file.
std::string str;
if (File::ReadFileToString(true, engine_->CheatFilename().c_str(), str)) {
if (File::ReadFileToString(true, engine_->CheatFilename(), str)) {
fileCheckHash_ = XXH3_64bits(str.c_str(), str.size());
}
fileCheckCounter_ = 0;
@ -120,7 +120,7 @@ void CwCheatScreen::update() {
if (fileCheckCounter_++ >= FILE_CHECK_FRAME_INTERVAL && engine_) {
// Check if the file has changed. If it has, we'll reload.
std::string str;
if (File::ReadFileToString(true, engine_->CheatFilename().c_str(), str)) {
if (File::ReadFileToString(true, engine_->CheatFilename(), str)) {
uint64_t newHash = XXH3_64bits(str.c_str(), str.size());
if (newHash != fileCheckHash_) {
// This will update the hash.
@ -176,7 +176,7 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
#if PPSSPP_PLATFORM(UWP)
LaunchBrowser(engine_->CheatFilename().c_str());
#else
File::OpenFileInEditor(engine_->CheatFilename().ToString());
File::OpenFileInEditor(engine_->CheatFilename());
#endif
}
return UI::EVENT_DONE;

View File

@ -404,9 +404,9 @@ public:
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
if (File::Exists(screenshot_png))
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_png, info_->icon.data);
else if (File::Exists(screenshot_jpg))
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_jpg, info_->icon.data);
else
// Read standard icon
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
@ -451,9 +451,9 @@ handleELF:
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
if (File::Exists(screenshot_png)) {
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_png, info_->icon.data);
} else if (File::Exists(screenshot_jpg)) {
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_jpg, info_->icon.data);
} else {
// Read standard icon
VERBOSE_LOG(LOADER, "Loading unknown.png because there was an ELF");
@ -492,9 +492,9 @@ handleELF:
std::lock_guard<std::mutex> guard(info_->lock);
// Let's use the screenshot as an icon, too.
std::string screenshotPath = ReplaceAll(gamePath_.ToString(), ".ppst", ".jpg");
Path screenshotPath = gamePath_.WithReplacedExtension("ppst", "jpg");
if (File::Exists(screenshotPath)) {
if (File::ReadFileToString(false, screenshotPath.c_str(), info_->icon.data)) {
if (File::ReadFileToString(false, Path(screenshotPath), info_->icon.data)) {
info_->icon.dataLoaded = true;
} else {
ERROR_LOG(G3D, "Error loading screenshot data: '%s'", screenshotPath.c_str());
@ -579,9 +579,9 @@ handleELF:
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
if (File::Exists(screenshot_png))
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_png, info_->icon.data);
else if (File::Exists(screenshot_jpg))
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
File::ReadFileToString(false, screenshot_jpg, info_->icon.data);
else {
DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);

View File

@ -421,7 +421,7 @@ void SetBackgroundPopupScreen::update() {
if (pic) {
const Path bgPng = GetSysDirectory(DIRECTORY_SYSTEM) / "background.png";
File::WriteStringToFile(false, pic->data, bgPng.c_str());
File::WriteStringToFile(false, pic->data, bgPng);
}
NativeMessageReceived("bgImage_updated", "");

View File

@ -1120,7 +1120,7 @@ UI::EventReturn GameSettingsScreen::OnChangeMemStickDir(UI::EventParams &e) {
pendingMemstickFolder_ = newPath;
std::string promptMessage = sy->T("ChangingMemstickPath", "Save games, save states, and other data will not be copied to this folder.\n\nChange the Memory Stick folder?");
if (!File::Exists(newPath)) {
if (!File::Exists(Path(newPath))) {
promptMessage = sy->T("ChangingMemstickPathNotExists", "That folder doesn't exist yet.\n\nSave games, save states, and other data will not be copied to this folder.\n\nCreate a new Memory Stick folder?");
}
// Add the path for clarity and proper confirmation.
@ -1299,16 +1299,16 @@ void GameSettingsScreen::CallbackMemstickFolder(bool yes) {
std::string testWriteFile = pendingMemstickFolder_ + "/.write_verify_file";
// Already, create away.
if (!File::Exists(pendingMemstickFolder_)) {
if (!File::Exists(Path(pendingMemstickFolder_))) {
File::CreateFullPath(Path(pendingMemstickFolder_));
}
if (!File::WriteDataToFile(true, "1", 1, testWriteFile.c_str())) {
if (!File::WriteDataToFile(true, "1", 1, Path(testWriteFile))) {
settingInfo_->Show(sy->T("ChangingMemstickPathInvalid", "That path couldn't be used to save Memory Stick files."), nullptr);
return;
}
File::Delete(Path(testWriteFile));
File::WriteDataToFile(true, pendingMemstickFolder_.c_str(), (unsigned int)pendingMemstickFolder_.size(), memstickDirFile.c_str());
File::WriteDataToFile(true, pendingMemstickFolder_.c_str(), (unsigned int)pendingMemstickFolder_.size(), Path(memstickDirFile));
// Save so the settings, at least, are transferred.
g_Config.memStickDirectory = Path(pendingMemstickFolder_);
g_Config.Save("MemstickPathChanged");
@ -1729,7 +1729,7 @@ UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e)
std::string gameID = g_paramSFO.GetDiscID();
Path generatedFilename;
if (TextureReplacer::GenerateIni(gameID, &generatedFilename)) {
File::OpenFileInEditor(generatedFilename.ToString());
File::OpenFileInEditor(generatedFilename);
}
return UI::EVENT_DONE;
}
@ -1772,8 +1772,8 @@ UI::EventReturn DeveloperToolsScreen::OnCopyStatesToRoot(UI::EventParams &e) {
GetFilesInDir(savestate_dir, &files, nullptr, 0);
for (const File::FileInfo &file : files) {
std::string src = file.fullName;
std::string dst = root_dir.ToString() + file.name;
Path src = Path(file.fullName);
Path dst = root_dir / file.name;
INFO_LOG(SYSTEM, "Copying file '%s' to '%s'", src.c_str(), dst.c_str());
File::Copy(src, dst);
}

View File

@ -613,11 +613,11 @@ void GameBrowser::Draw(UIContext &dc) {
}
}
static bool IsValidPBP(const std::string &path, bool allowHomebrew) {
static bool IsValidPBP(const Path &path, bool allowHomebrew) {
if (!File::Exists(path))
return false;
std::unique_ptr<FileLoader> loader(ConstructFileLoader(path));
std::unique_ptr<FileLoader> loader(ConstructFileLoader(path.ToString()));
PBPReader pbp(loader.get());
std::vector<u8> sfoData;
if (!pbp.GetSubFile(PBP_PARAM_SFO, &sfoData))
@ -719,11 +719,11 @@ void GameBrowser::Refresh() {
bool isGame = !fileInfo[i].isDirectory;
bool isSaveData = false;
// Check if eboot directory
if (!isGame && path_.GetPath().size() >= 4 && IsValidPBP(path_.GetPath() + fileInfo[i].name + "/EBOOT.PBP", true))
if (!isGame && path_.GetPath().size() >= 4 && IsValidPBP(Path(path_.GetPath()) / fileInfo[i].name / "EBOOT.PBP", true))
isGame = true;
else if (!isGame && File::Exists(path_.GetPath() + fileInfo[i].name + "/PSP_GAME/SYSDIR"))
else if (!isGame && File::Exists(Path(path_.GetPath() + fileInfo[i].name + "/PSP_GAME/SYSDIR")))
isGame = true;
else if (!isGame && File::Exists(path_.GetPath() + fileInfo[i].name + "/PARAM.SFO"))
else if (!isGame && File::Exists(Path(path_.GetPath() + fileInfo[i].name + "/PARAM.SFO")))
isSaveData = true;
if (!isGame && !isSaveData) {

View File

@ -386,7 +386,7 @@ static void CheckFailedGPUBackends() {
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
std::string data;
if (File::ReadFileToString(true, cache.c_str(), data))
if (File::ReadFileToString(true, cache, data))
g_Config.sFailedGPUBackends = data;
}
@ -414,7 +414,7 @@ static void CheckFailedGPUBackends() {
// Let's try to create, in case it doesn't exist.
if (!File::Exists(GetSysDirectory(DIRECTORY_APP_CACHE)))
File::CreateDir(GetSysDirectory(DIRECTORY_APP_CACHE));
File::WriteStringToFile(true, g_Config.sFailedGPUBackends, cache.c_str());
File::WriteStringToFile(true, g_Config.sFailedGPUBackends, cache);
} else {
// Just save immediately, since we have storage.
g_Config.Save("got storage permission");
@ -499,13 +499,15 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
g_Config.memStickDirectory = Path(external_dir);
g_Config.flash0Directory = Path(external_dir) / "flash0";
std::string memstickDirFile = g_Config.internalDataDirectory + "/memstick_dir.txt";
Path memstickDirFile = Path(g_Config.internalDataDirectory) / "memstick_dir.txt";
if (File::Exists(memstickDirFile)) {
std::string memstickDir;
File::ReadFileToString(true, memstickDirFile.c_str(), memstickDir);
File::ReadFileToString(true, memstickDirFile, memstickDir);
Path memstickPath(memstickDir);
if (!memstickPath.empty() && File::Exists(memstickPath)) {
g_Config.memStickDirectory = memstickPath;
} else {
ERROR_LOG(SYSTEM, "Couldn't read directory '%s' specified by memstick_dir.txt.", memstickDir.c_str());
}
}
#elif PPSSPP_PLATFORM(IOS)
@ -1165,7 +1167,7 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) {
if (msg == "bgImage_updated") {
if (!value.empty()) {
Path dest = GetSysDirectory(DIRECTORY_SYSTEM) / (endsWithNoCase(value, ".jpg") ? "background.jpg" : "background.png");
File::Copy(value, dest.ToString());
File::Copy(Path(value), dest);
}
UIBackgroundShutdown();
// It will init again automatically. We can't init outside a frame on Vulkan.

View File

@ -145,7 +145,7 @@ bool RunTests() {
PSP_EndHostFrame();
std::string expect_results;
if (!File::ReadFileToString(true, expectedFile.c_str(), expect_results)) {
if (!File::ReadFileToString(true, expectedFile, expect_results)) {
ERROR_LOG(SYSTEM, "Error opening expectedFile %s", expectedFile.c_str());
break;
}

View File

@ -278,7 +278,7 @@ bool CompareOutput(const std::string &bootFilename, const std::string &output, b
printf("%s", output.c_str());
printf("============== expected output:\n");
std::string fullExpected;
if (File::ReadFileToString(true, expect_filename.c_str(), fullExpected))
if (File::ReadFileToString(true, Path(expect_filename), fullExpected))
printf("%s", fullExpected.c_str());
printf("===============================\n");
}

View File

@ -427,10 +427,10 @@ int main(int argc, const char* argv[])
#ifdef __ANDROID__
// For some reason the debugger installs it with this name?
if (File::Exists("/data/app/org.ppsspp.ppsspp-2.apk")) {
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp-2.apk"))) {
VFSRegister("", new ZipAssetReader("/data/app/org.ppsspp.ppsspp-2.apk", "assets/"));
}
if (File::Exists("/data/app/org.ppsspp.ppsspp.apk")) {
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp.apk"))) {
VFSRegister("", new ZipAssetReader("/data/app/org.ppsspp.ppsspp.apk", "assets/"));
}
#endif

View File

@ -594,7 +594,7 @@ static bool TestPath() {
EXPECT_EQ_STR(path3.WithExtraExtension("txt").ToString(), std::string("/asdf/jkl/foo/bar.txt"));
EXPECT_EQ_STR(Path("foo.bar/hello").GetFileExtension(), std::string(""));
EXPECT_EQ_STR(Path("foo.bar/hello.txt").WithReplacedExtension("txt", "html").ToString(), std::string("foo.bar/hello.html"));
return true;
}