Enable recursive search for virtual game drives

This commit is contained in:
d0k3 2016-12-01 02:13:13 +01:00
parent c2500b138a
commit 3dcfdd2b20
3 changed files with 23 additions and 18 deletions

View File

@ -1194,12 +1194,13 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter
contents->entry->type = T_DOTDOT;
contents->entry->size = 0;
contents->n_entries = 1;
if (DriveType(path) & DRV_VIRTUAL) {
if (!GetVirtualDirContents(contents, path, pattern))
contents->n_entries = 0;
} else {
// search the path
char fpath[256]; // 256 is the maximum length of a full path
strncpy(fpath, path, 256);
if (DriveType(path) & DRV_VIRTUAL) {
if (!GetVirtualDirContents(contents, fpath, 256, pattern, recursive))
contents->n_entries = 0;
} else {
if (!GetDirContentsWorker(contents, fpath, 256, pattern, recursive))
contents->n_entries = 0;
}

View File

@ -107,31 +107,35 @@ bool GetVirtualDir(VirtualDir* vdir, const char* path) {
return GetVirtualFile(&vfile, path) && OpenVirtualDir(vdir, &vfile);
}
bool GetVirtualDirContents(DirStruct* contents, const char* path, const char* pattern) {
u32 virtual_src = GetVirtualSource(path);
if (!virtual_src) return false; // not a virtual path
bool GetVirtualDirContents(DirStruct* contents, char* fpath, int fnsize, const char* pattern, bool recursive) {
VirtualDir vdir;
VirtualFile vfile;
if (!GetVirtualDir(&vdir, path))
char* fname = fpath + strnlen(fpath, fnsize - 1);
(fname++)[0] = '/';
if (!GetVirtualDir(&vdir, fpath))
return false; // get dir reader object
while ((contents->n_entries < MAX_DIR_ENTRIES) && (ReadVirtualDir(&vfile, &vdir))) {
DirEntry* entry = &(contents->entry[contents->n_entries]);
if (!(vfile.flags & VRT_GAME)) {
if (pattern && !MatchName(pattern, vfile.name)) continue;
snprintf(entry->path, 256, "%s/%s", path, vfile.name);
strncpy(fname, vfile.name, (fnsize - 1) - (fname - fpath));
} else {
char name[256];
if (!GetVGameFilename(name, &vfile, 256)) return false;
if (pattern && !MatchName(pattern, name)) continue;
snprintf(entry->path, 256, "%s/%s", path, name);
strncpy(fname, name, (fnsize - 1) - (fname - fpath));
}
entry->name = entry->path + strnlen(path, 256) + 1;
if (!pattern || MatchName(pattern, fname)) {
strncpy(entry->path, fpath, 256);
entry->name = entry->path + (fname - fpath);
entry->size = vfile.size;
entry->type = (vfile.flags & VFLAG_DIR) ? T_DIR : T_FILE;
entry->marked = 0;
contents->n_entries++;
}
if (recursive && (vfile.flags & VFLAG_DIR)) {
if (!GetVirtualDirContents(contents, fpath, fnsize, pattern, recursive))
break;
}
}
return true; // not much we can check here
}

View File

@ -47,7 +47,7 @@ bool OpenVirtualDir(VirtualDir* vdir, VirtualFile* ventry);
bool GetVirtualFile(VirtualFile* vfile, const char* path);
bool GetVirtualDir(VirtualDir* vdir, const char* path);
bool GetVirtualDirContents(DirStruct* contents, const char* path, const char* pattern);
bool GetVirtualDirContents(DirStruct* contents, char* fpath, int fnsize, const char* pattern, bool recursive);
int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, u32* bytes_read);
int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written);