mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Enable recursive search for virtual game drives
This commit is contained in:
parent
c2500b138a
commit
3dcfdd2b20
@ -1194,12 +1194,13 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter
|
|||||||
contents->entry->type = T_DOTDOT;
|
contents->entry->type = T_DOTDOT;
|
||||||
contents->entry->size = 0;
|
contents->entry->size = 0;
|
||||||
contents->n_entries = 1;
|
contents->n_entries = 1;
|
||||||
|
// 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 (DriveType(path) & DRV_VIRTUAL) {
|
||||||
if (!GetVirtualDirContents(contents, path, pattern))
|
if (!GetVirtualDirContents(contents, fpath, 256, pattern, recursive))
|
||||||
contents->n_entries = 0;
|
contents->n_entries = 0;
|
||||||
} else {
|
} else {
|
||||||
char fpath[256]; // 256 is the maximum length of a full path
|
|
||||||
strncpy(fpath, path, 256);
|
|
||||||
if (!GetDirContentsWorker(contents, fpath, 256, pattern, recursive))
|
if (!GetDirContentsWorker(contents, fpath, 256, pattern, recursive))
|
||||||
contents->n_entries = 0;
|
contents->n_entries = 0;
|
||||||
}
|
}
|
||||||
|
@ -107,30 +107,34 @@ bool GetVirtualDir(VirtualDir* vdir, const char* path) {
|
|||||||
return GetVirtualFile(&vfile, path) && OpenVirtualDir(vdir, &vfile);
|
return GetVirtualFile(&vfile, path) && OpenVirtualDir(vdir, &vfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetVirtualDirContents(DirStruct* contents, const char* path, const char* pattern) {
|
bool GetVirtualDirContents(DirStruct* contents, char* fpath, int fnsize, const char* pattern, bool recursive) {
|
||||||
u32 virtual_src = GetVirtualSource(path);
|
|
||||||
if (!virtual_src) return false; // not a virtual path
|
|
||||||
|
|
||||||
VirtualDir vdir;
|
VirtualDir vdir;
|
||||||
VirtualFile vfile;
|
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
|
return false; // get dir reader object
|
||||||
while ((contents->n_entries < MAX_DIR_ENTRIES) && (ReadVirtualDir(&vfile, &vdir))) {
|
while ((contents->n_entries < MAX_DIR_ENTRIES) && (ReadVirtualDir(&vfile, &vdir))) {
|
||||||
DirEntry* entry = &(contents->entry[contents->n_entries]);
|
DirEntry* entry = &(contents->entry[contents->n_entries]);
|
||||||
if (!(vfile.flags & VRT_GAME)) {
|
if (!(vfile.flags & VRT_GAME)) {
|
||||||
if (pattern && !MatchName(pattern, vfile.name)) continue;
|
strncpy(fname, vfile.name, (fnsize - 1) - (fname - fpath));
|
||||||
snprintf(entry->path, 256, "%s/%s", path, vfile.name);
|
|
||||||
} else {
|
} else {
|
||||||
char name[256];
|
char name[256];
|
||||||
if (!GetVGameFilename(name, &vfile, 256)) return false;
|
if (!GetVGameFilename(name, &vfile, 256)) return false;
|
||||||
if (pattern && !MatchName(pattern, name)) continue;
|
strncpy(fname, name, (fnsize - 1) - (fname - fpath));
|
||||||
snprintf(entry->path, 256, "%s/%s", path, name);
|
|
||||||
}
|
}
|
||||||
entry->name = entry->path + strnlen(path, 256) + 1;
|
if (!pattern || MatchName(pattern, fname)) {
|
||||||
entry->size = vfile.size;
|
strncpy(entry->path, fpath, 256);
|
||||||
entry->type = (vfile.flags & VFLAG_DIR) ? T_DIR : T_FILE;
|
entry->name = entry->path + (fname - fpath);
|
||||||
entry->marked = 0;
|
entry->size = vfile.size;
|
||||||
contents->n_entries++;
|
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
|
return true; // not much we can check here
|
||||||
|
@ -47,7 +47,7 @@ bool OpenVirtualDir(VirtualDir* vdir, VirtualFile* ventry);
|
|||||||
|
|
||||||
bool GetVirtualFile(VirtualFile* vfile, const char* path);
|
bool GetVirtualFile(VirtualFile* vfile, const char* path);
|
||||||
bool GetVirtualDir(VirtualDir* vdir, 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 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);
|
int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user