Get rid of FindVirtualFileBySize()

This commit is contained in:
d0k3 2016-11-28 21:21:42 +01:00
parent ddac828dcb
commit cdb9000e6a
3 changed files with 16 additions and 21 deletions

View File

@ -619,9 +619,17 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
f_sync(&ofile);
osize = f_size(&ofile);
if (!GetVirtualFile(&dvfile, dest)) {
if (!FindVirtualFileBySize(&dvfile, dest, osize)) {
VirtualDir vdir;
if (!GetVirtualDir(&vdir, destdir)) {
f_close(&ofile);
return false;
} else while (true) {
if (!ReadVirtualDir(&dvfile, &vdir)) {
f_close(&ofile);
return false;
}
if (dvfile.size == osize) // search by size should be a last resort solution
break; // file found
}
snprintf(dest, 255, "%s/%s", destdir, dvfile.name);
if (!ShowPrompt(true, "Entry not found: %s\nInject into %s instead?", deststr, dest)) {

View File

@ -105,25 +105,6 @@ bool GetVirtualDir(VirtualDir* vdir, const char* path) {
return GetVirtualFile(&vfile, path) && OpenVirtualDir(vdir, &vfile);
}
// hacky solution, actually ignores path
bool FindVirtualFileBySize(VirtualFile* vfile, const char* path, u32 size) {
// get virtual source
u32 virtual_src = 0;
virtual_src = GetVirtualSource(path);
if (!virtual_src) return false;
VirtualDir vdir; // read virtual root dir, match size
OpenVirtualRoot(&vdir, virtual_src); // get dir reader object
while (ReadVirtualDir(vfile, &vdir)) {
vfile->flags |= virtual_src; // add source flag
if (vfile->size == size) // search by size should be a last resort solution
return true; // file found
}
// failed if arriving here
return false;
}
bool GetVirtualDirContents(DirStruct* contents, const char* path, const char* pattern) {
u32 virtual_src = GetVirtualSource(path);
if (!virtual_src) return false; // not a virtual path

View File

@ -40,8 +40,14 @@ typedef struct {
u32 GetVirtualSource(const char* path);
bool CheckVirtualDrive(const char* path);
bool ReadVirtualDir(VirtualFile* vfile, VirtualDir* vdir);
bool OpenVirtualRoot(VirtualDir* vdir, u32 virtual_src);
bool OpenVirtualDir(VirtualDir* vdir, VirtualFile* ventry);
bool GetVirtualFile(VirtualFile* vfile, const char* path);
bool FindVirtualFileBySize(VirtualFile* vfile, const char* path, u32 size);
bool GetVirtualDir(VirtualDir* vdir, const char* path);
bool GetVirtualDirContents(DirStruct* contents, const char* path, const char* pattern);
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);