Skip to content

Commit

Permalink
Use Path for fullName in dirlisting. Bugfixes.
Browse files Browse the repository at this point in the history
Buildfixes

UWP: Buildfix.

headless: Buildfix.

Common: Buildfix.

iOS: Buildfixes.

libretro: Buildfix.

Qt: Buildfix.
  • Loading branch information
hrydgard committed May 13, 2021
1 parent ae06499 commit a40b1de
Show file tree
Hide file tree
Showing 26 changed files with 108 additions and 127 deletions.
4 changes: 2 additions & 2 deletions Common/CPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static std::vector<int> ParseCPUList(const std::string &filename) {
std::string data;
std::vector<int> results;

if (File::ReadFileToString(true, filename.c_str(), data)) {
if (File::ReadFileToString(true, Path(filename), data)) {
std::vector<std::string> ranges;
SplitString(data, ',', ranges);
for (auto range : ranges) {
Expand Down Expand Up @@ -372,7 +372,7 @@ void CPUInfo::Detect() {
// This seems to be the count per core. Hopefully all cores are the same, but we counted each above.
logical_cpu_count /= std::max(num_cores, 1);
#elif PPSSPP_PLATFORM(LINUX)
if (File::Exists("/sys/devices/system/cpu/present")) {
if (File::Exists(Path("/sys/devices/system/cpu/present"))) {
// This may not count unplugged cores, but at least it's a best guess.
// Also, this assumes the CPU cores are heterogeneous (e.g. all cores could be active simultaneously.)
num_cores = 0;
Expand Down
12 changes: 2 additions & 10 deletions Common/File/DirListing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool GetFileInfo(const Path &path, FileInfo * fileInfo) {
}

// TODO: Expand relative paths?
fileInfo->fullName = path.ToString();
fileInfo->fullName = path;

#ifdef _WIN32
auto FiletimeToStatTime = [](FILETIME ft) {
Expand Down Expand Up @@ -191,15 +191,7 @@ size_t GetFilesInDir(const Path &directory, std::vector<FileInfo> * files, const
FileInfo info;
info.name = virtualName;

// It's OK not to use Path /-concat here.
std::string dir = directory.ToString();

// Only append a slash if there isn't one on the end.
size_t lastSlash = dir.find_last_of("/");
if (lastSlash != (dir.length() - 1))
dir.append("/");

info.fullName = dir + virtualName;
info.fullName = directory / virtualName;
info.isDirectory = IsDirectory(Path(info.fullName));
info.exists = true;
info.size = 0;
Expand Down
2 changes: 1 addition & 1 deletion Common/File/DirListing.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace File {

struct FileInfo {
std::string name;
std::string fullName; // TODO: Make into Path
Path fullName;
bool exists = false;
bool isDirectory = false;
bool isWritable = false;
Expand Down
2 changes: 1 addition & 1 deletion Common/File/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Path Path::WithExtraExtension(const std::string &ext) const {

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);
std::string newPath = path_.substr(0, path_.size() - oldExtension.size() - 1);
return Path(newPath + "." + newExtension);
} else {
return Path(*this);
Expand Down
6 changes: 3 additions & 3 deletions Common/File/PathBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<File::

File::FileInfo info;
info.name = item;
info.fullName = baseURL.Relative(item).ToString();
info.fullName = Path(baseURL.Relative(item).ToString());
info.isDirectory = endsWith(item, "/");
info.exists = true;
info.size = 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ std::vector<File::FileInfo> ApplyFilter(std::vector<File::FileInfo> files, const
auto pred = [&](const File::FileInfo &info) {
if (info.isDirectory || !filter)
return false;
std::string ext = File::GetFileExtension(info.fullName);
std::string ext = info.fullName.GetFileExtension();
return filters.find(ext) == filters.end();
};
files.erase(std::remove_if(files.begin(), files.end(), pred), files.end());
Expand Down Expand Up @@ -255,7 +255,7 @@ bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *
if (*drive == "A:/" || *drive == "B:/")
continue;
File::FileInfo fake;
fake.fullName = *drive;
fake.fullName = Path(*drive);
fake.name = *drive;
fake.isDirectory = true;
fake.exists = true;
Expand Down
17 changes: 5 additions & 12 deletions Common/File/VFS/AssetReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,24 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<File::Fil
for (auto diter = directories.begin(); diter != directories.end(); ++diter) {
File::FileInfo info;
info.name = *diter;
info.fullName = std::string(path);
if (info.fullName[info.fullName.size() - 1] == '/')
info.fullName = info.fullName.substr(0, info.fullName.size() - 1);

// Remove the "inzip" part of the fullname.
info.fullName = info.fullName.substr(strlen(in_zip_path_));
info.fullName += "/" + *diter;
info.fullName = Path(std::string(path).substr(strlen(in_zip_path_))) / *diter;
info.exists = true;
info.isWritable = false;
info.isDirectory = true;
listing->push_back(info);
}

for (auto fiter = files.begin(); fiter != files.end(); ++fiter) {
std::string fpath = path;
File::FileInfo info;
info.name = *fiter;
info.fullName = std::string(path);
if (info.fullName[info.fullName.size() - 1] == '/')
info.fullName = info.fullName.substr(0, info.fullName.size() - 1);
info.fullName = info.fullName.substr(strlen(in_zip_path_));
info.fullName += "/" + *fiter;
info.fullName = Path(std::string(path).substr(strlen(in_zip_path_))) / *fiter;
info.exists = true;
info.isWritable = false;
info.isDirectory = false;
std::string ext = File::GetFileExtension(info.fullName);
std::string ext = File::GetFileExtension(info.fullName.ToString());
if (filter) {
if (filters.find(ext) == filters.end())
continue;
Expand All @@ -162,7 +155,7 @@ bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) {
return false;
}

info->fullName = path;
info->fullName = Path(path);
info->exists = true; // TODO
info->isWritable = false;
info->isDirectory = false; // TODO
Expand Down
2 changes: 1 addition & 1 deletion Common/MemArenaPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void MemArena::GrabLowMemSpace(size_t size) {
// Some platforms (like Raspberry Pi) end up flushing to disk.
// To avoid this, we try to use /dev/shm (tmpfs) if it exists.
fd = -1;
if (File::Exists(tmpfs_location)) {
if (File::Exists(Path(tmpfs_location))) {
fd = open(tmpfs_ram_temp_file.c_str(), O_RDWR | O_CREAT, mode);
if (fd >= 0) {
// Great, this definitely shouldn't flush to disk.
Expand Down
2 changes: 1 addition & 1 deletion Core/FileLoaders/DiskCachingFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ void DiskCachingFileLoaderCache::GarbageCollectCacheFiles(u64 goalBytes) {
}

#ifdef _WIN32
const std::wstring w32path = ConvertUTF8ToWString(file.fullName);
const std::wstring w32path = file.fullName.ToWString();
bool success = DeleteFileW(w32path.c_str()) != 0;
#else
bool success = unlink(file.fullName.c_str()) == 0;
Expand Down
21 changes: 11 additions & 10 deletions GPU/Common/PostShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ void LoadPostShaderInfo(const std::vector<Path> &directories) {
for (size_t f = 0; f < fileInfo.size(); f++) {
IniFile ini;
bool success = false;
std::string name = fileInfo[f].fullName;
std::string path = directories[d].ToString();
Path name = fileInfo[f].fullName;
Path path = directories[d];
// Hack around Android VFS path bug. really need to redesign this.
if (name.substr(0, 7) == "assets/")
name = name.substr(7);
if (path.substr(0, 7) == "assets/")
path = path.substr(7);
if (name.ToString().substr(0, 7) == "assets/")
name = Path(name.ToString().substr(7));
if (path.ToString().substr(0, 7) == "assets/")
path = Path(path.ToString().substr(7));

if (ini.LoadFromVFS(name) || ini.Load(fileInfo[f].fullName)) {
if (ini.LoadFromVFS(name.ToString()) || ini.Load(fileInfo[f].fullName)) {
success = true;
// vsh load. meh.
}

if (!success)
continue;

Expand All @@ -118,9 +119,9 @@ void LoadPostShaderInfo(const std::vector<Path> &directories) {
section.Get("Parent", &info.parent, "");
section.Get("Visible", &info.visible, true);
section.Get("Fragment", &temp, "");
info.fragmentShaderFile = path + "/" + temp;
info.fragmentShaderFile = path / temp;
section.Get("Vertex", &temp, "");
info.vertexShaderFile = path + "/" + temp;
info.vertexShaderFile = path / temp;
section.Get("OutputResolution", &info.outputResolution, false);
section.Get("Upscaling", &info.isUpscalingFilter, false);
section.Get("SSAA", &info.SSAAFilterLevel, 0);
Expand Down Expand Up @@ -165,7 +166,7 @@ void LoadPostShaderInfo(const std::vector<Path> &directories) {
section.Get("Name", &info.name, section.name().c_str());
section.Get("Compute", &temp, "");
section.Get("MaxScale", &info.maxScale, 255);
info.computeShaderFile = path + "/" + temp;
info.computeShaderFile = path / temp;

appendTextureShader(info);
}
Expand Down
10 changes: 5 additions & 5 deletions GPU/Common/PostShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include "Common/Data/Format/IniFile.h"

struct ShaderInfo {
std::string iniFile; // which ini file was this definition in? So we can write settings back later
Path iniFile; // which ini file was this definition in? So we can write settings back later
std::string section; // ini file section. This is saved.
std::string name; // Fancy display name.
std::string parent; // Parent shader ini section name.

std::string fragmentShaderFile;
std::string vertexShaderFile;
Path fragmentShaderFile;
Path vertexShaderFile;

// Show this shader in lists (i.e. not just for chaining.)
bool visible;
Expand Down Expand Up @@ -65,11 +65,11 @@ struct ShaderInfo {
};

struct TextureShaderInfo {
std::string iniFile;
Path iniFile;
std::string section;
std::string name;

std::string computeShaderFile;
Path computeShaderFile;
int maxScale;

bool operator == (const std::string &other) {
Expand Down
6 changes: 4 additions & 2 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ void PresentationCommon::CalculatePostShaderUniforms(int bufferWidth, int buffer
uniforms->setting[3] = g_Config.mPostShaderSetting[shaderInfo->section + "SettingValue4"];
}

static std::string ReadShaderSrc(const std::string &filename) {
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)
if (!data) {
return "";
}

std::string src(data, sz);
delete[] data;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void TextureCacheVulkan::NotifyConfigChanged() {
CompileScalingShader();
}

static std::string ReadShaderSrc(const std::string &filename) {
static std::string ReadShaderSrc(const Path &filename) {
size_t sz = 0;
char *data = (char *)VFSReadFile(filename.c_str(), &sz);
if (!data)
Expand Down
12 changes: 5 additions & 7 deletions Qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
#include <string>
#include "Qt/QtHost.h"

std::string QtHost::SymbolMapFilename(std::string currentFilename) {
size_t dot = currentFilename.rfind('.');
if (dot == std::string::npos)
currentFilename.append(".map");
Path QtHost::SymbolMapFilename(Path currentFilename) {
std::string ext = currentFilename.GetFileExtension();
if (ext == "")
return currentFilename.WithExtraExtension("map");
else
currentFilename.replace(dot, -1, ".map");

return currentFilename;
return currentFilename.WithReplacedExtension(ext, "map");
}
6 changes: 3 additions & 3 deletions Qt/QtHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class QtHost : public Host {
}
virtual bool AttemptLoadSymbolMap() override {
auto fn = SymbolMapFilename(PSP_CoreParameter().fileToStart);
return g_symbolMap->LoadSymbolMap(fn.c_str());
return g_symbolMap->LoadSymbolMap(fn);
}

virtual void NotifySymbolMapUpdated() override { g_symbolMap->SortSymbols(); }

void PrepareShutdown() {
auto fn = SymbolMapFilename(PSP_CoreParameter().fileToStart);
g_symbolMap->SaveSymbolMap(fn.c_str());
g_symbolMap->SaveSymbolMap(fn);
}
void SetWindowTitle(const char *message) override {
std::string title = std::string("PPSSPP ") + PPSSPP_GIT_VERSION;
Expand All @@ -95,6 +95,6 @@ class QtHost : public Host {
void NotifySwitchUMDUpdated() override {}

private:
std::string SymbolMapFilename(std::string currentFilename);
Path SymbolMapFilename(Path currentFilename);
MainWindow* mainWindow;
};
16 changes: 8 additions & 8 deletions Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ void SaveStateActionFinished(SaveState::Status status, const std::string &messag

void MainWindow::qlstateAct()
{
std::string gamePath = PSP_CoreParameter().fileToStart;
std::string gamePath = PSP_CoreParameter().fileToStart.ToString();
SaveState::LoadSlot(gamePath, 0, SaveStateActionFinished, this);
}

void MainWindow::qsstateAct()
{
std::string gamePath = PSP_CoreParameter().fileToStart;
std::string gamePath = PSP_CoreParameter().fileToStart.ToString();
SaveState::SaveSlot(gamePath, 0, SaveStateActionFinished, this);
}

Expand All @@ -177,7 +177,7 @@ void MainWindow::lstateAct()
if (dialog.exec())
{
QStringList fileNames = dialog.selectedFiles();
SaveState::Load(fileNames[0].toStdString(), -1, SaveStateActionFinished, this);
SaveState::Load(Path(fileNames[0].toStdString()), -1, SaveStateActionFinished, this);
}
}

Expand All @@ -192,7 +192,7 @@ void MainWindow::sstateAct()
if (dialog.exec())
{
QStringList fileNames = dialog.selectedFiles();
SaveState::Save(fileNames[0].toStdString(), -1, SaveStateActionFinished, this);
SaveState::Save(Path(fileNames[0].toStdString()), -1, SaveStateActionFinished, this);
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ void MainWindow::lmapAct()
if (fileNames.count() > 0)
{
QString fileName = QFileInfo(fileNames[0]).absoluteFilePath();
g_symbolMap->LoadSymbolMap(fileName.toStdString().c_str());
g_symbolMap->LoadSymbolMap(Path(fileName.toStdString()));
}
}

Expand All @@ -292,7 +292,7 @@ void MainWindow::smapAct()
if (dialog.exec())
{
fileNames = dialog.selectedFiles();
g_symbolMap->SaveSymbolMap(fileNames[0].toStdString().c_str());
g_symbolMap->SaveSymbolMap(Path(fileNames[0].toStdString()));
}
}

Expand All @@ -311,7 +311,7 @@ void MainWindow::lsymAct()
if (fileNames.count() > 0)
{
QString fileName = QFileInfo(fileNames[0]).absoluteFilePath();
g_symbolMap->LoadNocashSym(fileName.toStdString().c_str());
g_symbolMap->LoadNocashSym(Path(fileName.toStdString()));
}
}

Expand All @@ -327,7 +327,7 @@ void MainWindow::ssymAct()
if (dialog.exec())
{
fileNames = dialog.selectedFiles();
g_symbolMap->SaveNocashSym(fileNames[0].toStdString().c_str());
g_symbolMap->SaveNocashSym(Path(fileNames[0].toStdString()));
}
}

Expand Down
Loading

0 comments on commit a40b1de

Please sign in to comment.