void collectFiles(Disk &disk,Directory *directory) { if (directory == NULL) return; directory->Rewind(); char name[B_FILE_NAME_LENGTH]; block_run run; while (directory->GetNextEntry(name,&run) >= B_OK) { if (!strcmp(name,".") || !strcmp(name,"..")) continue; gHashtable.Put(run); if (++gCount % 50 == 0) printf(" %7Ld%s1A\n",gCount,gEscape); Inode *inode = Inode::Factory(&disk,run); if (inode != NULL) { if (inode->IsDirectory()) collectFiles(disk,static_cast<Directory *>(inode)); delete inode; } else printf(" Directory \"%s\" (%ld, %d) points to corrupt inode \"%s\" (%ld, %d)\n", directory->Name(),directory->BlockRun().allocation_group,directory->BlockRun().start, name,run.allocation_group,run.start); } }
void Builder::collectFiles() { mFileSet.clear(); if (boost::filesystem::is_directory(mParams.inputPath)) { collectFiles(mParams.inputPath); } else if (boost::filesystem::is_regular_file(mParams.inputPath)) { std::ifstream infile; infile.open(mParams.inputPath.c_str()); if (infile.is_open()) { String path; while (std::getline(infile, path)) { boost::trim(path); if (StringUtil::startsWith(path, "#", true)) continue; if (!path.empty()) { if (boost::filesystem::is_directory(path)) collectFiles(path); else { StringStream ss; ss << path << " isn't a directory"; mErrors.push_back(ss.str()); } } } } else { StringStream ss; ss << "Can't open file: " << mParams.inputPath; mErrors.push_back(ss.str()); } } }
QFileInfoList Zerberus::sfzFiles() { QFileInfoList l; QStringList pl = Ms::preferences.mySoundfontsPath.split(";"); pl.prepend(QFileInfo(QString("%1%2").arg(Ms::mscoreGlobalShare).arg("sound")).absoluteFilePath()); foreach (const QString& s, pl) { QString ss(s); if (!s.isEmpty() && s[0] == '~') ss = QDir::homePath() + s.mid(1); collectFiles(&l, ss); }
static void collectFiles(QFileInfoList* l, const QString& path) { // printf("collect files <%s>\n", qPrintable(path)); QDir dir(path); foreach (const QFileInfo& s, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot)) { if (path == s.absoluteFilePath()) return; if (s.isDir() && !s.isHidden()) collectFiles(l, s.absoluteFilePath()); else { if (s.suffix().toLower() == "sfz") l->append(s); } } }
QFileInfoList Zerberus::sfzFiles() { QFileInfoList l; QStringList pl = Ms::preferences.getString(PREF_APP_PATHS_MYSOUNDFONTS).split(";"); pl.prepend(QFileInfo(QString("%1%2").arg(Ms::mscoreGlobalShare).arg("sound")).absoluteFilePath()); // append extensions directory QStringList extensionsDir = Ms::Extension::getDirectoriesByType(Ms::Extension::sfzsDir); pl.append(extensionsDir); foreach (const QString& s, pl) { QString ss(s); if (!s.isEmpty() && s[0] == '~') ss = QDir::homePath() + s.mid(1); collectFiles(&l, ss); }
void collectFiles(Disk &disk) { Directory *root = (Directory *)Inode::Factory(&disk,disk.Root()); puts("Collecting files (this will take some time)..."); if (root == NULL || root->InitCheck() < B_OK) { fprintf(stderr," Could not open root directory!\n"); return; } collectFiles(disk,root); printf(" %7Ld files found.\n",gCount); delete root; }
void MasterTableCache::updateTab() { collectFiles(); if (needsUpdate()) { masterTab_ = table(); for (const auto & file : files_) { if (njh::files::normalize(file.first) == njh::files::normalize(tabOpts_.out_.outFilename_)) { continue; } table fileTab = table(file.first.string(), tabOpts_.outDelim_, tabOpts_.hasHeader_); if (masterTab_.content_.empty()) { masterTab_ = fileTab; } else { masterTab_.rbind(fileTab, false); } } } }
void WorkerThread::runRezip() { emit(beginRunRezip()); emit(stageEvent("Finding and saving modified game data")); emit(infoEvent("Identifying modified files (including previously modified files)")); QMap<QString, uint32_t> newChecksums; collectFiles(m_tempPath, &newChecksums); QStringList modified; // TODO: also determine removed files? QMapIterator<QString, uint32_t> i(newChecksums); while (i.hasNext()) { i.next(); if(!m_checksums.contains(i.key()) || m_checksums[i.key()] != i.value()) { modified << i.key(); } } if(modified.empty()) { emit(infoEvent("No modified files found")); return; } emit(infoEvent("Rezipping modified files")); QString gameFileBase = QFileInfo(m_gameFileName).baseName(); QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix; CZipArchive zip; try { zip.Open(diffFileName.toUtf8(), CZipArchive::zipCreate); // TODO: review that path finding stuff some time. QDir tempDir(m_tempPath); tempDir.makeAbsolute(); foreach(QString externalPath, modified) { QDir externalDir(externalPath); externalDir.makeAbsolute(); QString internalPath = tempDir.relativeFilePath(externalDir.absolutePath()); zip.AddNewFile((LPCTSTR)externalPath.toUtf8(), (LPCTSTR)internalPath.toUtf8(), CZipCompressor::levelBest); } zip.Close(); } catch(CZipException ex) {
int checkIndex(Disk &disk,char *attribute,block_run &run,bool collect) { Directory *index = (Directory *)Inode::Factory(&disk,run); status_t status; if (index == NULL || (status = index->InitCheck()) < B_OK) { fprintf(stderr," Could not get index directory for \"%s\": %s!\n",attribute,index ? strerror(status) : "not found/corrupted"); return -1; } printf("\nCheck \"%s\" index's on-disk structure...\n",attribute); //dump_inode(index->InodeBuffer()); BPlusTree *tree; if (index->GetTree(&tree) < B_OK || tree->Validate(true) < B_OK) { fprintf(stderr," B+Tree of index \"%s\" seems to be corrupt!\n",attribute); //return -1; } if (collect && (!gDoNotCheckIndex || !gDoNotCheckForFiles)) collectFiles(disk); if (!gDoNotCheckIndex) { printf("Check for non-existing files in index \"%s\"...\n",attribute); checkIndexForNonExistingFiles(disk,*tree); } if (!gDoNotCheckForFiles) { printf("Check for files not in index \"%s\" (this may take even more time)...\n",attribute); checkFiles(disk,*tree,attribute); } return 0; }
int main(int argc,char *argv[]) { char *p,*branch; char command[PM_MAX_PATH]; char drive[PM_MAX_DRIVE]; char dir[PM_MAX_PATH]; char name[PM_MAX_PATH]; char ext[PM_MAX_PATH]; ibool checkout = false; if (argc >= 2 && stricmp(argv[1],"-c") == 0) { checkout = true; argc--; argv++; } if (argc != 2 && argc != 3) { printf("Usage: p4_cvs [-c] <cvs command> <cvs branch>\n"); return 0; } if (argc == 3) branch = argv[2]; else branch = NULL; if ((p = getenv("TEMP")) == NULL) { if ((p = getenv("TMP")) == NULL) PM_fatalError("Unable to find temporary directory!"); } PM_splitpath(p,drive,dir,name,ext); PM_backslash(dir); strcat(dir,name); PM_splitpath(tmpnam(NULL),NULL,NULL,name,ext); PM_makepath(tempPath,drive,dir,name,ext); PM_splitpath(tmpnam(NULL),NULL,NULL,name,ext); PM_makepath(tempPath2,drive,dir,name,ext); PM_splitpath(logName,NULL,NULL,name,ext); PM_makepath(logPath,drive,dir,name,ext); #ifndef __UNIX__ strlwr(tempPath); strlwr(tempPath2); strlwr(logPath); #endif remove(logPath); printf("Opening CVS files in Perforce ... "); fflush(stdout); collectFiles("*",true,false); sprintf(command,"p4p -x %s open >>& %s",tempPath,logPath); system(command); printf("Done\n"); fflush(stdout); if (checkout) { printf("Removing Perforce files ... "); fflush(stdout); sprintf(command,"k_rm -rf *",tempPath,logPath); system(command); printf("Done\n"); fflush(stdout); } printf("Syncing to latest CVS files ... "); fflush(stdout); if (checkout) { if (branch) sprintf(command,"%s checkout -r %s >>& %s",argv[1],branch,logPath); else sprintf(command,"%s checkout . >>& %s",argv[1],logPath); } else { if (branch) sprintf(command,"%s update -r %s >>& %s",argv[1],branch,logPath); else sprintf(command,"%s update . >>& %s",argv[1],logPath); } system(command); printf("Done\n"); fflush(stdout); printf("Adding new files to Perforce ... "); fflush(stdout); collectFiles("*",true,false); sprintf(command,"p4p -x %s add >>& %s",tempPath,logPath); system(command); printf("Done\n"); fflush(stdout); printf("Reverting CVS special files ... "); fflush(stdout); collectFiles(".cvsignore",true,true); sprintf(command,"p4p -x %s revert >>& %s",tempPath,logPath); system(command); printf("Done\n"); fflush(stdout); printf("Reverting unchanged files ... "); fflush(stdout); sprintf(command,"p4p diff -sr | p4p -x - revert >>& %s",logPath); system(command); printf("Done\n"); fflush(stdout); remove(tempPath); printf("Deleting removed files ... "); fflush(stdout); sprintf(command,"p4p opened >>& %s",tempPath2); system(command); findRemovedFiles(tempPath2); sprintf(command,"p4p -x %s revert >>& %s",tempPath,logPath); system(command); sprintf(command,"p4p -x %s delete >>& %s",tempPath,logPath); system(command); printf("Done\n"); fflush(stdout); // Clean up and exit remove(tempPath); remove(tempPath2); return 0; }
bool Builder::run(const BuilderParams ¶ms) { mParams = params; collectFiles(); // initialize sc-memory sc_memory_params p; sc_memory_params_clear(&p); p.clear = mParams.clearOutput ? SC_TRUE : SC_FALSE; p.config_file = mParams.configFile.empty() ? 0 : mParams.configFile.c_str(); p.repo_path = mParams.outputPath.c_str(); p.ext_path = mParams.extensionsPath.size() > 0 ? mParams.extensionsPath.c_str() : 0; sc_memory_initialize(&p); mContext = sc_memory_context_new(sc_access_lvl_make_min); std::cout << "Build knowledge base from sources... " << std::endl; // process founded files uint32 done = 0, last_progress = -1; tFileSet::iterator it, itEnd = mFileSet.end(); for (it = mFileSet.begin(); it != itEnd; ++it) { uint32 progress = (uint32)(((float)++done / (float)mFileSet.size()) * 100); if (mParams.showFileNames) { std::cout << "[ " << progress << "% ] " << *it << std::endl; } else { if (last_progress != progress) { if (progress % 10 == 0) { std::cout << "[" << progress << "%]"; std::cout.flush(); } else { std::cout << "."; std::cout.flush(); } last_progress = progress; } } try { processFile(*it); } catch(const Exception &e) { StringStream ss; ss << e.getDescription() << " in " << e.getFileName() << " at line " << e.getLineNumber(); mErrors.push_back(ss.str()); } } std::cout << std::endl << "done" << std::endl; // print errors std::cout << std::endl << "-------" << std::endl << "Errors:" << std::endl; int idx = 1; tStringList::iterator itErr, itErrEnd = mErrors.end(); for (itErr = mErrors.begin(); itErr != itErrEnd; ++itErr) std::cout << "[" << idx++ << "]\t" << *itErr << std::endl; // print statistics sc_stat stat; sc_memory_stat(mContext, &stat); unsigned int all_count = stat.arc_count + stat.node_count + stat.link_count; std::cout << std::endl << "Statistics" << std::endl; std::cout << "Nodes: " << stat.node_count << "(" << ((float)stat.node_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Arcs: " << stat.arc_count << "(" << ((float)stat.arc_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Links: " << stat.link_count << "(" << ((float)stat.link_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Total: " << all_count << std::endl; sc_memory_context_free(mContext); sc_memory_shutdown(SC_TRUE); return true; }
int main(int argc,char **argv) { puts("Copyright (c) 2001-2008 pinc Software."); char *toolName = argv[0]; if (argc < 2 || !strcmp(argv[1],"--help")) { printUsage(toolName); return -1; } while (*++argv) { char *arg = *argv; if (*arg == '-') { while (*++arg && isalpha(*arg)) { switch (*arg) { case 'i': gDoNotCheckIndex = true; break; case 'f': gDoNotCheckForFiles = true; break; case 'a': gCheckAll = true; break; } } } else break; } char *attribute = argv[0]; if (!gCheckAll && attribute == NULL) { printUsage(toolName); return -1; } dev_t device = dev_for_path("."); if (device < B_OK) { fprintf(stderr,"Could not find device for current location: %s\n",strerror(device)); return -1; } fs_info info; if (fs_stat_dev(device,&info) < B_OK) { fprintf(stderr,"Could not get stats for device: %s\n",strerror(errno)); return -1; } Disk disk(info.device_name); status_t status; if ((status = disk.InitCheck()) < B_OK) { fprintf(stderr,"Could not open device or file \"%s\": %s\n",info.device_name,strerror(status)); return -1; } if (disk.ValidateSuperBlock() < B_OK) { fprintf(stderr,"The disk's superblock is corrupt!\n"); return -1; } Directory *indices = (Directory *)Inode::Factory(&disk,disk.Indices()); if (indices == NULL || (status = indices->InitCheck()) < B_OK) { fprintf(stderr," Could not get indices directory: %s!\n",indices ? strerror(status) : "not found/corrupted"); delete indices; return -1; } BPlusTree *tree; if (indices->GetTree(&tree) < B_OK || tree->Validate() < B_OK) { fprintf(stderr," Indices B+Tree seems to be corrupt!\n"); delete indices; return -1; } block_run run; if (gCheckAll) { putchar('\n'); collectFiles(disk); char name[B_FILE_NAME_LENGTH]; while (indices->GetNextEntry(name,&run) >= B_OK) checkIndex(disk,name,run,false); } else if (indices->FindEntry(attribute,&run) == B_OK) checkIndex(disk,attribute,run,true); else fprintf(stderr," Could not find index directory for \"%s\"!\n",attribute); delete indices; gHashtable.MakeEmpty(HASH_EMPTY_NONE,HASH_EMPTY_FREE); return 0; }
void WorkerThread::runUnzip() { emit(beginRunUnzip()); emit(stageEvent("Extracting and merging game data")); emit(infoEvent("Unzipping original game files")); CZipArchive zip; try { zip.Open(m_gameFileName.toStdString().c_str(), CZipArchive::zipOpenReadOnly); ZIP_SIZE_TYPE totalSize = 0; for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) { totalSize += zip.GetFileInfo(i)->m_uUncomprSize; // uncompressed size QString name = QString::fromUtf8(zip.GetFileInfo(i)->GetFileName()); if(!validName(name)) { emit(errorEvent("Game pack contains illegal file names (e.g. " + name + ")")); emit(infoEvent("A near future release of WHDRun will fix this problem, sorry for the inconvenience")); m_die = true; return; } } emit(unzipTotalSize(totalSize)); ZIP_SIZE_TYPE progress = 0; for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) { progress += zip.GetFileInfo(i)->m_uUncomprSize; zip.ExtractFile(i, m_tempPath.toUtf8()); emit(unzipProgress(progress)); } zip.Close(); } catch(CZipException ex) { zip.Close(CZipArchive::afAfterException); emit(errorEvent(QString("Error while unzipping: %1").arg((LPCTSTR)ex.GetErrorDescription()))); m_die = true; // no need to rezip return; } emit(infoEvent("Collecting checksums of unmodified files")); emit(beginCollect()); m_checksums.clear(); collectFiles(m_tempPath, &m_checksums); // TODO: progress for this? (should always be quick) QString gameFileBase = QFileInfo(m_gameFileName).baseName(); QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix; if(QFileInfo(diffFileName).exists()) { emit(infoEvent("Merging original game files with previously modified files")); CZipArchive zip; try { zip.Open(diffFileName.toUtf8(), CZipArchive::zipOpenReadOnly); //TODO: progress infoEvent for this? (should always be quick) for (ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) { zip.ExtractFile(i, m_tempPath.toUtf8()); } zip.Close(); } catch(CZipException ex) { zip.Close(CZipArchive::afAfterException); emit(errorEvent(QString("Error while unzipping changes: %1").arg((LPCTSTR)ex.GetErrorDescription()))); m_die = true; // no need to rezip return; } } emit(endRunUnzip()); }