struct mCore* mCoreFind(const char* path) { struct VDir* archive = VDirOpenArchive(path); struct mCore* core = NULL; if (archive) { struct VDirEntry* dirent = archive->listNext(archive); while (dirent) { struct VFile* vf = archive->openFile(archive, dirent->name(dirent), O_RDONLY); if (!vf) { dirent = archive->listNext(archive); continue; } core = mCoreFindVF(vf); vf->close(vf); if (core) { break; } dirent = archive->listNext(archive); } archive->close(archive); } else { struct VFile* vf = VFileOpen(path, O_RDONLY); if (!vf) { return NULL; } core = mCoreFindVF(vf); vf->close(vf); } if (core) { return core; } return NULL; }
struct VDir* _vdwOpenDir(struct VDir* vd, const char* path) { struct VDirW32* vdw = (struct VDirW32*) vd; if (!path) { return 0; } const char* dir = vdw->path; char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + 2)); sprintf(combined, "%s\\%s", dir, path); struct VDir* vd2 = VDirOpen(combined); if (!vd2) { vd2 = VDirOpenArchive(combined); } free(combined); return vd2; }
struct VDir* _vdsceOpenDir(struct VDir* vd, const char* path) { struct VDirSce* vdsce = (struct VDirSce*) vd; if (!path) { return 0; } const char* dir = vdsce->path; char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + strlen(PATH_SEP) + 1)); sprintf(combined, "%s%s%s", dir, PATH_SEP, path); struct VDir* vd2 = VDirOpen(combined); if (!vd2) { vd2 = VDirOpenArchive(combined); } free(combined); return vd2; }
void mLibraryLoadDirectory(struct mLibrary* library, const char* base) { struct VDir* dir = VDirOpenArchive(base); if (!dir) { dir = VDirOpen(base); } sqlite3_exec(library->db, "BEGIN TRANSACTION;", NULL, NULL, NULL); if (!dir) { sqlite3_clear_bindings(library->deleteRoot); sqlite3_reset(library->deleteRoot); sqlite3_bind_text(library->deleteRoot, 1, base, -1, SQLITE_TRANSIENT); sqlite3_step(library->deleteRoot); sqlite3_exec(library->db, "COMMIT;", NULL, NULL, NULL); return; } struct mLibraryEntry entry; memset(&entry, 0, sizeof(entry)); entry.base = base; struct mLibraryListing entries; mLibraryListingInit(&entries, 0); mLibraryGetEntries(library, &entries, 0, 0, &entry); size_t i; for (i = 0; i < mLibraryListingSize(&entries); ++i) { struct mLibraryEntry* current = mLibraryListingGetPointer(&entries, i); struct VFile* vf = dir->openFile(dir, current->filename, O_RDONLY); _mLibraryDeleteEntry(library, current); if (!vf) { continue; } _mLibraryAddEntry(library, current->filename, base, vf); } mLibraryListingDeinit(&entries); dir->rewind(dir); struct VDirEntry* dirent = dir->listNext(dir); while (dirent) { struct VFile* vf = dir->openFile(dir, dirent->name(dirent), O_RDONLY); if (!vf) { dirent = dir->listNext(dir); continue; } _mLibraryAddEntry(library, dirent->name(dirent), base, vf); dirent = dir->listNext(dir); } dir->close(dir); sqlite3_exec(library->db, "COMMIT;", NULL, NULL, NULL); }
struct mCore* mCoreFind(const char* path) { struct VDir* archive = VDirOpenArchive(path); struct mCore* (*open)(void) = NULL; if (archive) { struct VDirEntry* dirent = archive->listNext(archive); while (dirent) { struct VFile* vf = archive->openFile(archive, dirent->name(dirent), O_RDONLY); if (!vf) { dirent = archive->listNext(archive); continue; } struct mCoreFilter* filter; for (filter = &_filters[0]; filter->filter; ++filter) { if (filter->filter(vf)) { break; } } vf->close(vf); if (filter->open) { open = filter->open; break; } dirent = archive->listNext(archive); } archive->close(archive); } else { struct VFile* vf = VFileOpen(path, O_RDONLY); if (!vf) { return NULL; } struct mCoreFilter* filter; for (filter = &_filters[0]; filter->filter; ++filter) { if (filter->filter(vf)) { break; } } vf->close(vf); if (filter->open) { open = filter->open; } } if (open) { return open(); } return NULL; }
struct VFile* mLibraryOpenVFile(struct mLibrary* library, const struct mLibraryEntry* entry) { struct mLibraryListing entries; mLibraryListingInit(&entries, 0); if (!mLibraryGetEntries(library, &entries, 0, 0, entry)) { mLibraryListingDeinit(&entries); return NULL; } struct VFile* vf = NULL; size_t i; for (i = 0; i < mLibraryListingSize(&entries); ++i) { struct mLibraryEntry* e = mLibraryListingGetPointer(&entries, i); struct VDir* dir = VDirOpenArchive(e->base); bool isArchive = true; if (!dir) { dir = VDirOpen(e->base); isArchive = false; } if (!dir) { continue; } vf = dir->openFile(dir, e->filename, O_RDONLY); if (vf && isArchive) { struct VFile* vfclone = VFileMemChunk(NULL, vf->size(vf)); uint8_t buffer[2048]; ssize_t read; while ((read = vf->read(vf, buffer, sizeof(buffer))) > 0) { vfclone->write(vfclone, buffer, read); } vf->close(vf); vf = vfclone; } dir->close(dir); if (vf) { break; } } return vf; }
struct VFile* mDirectorySetOpenPath(struct mDirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)) { dirs->archive = VDirOpenArchive(path); struct VFile* file; if (dirs->archive) { file = VDirFindFirst(dirs->archive, filter); if (!file) { dirs->archive->close(dirs->archive); dirs->archive = 0; } } else { file = VFileOpen(path, O_RDONLY); if (file && !filter(file)) { file->close(file); file = 0; } } if (file) { char dirname[PATH_MAX]; separatePath(path, dirname, dirs->baseName, 0); mDirectorySetAttachBase(dirs, VDirOpen(dirname)); } return file; }