Io: Provide directory existence with listing.

Sometimes, you need to tell the difference between an empty directory and
one that doesn't exist at all.  We can do this in a single call.
This commit is contained in:
Unknown W. Brackets
2022-10-09 14:42:31 -07:00
parent 7b8350f8a8
commit 4942692558
11 changed files with 66 additions and 29 deletions
+8 -2
View File
@@ -631,11 +631,14 @@ PSPFileInfo ISOFileSystem::GetFileInfo(std::string filename) {
return x;
}
std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) {
std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(const std::string &path, bool *exists) {
std::vector<PSPFileInfo> myVector;
TreeEntry *entry = GetFromPath(path);
if (!entry)
if (!entry) {
if (exists)
*exists = false;
return myVector;
}
const std::string dot(".");
const std::string dotdot("..");
@@ -651,6 +654,7 @@ std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) {
x.name = e->name;
// Strangely, it seems to be executable even for files.
x.access = 0555;
x.exists = true;
x.size = e->size;
x.type = e->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
x.isOnSectorSystem = true;
@@ -659,6 +663,8 @@ std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) {
x.numSectors = (u32)((e->size + sectorSize - 1) / sectorSize);
myVector.push_back(x);
}
if (exists)
*exists = true;
return myVector;
}