int FSZip::load(string backfile, string filename, FileBuffer *p, bool async) { Zip zip; if (zip.Open(backfile.substr(1))) return -1; if (!zip.check_file_exist(filename)) return -1; if (async) { p->m_aync_thread = thread(zip_async_load, backfile, filename, p); } else { shared_ptr<FileBuffer> pzip = zip.get_file_buff(filename); if (pzip == NULL) return -1; p->swap(*pzip); p->m_loaded = true; } return 0; }
bool FSZip::exist(string backfile, string filename) { Zip zip; if (zip.Open(backfile.substr(1))) return false; return zip.check_file_exist(filename); }
int zip_async_load(string zipfile, string fn, FileBuffer * buff) { std::lock_guard<mutex> lock(buff->m_async_mutex); Zip zip; if (zip.Open(zipfile.substr(1))) return -1; shared_ptr<FileBuffer> p = zip.get_file_buff(fn); if (p == NULL) return -1; buff->swap(*p); buff->m_loaded = true; return 0; }
int FSZip::for_each_ls(uuu_ls_file fn, string backfile, string filename, void *p) { Zip zip; if (zip.Open(backfile.substr(1))) return -1; for(auto it = zip.m_filemap.begin(); it!=zip.m_filemap.end(); ++it) { if(it->first.substr(0, filename.size()) == filename || filename.empty()) { string name = backfile; name += "/"; name += it->first; fn(name.c_str()+1, p); } } return 0; }