bool addFileToParallelProcessor(ParallelFileProcessor *p, const char *inFile, const struct stat *inFileInfo, struct folder_info *folderInfo, const bool ownInfo) { if( p && inFile && inFileInfo && folderInfo ){ if( ownInfo ){ p->items().push_back(FileEntry( inFile, inFileInfo, new FolderInfo(*folderInfo), ownInfo )); } else{ p->items().push_back(FileEntry( inFile, inFileInfo, folderInfo, ownInfo )); } return true; } else{ // fprintf( stderr, "Error: Processor=%p file=%p, finfo=%p dinfo=%p, own=%d\n", p, inFile, inFileInfo, folderInfo, ownInfo ); return false; } }
/** See if an object is in the cache. */ FieldCacheAuto* FieldCacheImpl::lookup (IndexReader* reader, const TCHAR* field, int32_t type) { FieldCacheAuto* ret = NULL; FileEntry* entry = _CLNEW FileEntry (field, type); { // CPIXASYNC SCOPED_LOCK_MUTEX(THIS_LOCK) SCOPED_LOCK_CRUCIAL_MUTEX(FieldCacheImpl_THIS_LOCK) fieldcacheCacheReaderType* readerCache = cache.get(reader); if (readerCache != NULL) ret = readerCache->get (entry); _CLDELETE(entry); } return ret; }
// Done void ModelProperties::done() { if (NULL != m_pListOfMaterial) { materialListGroup->layout()->removeWidget(m_pListOfMaterial); delete m_pListOfMaterial; m_pListOfMaterial= NULL; listOfMaterialsButton->blockSignals(true); listOfMaterialsButton->setChecked(false); listOfMaterialsButton->blockSignals(false); // Free fileEntry m_FileEntry= FileEntry(); } }
void listVerboseFiles(Aurora::ERFFile &erf, Aurora::GameID game) { const Aurora::Archive::ResourceList &resources = erf.getResources(); const size_t fileCount = resources.size(); std::printf("Number of files: %u\n\n", (uint)fileCount); std::vector<FileEntry> fileEntries; fileEntries.reserve(fileCount); size_t nameLength = 10; for (Aurora::Archive::ResourceList::const_iterator r = resources.begin(); r != resources.end(); ++r) { const Aurora::FileType type = TypeMan.aliasFileType(r->type, game); Common::UString name = r->name; if (name.empty()) findHashedName(r->hash, name); name.replaceAll('\\', '/'); name = TypeMan.addFileType(name, type); nameLength = MAX<size_t>(nameLength, name.size() + 1); fileEntries.push_back(FileEntry(name, erf.getResourceSize(r->index))); } if ((nameLength % 2) == 1) nameLength++; std::printf("%sFileName%s| Size\n", Common::UString(' ', (nameLength - 8) / 2).c_str(), Common::UString(' ', (nameLength - 8) / 2).c_str()); std::printf("%s|===========\n", Common::UString('=', nameLength).c_str()); for (std::vector<FileEntry>::const_iterator f = fileEntries.begin(); f != fileEntries.end(); ++f) std::printf("%-*s| %10d\n", (int)nameLength, f->file.c_str(), f->size); }
FileEntry::FileEntry( const char *name, const struct stat *finfo, FolderInfo &dinfo ) { FileEntry( name, finfo, new FolderInfo(dinfo), true ); }
int main(int argc, char** argv) try { po::options_description desc("Required options"); desc.add_options() ("help,h", "produce help message") ("force,f", "overwrite existing files") ("mpq", po::value<std::string>(), "the mpq to create") ("files", po::value<std::vector<std::string> >(), "input files"); po::positional_options_description p; p.add("mpq", 1); p.add("files", -1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (!vm.count("files") || !vm.count("mpq") || vm.count("help")) { std::cout << "usage: <mpq> [<files> ...]" << std::endl << std::endl << desc << std::endl; return 1; } std::vector<std::string> files(vm["files"].as< std::vector<std::string> >()); std::vector<FileEntry> toAdd; fs::path mpqPath(vm["mpq"].as<std::string>()); if(fs::exists(mpqPath)) { if(vm.count("force")) fs::remove(mpqPath); else throw std::runtime_error("mpq does already exist"); } for(std::vector<std::string>::iterator path = files.begin(); path != files.end(); ++path) { if(fs::is_regular_file(*path)) toAdd.push_back(FileEntry(*path, *path)); if(!fs::is_directory(*path)) //no symlinks etc continue; for(fs::recursive_directory_iterator file(*path), end; file != end; ++file) if(fs::is_regular_file(file->path())) toAdd.push_back(FileEntry(file->path(), makeRelative(*path, file->path()))); } for(std::vector<FileEntry>::iterator it = toAdd.begin(); it != toAdd.end(); ++it) std::cout << it->realPath << " >> " << it->mpqPath << std::endl; HANDLE mpq; if(!SFileCreateArchive(mpqPath.string().c_str(), MPQ_CREATE_ARCHIVE_V2, toAdd.size(), &mpq)) throw std::runtime_error("couldn't create mpq"); SFileSetLocale(0); size_t counter(0); for(std::vector<FileEntry>::iterator it = toAdd.begin(); it != toAdd.end(); ++it) { loadbar(++counter, toAdd.size()); if(!SFileAddFileEx(mpq, it->realPath.string().c_str(), it->mpqPath.string().c_str(), MPQ_FILE_COMPRESS, MPQ_COMPRESSION_BZIP2, MPQ_COMPRESSION_BZIP2)) std::cout << "couldn't add file " << it->realPath << std::endl; } std::cout << std::endl; SFileCompactArchive(mpq, NULL, false); SFileFlushArchive(mpq); SFileCloseArchive(mpq); return 0; } catch (const std::exception& e) { std::cerr << "error: " << e.what() << "\n"; }