CDirectory::~CDirectory() { CDirEntry *pEntry = m_pEntryList; while (pEntry) { CDirEntry *pTmp = pEntry; pEntry = pEntry->GetNext(); delete pTmp; } }
void CDirectory::AddEntry(struct dirent *de, CDirectory *pSubDir, const char *pHostName) { CDirEntry *pEntry = new CDirEntry; pEntry->Create(de, pSubDir, pHostName); pEntry->SetNext(m_pEntryList); m_pEntryList = pEntry; m_nbEntry++; }
void CListProcess::UpdateStatus(int nItem) { wxString sTime; bool bStartTime = false; bool bStopTime = false; long nMin; long nMax; long nCount = (long) m_pDirList->GetCount(); if(nItem >= 0) { nMin = (long) nItem; nMax = nMin; nMax++; if(nMax > nCount) { nMax = nCount; } } else { nMin = 0; nMax = nCount; } wxListItem info; CDirEntry *pDirEntry; for(long i = nMin; i < nMax; i++) { pDirEntry = m_pDirList->At((size_t)i); const wxString &sStatus(pDirEntry->GetStatusString()); sTime = pDirEntry->FormatStartTime(); SetItem(i,ITEM_START,sTime); if(!sTime.IsEmpty()) { bStartTime = true; } sTime = pDirEntry->FormatStopTime(); SetItem(i,ITEM_STOP,sTime); if(!sTime.IsEmpty()) { bStopTime = true; } SetItem(i,ITEM_STATUS,sStatus); SetItemTextColour(i,pDirEntry->GetStatusColour()); } if(bStartTime) { SetColumnWidth(ITEM_START,wxLIST_AUTOSIZE ); } if(bStopTime) { SetColumnWidth(ITEM_STOP,wxLIST_AUTOSIZE ); } SetColumnWidth(ITEM_STATUS,wxLIST_AUTOSIZE); // Refresh(); }
MemHandle CPWad::Read (XString item) { CDirEntry *entry = (CDirEntry *)directory[item]; if (entry) { file.Seek (entry->Offset()); MemHandle data = file.Read ((size_t)entry->Size()); if (data.Size() == (size_t) entry->Size()) return data; } return 0; }
void operator()( const CDirEntry & dirEntry ) { //const static size_t kInvalidFileNumber = numeric_limits<size_t>::max(); if( ! dirEntry.IsFile() ) { return; } CFile file(dirEntry); string name = file.GetName(); if (NStr::EndsWith(name, ".txt") || NStr::StartsWith(name, ".")) { return; } if (NStr::EndsWith(name, extKeep)) { return; } // extract info from the file name const string sFileName = file.GetName(); vector<string> vecFileNamePieces; NStr::Split( sFileName, ".", vecFileNamePieces ); BOOST_REQUIRE(vecFileNamePieces.size() == 3); string sTestName = vecFileNamePieces[0]; BOOST_REQUIRE(!sTestName.empty()); string sObjType = vecFileNamePieces[1]; BOOST_REQUIRE(!sObjType.empty()); string sFileType = vecFileNamePieces[2]; BOOST_REQUIRE(!sFileType.empty()); STestInfo & test_info_to_load = (*m_pTestNameToInfoMap)[vecFileNamePieces[0]]; // assign object type contained in test input if (sObjType == "entry" || sObjType == "annot") { test_info_to_load.mObjType = sObjType; } else { BOOST_FAIL("Unknown object type " << sObjType << "."); } // figure out what type of file we have and set appropriately if (sFileType == mExtInput) { BOOST_REQUIRE( test_info_to_load.mInFile.GetPath().empty() ); test_info_to_load.mInFile = file; } else if (sFileType == mExtOutput) { BOOST_REQUIRE( test_info_to_load.mOutFile.GetPath().empty() ); test_info_to_load.mOutFile = file; } else if (sFileType == mExtErrors) { BOOST_REQUIRE( test_info_to_load.mErrorFile.GetPath().empty() ); test_info_to_load.mErrorFile = file; } else { BOOST_FAIL("Unknown file type " << sFileName << "."); } }
MemHandle CPWad::Read (XString map, XString item) { CDirEntry *entry = (CDirEntry *)directory[map]; if (entry) { entry = (CDirEntry *)entry->subdir[item]; if (entry) { file.Seek (entry->Offset()); MemHandle data = file.Read ((size_t)entry->Size()); if (data.Size() == (size_t) entry->Size()) { cdebug.out << "Read From PWAD " << map << " " << item << " " << data.Size() << " bytes" << endl; return data; } } } cerr << "Read From PWAD " << map << " " << item << " FAILED!! " << endl; cdebug.out << "Read From PWAD " << map << " " << item << " FAILED!! " << endl; return 0; }
int CPWad::Write (MemHandle data, XString map, XString item) { CDirEntry *entry = (CDirEntry *)directory[map]; if (entry) { entry = (CDirEntry *)entry->subdir[item]; if (entry) { file.Seek (entry->Offset()); if (data.Size() == (size_t) entry->Size()) { int status = file.Write (data); cdebug.out << "Write to PWAD " << map << " " << item << " " << data.Size() << " bytes" << endl; return status; } } } cerr << "Write to PWAD " << map << " " << item << " FAILED!! " << endl; cdebug.out << "Write to PWAD " << map << " " << item << " FAILED!! " << endl; return -1; }
string g_FindDataFile(const CTempString& name, CDirEntry::EType type) { #ifdef NCBI_OS_MSWIN static const char* kDelim = ";"; #else static const char* kDelim = ":"; #endif if ( !s_IgnoredDataFiles->empty() && CDirEntry::MatchesMask(name, *s_IgnoredDataFiles) ) { return kEmptyStr; } list<string> dirs; if (CDirEntry::IsAbsolutePath(name)) { dirs.push_back(kEmptyStr); } else { TNCBIDataPath path; TNCBIDataDir dir; if ( !path.Get().empty() ) { NStr::Split(path.Get(), kDelim, dirs); } if ( !dir.Get().empty() ) { dirs.push_back(dir.Get()); } } CDirEntry candidate; EFollowLinks fl = (type == CDirEntry::eLink) ? eIgnoreLinks : eFollowLinks; ITERATE (list<string>, dir, dirs) { candidate.Reset(CDirEntry::MakePath(*dir, name)); if (candidate.Exists() && candidate.GetType(fl) == type) { return candidate.GetPath(); } }
bool CListProcess::TransferDataToWindow() { wxString sTime; bool bStartTime = false; bool bStopTime = false; bool bRtn = true; bool bIsShown = IsShownOnScreen(); if(bIsShown) { Show(false); } size_t n = m_pDirList->GetCount(); long nItem; CDirEntry *pDirEntry; ClearAll(); InsertColumn(ITEM_DIR,_T("Directory"),wxLIST_FORMAT_LEFT); InsertColumn(ITEM_START,_T("Start"),wxLIST_FORMAT_LEFT); InsertColumn(ITEM_STOP,_T("Stop"),wxLIST_FORMAT_LEFT); InsertColumn(ITEM_STATUS,_T("Status"),wxLIST_FORMAT_LEFT); for(size_t i = 0; (i < n) && bRtn; i++) { pDirEntry = m_pDirList->At(i); const wxString &sInput(pDirEntry->GetInputDir()); const wxString &sStatus(pDirEntry->GetStatusString()); nItem = InsertItem((long)i,sInput); sTime = pDirEntry->FormatStartTime(); SetItem(nItem,ITEM_START,sTime); if(!sTime.IsEmpty()) { bStartTime = true; } sTime = pDirEntry->FormatStopTime(); SetItem(nItem,ITEM_STOP,sTime); if(!sTime.IsEmpty()) { bStopTime = true; } SetItem(nItem,ITEM_STATUS,sStatus); SetItemTextColour(nItem,pDirEntry->GetStatusColour()); } SetColumnWidth(ITEM_DIR,wxLIST_AUTOSIZE ); #define HEADER_SIZE 80 SetColumnWidth(ITEM_START,bStartTime ? wxLIST_AUTOSIZE : HEADER_SIZE); SetColumnWidth(ITEM_STOP,bStopTime ? wxLIST_AUTOSIZE : HEADER_SIZE); #undef HEADER_SIZE SetColumnWidth(ITEM_STATUS,wxLIST_AUTOSIZE ); if(bIsShown) { Show(true); } Refresh(); return bRtn; }
void sRunTest(const string &sTestName, const STestInfo & testInfo, bool keep) { cerr << "Testing " << testInfo.mInFile.GetName() << " against " << testInfo.mOutFile.GetName() << " and " << testInfo.mErrorFile.GetName() << endl; string logName = CDirEntry::GetTmpName(); CErrorLogger logger(logName); CGvfReader reader(0); CNcbiIfstream ifstr(testInfo.mInFile.GetPath().c_str()); typedef CGff2Reader::TAnnotList ANNOTS; ANNOTS annots; try { reader.ReadSeqAnnots(annots, ifstr, &logger); } catch (...) { BOOST_ERROR("Error: " << sTestName << " failed during conversion."); ifstr.close(); return; } string resultName = CDirEntry::GetTmpName(); CNcbiOfstream ofstr(resultName.c_str()); for (ANNOTS::iterator cit = annots.begin(); cit != annots.end(); ++cit){ ofstr << MSerial_AsnText << **cit; ofstr.flush(); } ifstr.close(); ofstr.close(); bool success = testInfo.mOutFile.CompareTextContents(resultName, CFile::eIgnoreWs); if (!success) { CDirEntry deResult = CDirEntry(resultName); if (keep) { deResult.Copy(testInfo.mOutFile.GetPath() + "." + extKeep); } deResult.Remove(); CDirEntry(logName).Remove(); BOOST_ERROR("Error: " << sTestName << " failed due to post processing diffs."); } CDirEntry(resultName).Remove(); success = testInfo.mErrorFile.CompareTextContents(logName, CFile::eIgnoreWs); CDirEntry deErrors = CDirEntry(logName); if (!success && keep) { deErrors.Copy(testInfo.mErrorFile.GetPath() + "." + extKeep); } deErrors.Remove(); if (!success) { BOOST_ERROR("Error: " << sTestName << " failed due to error handling diffs."); } };
void operator()( const CDirEntry & dirEntry ) { if( ! dirEntry.IsFile() ) { return; } CFile file(dirEntry); string name = file.GetName(); if (NStr::EndsWith(name, ".txt") || NStr::StartsWith(name, ".")) { return; } // extract info from the file name const string sFileName = file.GetName(); vector<CTempString> vecFileNamePieces; NStr::Split( sFileName, ".", vecFileNamePieces ); BOOST_REQUIRE(vecFileNamePieces.size() == 2); CTempString tsTestName = vecFileNamePieces[0]; BOOST_REQUIRE(!tsTestName.empty()); CTempString tsFileType = vecFileNamePieces[1]; BOOST_REQUIRE(!tsFileType.empty()); STestInfo & test_info_to_load = (*m_pTestNameToInfoMap)[vecFileNamePieces[0]]; // figure out what type of file we have and set appropriately if (tsFileType == mExtInput) { BOOST_REQUIRE( test_info_to_load.mInFile.GetPath().empty() ); test_info_to_load.mInFile = file; } else if (tsFileType == mExtOutput) { BOOST_REQUIRE( test_info_to_load.mOutFile.GetPath().empty() ); test_info_to_load.mOutFile = file; } else if (tsFileType == mExtErrors) { BOOST_REQUIRE( test_info_to_load.mErrorFile.GetPath().empty() ); test_info_to_load.mErrorFile = file; } else { BOOST_FAIL("Unknown file type " << sFileName << "."); } }
void operator()( const CDirEntry & dirEntry ) { const static size_t kInvalidFileNumber = numeric_limits<size_t>::max(); if( ! dirEntry.IsFile() ) { return; } CFile file(dirEntry); // skip the README file if( file.GetName() == "README.txt" ) { return; } // skip .svn files if( NStr::Find(file.GetPath(), ".svn") != NPOS ) { return; } const string sFilePath = file.GetPath(); cout << "Parsing file name: " << sFilePath << endl; // extract info from the file name const string sFileName = file.GetName(); vector<CTempString> vecFileNamePieces; NStr::Tokenize( sFileName, ".", vecFileNamePieces ); BOOST_REQUIRE( vecFileNamePieces.size() == 2 || vecFileNamePieces.size() == 3 ); CTempString tsTestName = vecFileNamePieces[0]; BOOST_REQUIRE( ! tsTestName.empty() ); CTempString tsFileType = vecFileNamePieces[1]; size_t iFileNumber = kInvalidFileNumber; if( vecFileNamePieces.size() > 2 ) { iFileNumber = NStr::StringToUInt(vecFileNamePieces[2]); } STestInfo & test_info_to_load = (*m_pTestNameToInfoMap)[vecFileNamePieces[0]]; // figure out what type of file we have and set appropriately if( tsFileType == "agp" && iFileNumber == kInvalidFileNumber ) { // handle agp file // (and make sure we don't have duplicates) BOOST_REQUIRE( test_info_to_load.m_AGPFile.GetPath().empty() ); test_info_to_load.m_AGPFile = file; } else if( tsFileType == "expected_seq_entry" && iFileNumber != kInvalidFileNumber ) { // handle expected seq-entry file // (Note that the files could come in in any order) vector<CFile> & vecExpectedSeqEntryFiles = test_info_to_load.m_vecExpectedSeqEntryFiles; if( vecExpectedSeqEntryFiles.size() <= iFileNumber ) { // expand the vector to include this file number vecExpectedSeqEntryFiles.resize( 1 + iFileNumber ); } // make sure no duplicates BOOST_REQUIRE( vecExpectedSeqEntryFiles[iFileNumber].GetPath().empty() ); vecExpectedSeqEntryFiles[iFileNumber] = file; } else if( tsFileType == "flags" && iFileNumber == kInvalidFileNumber ) { // handle flags file BOOST_REQUIRE( test_info_to_load.m_FlagFile.GetPath().empty() ); test_info_to_load.m_FlagFile = file; } else { BOOST_FAIL("Unknown file type"); } }
CPWad::CPWad (XString name) : file (name, O_RDWR | O_BINARY), currentmap(0) { if (file.IsOpen()) { // -=- read the pwad header -=- cout << "Opened '" << name << "'" << endl; cdebug.out << "Opened '" << name << "'" << endl; file.Read (&header, sizeof(PWAD_HEADER)); swaplong((int *)&(header.dir_offset)); swaplong((int *)&(header.dir_entries)); if (memcmp ("PWAD", header.signature, 4) != 0) { cout << "Not a PWAD!" << "\n"; cdebug.out << "Not a PWAD!" << "\n"; Fail (); return; } else { cdebug.out << "File size: " << file.Size() << endl; cdebug.out << "Directory Offset: " << header.dir_offset << endl; cdebug.out << "Directory Entries: " << header.dir_entries << endl; } // -=- read the directory -=- file.Seek (header.dir_offset); MemHandle dirbuff = file.Read ((size_t)(header.dir_entries * sizeof(DIR_ENTRY))); if (dirbuff.Size () != (header.dir_entries * sizeof(DIR_ENTRY))) { cout << "Error Reading PWAD Directory." << endl; cdebug.out << "Error Reading PWAD Directory." << endl; Fail (); } else { cout << "Building directory...." << flush; swap_lump_list((void *)dirbuff.Buffer(), header.dir_entries); // -=- go through each dir entry and add it to our internal dir -=- DIR_ENTRY *entry_ptr = (DIR_ENTRY *)dirbuff.Buffer(); for (int n = 0; n < header.dir_entries; n++) { AddEntry (entry_ptr[n]); } cout << "Done." << endl; // -=- print out directory used for debugging -=- CDirEntry *de; CDirEntry *sde; de = (CDirEntry *)directory.FirstItem (); while (de) { cdebug.out << de->GetKey() << " " << de->Size() << " bytes\t @" << de->Offset() << endl; sde = (CDirEntry *)de->subdir.FirstItem (); while (sde) { cdebug.out << " " << sde->GetKey() << " " << sde->Size() << " bytes\t @" << sde->Offset() << endl; sde = (CDirEntry *)sde->Next(); } de = (CDirEntry *)de->Next(); } // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- } } else { cout << "Cannot open '" << name << "'" << endl; cdebug.out << "Cannot open '" << name << "'" << endl; Fail (); } }