Common: Cleanup some Path constructions.

This commit is contained in:
Unknown W. Brackets 2021-05-14 22:48:04 -07:00
parent 2a9170a2ea
commit d376e67f87
13 changed files with 21 additions and 22 deletions

View file

@ -197,7 +197,7 @@ size_t GetFilesInDir(const Path &directory, std::vector<FileInfo> * files, const
info.size = 0;
info.isWritable = false; // TODO - implement some kind of check
if (!info.isDirectory) {
std::string ext = Path(info.fullName).GetFileExtension();
std::string ext = info.fullName.GetFileExtension();
if (!ext.empty()) {
ext = ext.substr(1); // Remove the dot.
if (filter && filters.find(ext) == filters.end()) {

View file

@ -258,7 +258,7 @@ bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *
fileInfo = ApplyFilter(pendingFiles_, filter);
return true;
} else {
File::GetFilesInDir(Path(path_), &fileInfo, filter);
File::GetFilesInDir(path_, &fileInfo, filter);
return true;
}
}

View file

@ -1593,7 +1593,7 @@ void Config::RestoreDefaults() {
createGameConfig(gameId_);
} else {
if (File::Exists(iniFilename_))
File::Delete(Path(iniFilename_));
File::Delete(iniFilename_);
recentIsos.clear();
currentDirectory = "";
}

View file

@ -86,8 +86,8 @@ static std::vector<PluginInfo> FindPlugins(const std::string &gameID, const std:
GetFilesInDir(GetSysDirectory(DIRECTORY_PLUGINS), &pluginDirs);
std::vector<PluginInfo> found;
for (auto subdir : pluginDirs) {
Path subdirFullName(subdir.fullName);
for (const auto &subdir : pluginDirs) {
const Path &subdirFullName = subdir.fullName;
if (!subdir.isDirectory || !File::Exists(subdirFullName / "plugin.ini"))
continue;

View file

@ -676,7 +676,7 @@ void InitSysDirectories() {
INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str());
}
Path testFile = Path(g_Config.memStickDirectory) / "_writable_test.$$$";
Path testFile = g_Config.memStickDirectory / "_writable_test.$$$";
// If any directory is read-only, fall back to the Documents directory.
// We're screwed anyway if we can't write to Documents, or can't detect it.

View file

@ -696,7 +696,7 @@ void ReplacedTexture::Load(int level, void *out, int rowPitch) {
png_image png = {};
png.version = PNG_IMAGE_VERSION;
FILE *fp = File::OpenCFile(Path(info.file), "rb");
FILE *fp = File::OpenCFile(info.file, "rb");
if (!png_image_begin_read_from_stdio(&png, fp)) {
ERROR_LOG(G3D, "Could not load texture replacement info: %s - %s", info.file.c_str(), png.message);
return;
@ -733,7 +733,7 @@ bool TextureReplacer::GenerateIni(const std::string &gameID, Path &generatedFile
if (gameID.empty())
return false;
Path texturesDirectory = Path(GetSysDirectory(DIRECTORY_TEXTURES)) / gameID;
Path texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) / gameID;
if (!File::Exists(texturesDirectory)) {
File::CreateFullPath(texturesDirectory);
}

View file

@ -580,7 +580,7 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
installInProgress_ = false;
installError_ = "";
if (deleteAfter) {
File::Delete(Path(zipfile));
File::Delete(zipfile);
}
InstallDone();
return true;

View file

@ -62,7 +62,7 @@ bool GameInfo::Delete() {
case IdentifiedFileType::PSP_ISO_NP:
{
// Just delete the one file (TODO: handle two-disk games as well somehow).
Path fileToRemove = Path(filePath_);
Path fileToRemove = filePath_;
File::Delete(fileToRemove);
g_Config.RemoveRecent(filePath_.ToString());
return true;
@ -134,7 +134,7 @@ std::vector<Path> GameInfo::GetSaveDataDirectories() {
}
for (size_t i = 0; i < dirs.size(); i++) {
if (startsWith(dirs[i].name, id)) {
directories.push_back(Path(dirs[i].fullName));
directories.push_back(dirs[i].fullName);
}
}
@ -155,7 +155,7 @@ u64 GameInfo::GetSaveDataSizeInBytes() {
// Note: GetFilesInDir does not fill in fileSize properly.
for (size_t i = 0; i < fileInfo.size(); i++) {
File::FileInfo finfo;
File::GetFileInfo(Path(fileInfo[i].fullName), &finfo);
File::GetFileInfo(fileInfo[i].fullName, &finfo);
if (!finfo.isDirectory)
filesSizeInDir += finfo.size;
}
@ -182,7 +182,7 @@ u64 GameInfo::GetInstallDataSizeInBytes() {
// Note: GetFilesInDir does not fill in fileSize properly.
for (size_t i = 0; i < fileInfo.size(); i++) {
File::FileInfo finfo;
File::GetFileInfo(Path(fileInfo[i].fullName), &finfo);
File::GetFileInfo(fileInfo[i].fullName, &finfo);
if (!finfo.isDirectory)
filesSizeInDir += finfo.size;
}
@ -235,7 +235,7 @@ bool GameInfo::DeleteAllSaveData() {
File::GetFilesInDir(saveDataDir[j], &fileInfo);
for (size_t i = 0; i < fileInfo.size(); i++) {
File::Delete(Path(fileInfo[i].fullName));
File::Delete(fileInfo[i].fullName);
}
File::DeleteDir(saveDataDir[j]);
@ -493,7 +493,7 @@ handleELF:
// Let's use the screenshot as an icon, too.
Path screenshotPath = gamePath_.WithReplacedExtension("ppst", "jpg");
if (File::Exists(screenshotPath)) {
if (File::ReadFileToString(false, Path(screenshotPath), info_->icon.data)) {
if (File::ReadFileToString(false, screenshotPath, info_->icon.data)) {
info_->icon.dataLoaded = true;
} else {
ERROR_LOG(G3D, "Error loading screenshot data: '%s'", screenshotPath.c_str());

View file

@ -1772,7 +1772,7 @@ UI::EventReturn DeveloperToolsScreen::OnCopyStatesToRoot(UI::EventParams &e) {
GetFilesInDir(savestate_dir, &files, nullptr, 0);
for (const File::FileInfo &file : files) {
Path src = Path(file.fullName);
Path src = 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

@ -429,7 +429,7 @@ static void ClearFailedGPUBackends() {
// In case they update drivers and have totally different problems much later, clear the failed list.
g_Config.sFailedGPUBackends.clear();
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
File::Delete(Path(GetSysDirectory(DIRECTORY_APP_CACHE)) / "FailedGraphicsBackends.txt");
File::Delete(GetSysDirectory(DIRECTORY_APP_CACHE) / "FailedGraphicsBackends.txt");
} else {
g_Config.Save("clearFailedGPUBackends");
}
@ -1004,7 +1004,7 @@ void NativeShutdownGraphics() {
void TakeScreenshot() {
g_TakeScreenshot = false;
Path path = Path(GetSysDirectory(DIRECTORY_SCREENSHOT));
Path path = GetSysDirectory(DIRECTORY_SCREENSHOT);
if (!File::Exists(path)) {
File::CreateDir(path);
}

View file

@ -159,7 +159,7 @@ void AsyncImageFileView::Draw(UIContext &dc) {
class ScreenshotViewScreen : public PopupScreen {
public:
ScreenshotViewScreen(Path filename, std::string title, int slot, std::shared_ptr<I18NCategory> i18n)
ScreenshotViewScreen(const Path &filename, std::string title, int slot, std::shared_ptr<I18NCategory> i18n)
: PopupScreen(title, i18n->T("Load State"), "Back"), filename_(filename), slot_(slot) {} // PopupScreen will translate Back on its own
int GetSlot() const {

View file

@ -114,7 +114,7 @@ public:
} else {
Path image_path = savePath_.WithReplacedExtension(".ppst", ".jpg");
if (File::Exists(image_path)) {
toprow->Add(new AsyncImageFileView(Path(image_path), IS_KEEP_ASPECT, new LinearLayoutParams(480, 272, Margins(10, 0))));
toprow->Add(new AsyncImageFileView(image_path, IS_KEEP_ASPECT, new LinearLayoutParams(480, 272, Margins(10, 0))));
} else {
toprow->Add(new TextView(sa->T("No screenshot"), new LinearLayoutParams(Margins(10, 5))))->SetTextColor(textStyle.fgColor);
}

View file

@ -96,8 +96,7 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptr<DX::DeviceResourc
char controlsConfigFilename[MAX_PATH] = { 0 };
std::wstring memstickFolderW = ApplicationData::Current->LocalFolder->Path->Data();
g_Config.memStickDirectory = Path(ReplaceAll(ConvertWStringToUTF8(memstickFolderW), "\\", "/"));
g_Config.memStickDirectory = Path(memstickFolderW);
// On Win32 it makes more sense to initialize the system directories here
// because the next place it was called was in the EmuThread, and it's too late by then.