void CResourceBase::AddResourceDir( LPCTSTR pszDirName ) { ADDTOCALLSTACK("CResourceBase::AddResourceDir"); if ( pszDirName[0] == '\0' ) return; CGString sFilePath = CGFile::GetMergedFileName( pszDirName, "*" GRAY_SCRIPT ); CFileList filelist; int iRet = filelist.ReadDir( sFilePath, false ); if ( iRet < 0 ) { // also check script file path sFilePath = CGFile::GetMergedFileName(m_sSCPBaseDir, sFilePath.GetPtr()); iRet = filelist.ReadDir( sFilePath, true ); if ( iRet < 0 ) { DEBUG_ERR(( "DirList=%d for '%s'\n", iRet, static_cast<LPCTSTR>(pszDirName) )); return; } } if ( iRet <= 0 ) // no files here. { return; } CGStringListRec * psFile = filelist.GetHead(); for ( ; psFile; psFile = psFile->GetNext()) { sFilePath = CGFile::GetMergedFileName( pszDirName, *psFile ); AddResourceFile( sFilePath ); } }
LOCAL_C void Test0(RTest& aTest) // // Scan for open files - no sessions // { aTest.Next(_L("Scan for open files with no sessions open")); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (list==NULL) return; TInt count=list->Count(); if (count==1) { gRunByBatch=ETrue; gBatchFile=(*list)[0].iName; delete list; fileScan.NextL(list); if (list==NULL) return; count=list->Count(); } while (count--) { TEntry entry=(*list)[count]; aTest.Printf(_L("%d) EntryName = %S\n"),count,&entry.iName); } //aTest.Printf(_L("Test will fail unless files are closed.\n")); //aTest.Printf(_L("Press any key ...\n")); //aTest.Getch(); }
CFileList* CLibraryMaps::WhatsNew(const CQuerySearch* pSearch, int nMaximum) const { ASSUME_LOCK( Library.m_pSection ); const DWORD tNow = static_cast< DWORD >( time( NULL ) ); CFileList* pHits = NULL; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); if ( pFile->IsAvailable() && pFile->IsShared() && pFile->m_oSHA1 && ( ! pSearch->m_pSchema || pSearch->m_pSchema->Equals( pFile->m_pSchema ) ) ) { const DWORD nTime = pFile->GetCreationTime(); if ( nTime && nTime + 12 * 60 * 60 > tNow ) // 12 hours { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pFile ); if ( nMaximum && pHits->GetCount() >= nMaximum ) break; } } } return pHits; }
void loadFileLists(CFileList& files, OPTIONS& opt) { // check type of input -> file | direcotry | list if(opt.inputFile.size() > 0) { vector<string>::iterator it; for(it = opt.inputFile.begin(); it != opt.inputFile.end(); it++) { if(fs::is_regular_file(fs::path(*it))) files.AddItem((*it).c_str()); else cout << "WARNING: input file " << *it << " not found" << endl; } } if(!opt.inputList.empty()) { vector<string>::iterator it; for(it = opt.inputList.begin(); it != opt.inputList.end(); it++) { if(!(*it).empty()) ReadTestList((*it).c_str(), &files, opt.inExt.c_str()); } } if(files.ListLength() < 1) { error_report = string("None suitable input files found"); throw runtime_error(error_report.c_str()); } }
LOCAL_C void Test1() // // This test is only called by default drive // Test OpenFileScan // { test.Next(_L("Scan for open files - one session only")); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; TInt r=file1.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(TheFs,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); }
void CLibraryDictionary::BuildHashTable() { ASSUME_LOCK( Library.m_pSection ); if ( m_bValid ) return; if ( ! m_pTable ) { m_pTable = new CQueryHashTable(); if ( ! m_pTable ) return; m_pTable->Create(); } m_pTable->Clear(); // Add words to hash table //TRACE( L"[LD] Dictionary size: %d words\n", m_oWordMap.GetCount() ); //TRACE( L"[LD] Hash table size: %d\n", m_oWordMap.GetHashTableSize() ); for ( POSITION pos1 = m_oWordMap.GetStartPosition(); pos1; ) { CString strWord; CFileList* pList = NULL; m_oWordMap.GetNextAssoc( pos1, strWord, pList ); //TRACE( L"[LD] Word \"%hs\" found %d time(s) in %d file(s)\n", (LPCSTR)CT2A( strWord ), oWord.m_nCount, oWord.m_pList->GetCount() ); for ( POSITION pos2 = pList->GetHeadPosition(); pos2; ) { const CLibraryFile* pFile = pList->GetNext( pos2 ); // Check if the file can be uploaded if ( pFile->IsShared() ) { // Add the keyword to the table m_pTable->AddExactString( strWord ); break; } } } // Add sha1/ed2k hashes to hash table for ( POSITION pos = LibraryMaps.GetFileIterator(); pos; ) { const CLibraryFile* pFile = LibraryMaps.GetNextFile( pos ); // Check if the file can be uploaded if ( pFile->IsShared() ) m_pTable->AddHashes( *pFile ); } m_bValid = true; }
void CFileContainerArc::List(CFileList &list, const char *mask, unsigned flags) { TString<256> Path; Path = mask; char *name = Path.rchr('/'); FDirInfo *Dir; if (name) { *name++ = 0; Dir = FindDir(Path); if (!Dir) return; // directory not found } else { name = Path; Dir = &Root; } // list directories and files #if FS_DIR != FS_FILE<<1 #error Check FS_DIR / FS_FILE relationship #endif for (unsigned Flag = FS_FILE; Flag <= FS_DIR; Flag <<= 1) { if (!(flags & Flag)) continue; CListIterator it; if (Flag == FS_FILE) // cannot write this as "it = (Flag == FS_FILE) ? ..." it = Dir->Files; else it = Dir->Dirs; for ( ; it; ++it) { if (!appMatchWildcard(it->name, name)) continue; TString<256> Name; Name = it->name; // process NOEXT if (flags & FS_NOEXT) { char *s = Name.rchr('.'); if (s) *s = 0; } CFileItem *item, *place; if (!(item = list.Find(Name, &place))) { item = new (Name, &list) CFileItem; // here: item->flags=0 list.InsertAfter(item, place); } item->flags |= containFlags|Flag; } } }
bool CLocalSearch::ExecuteSharedFiles(INT_PTR nMaximum, INT_PTR& nHits) { CSingleLock oLock( &Library.m_pSection ); if ( ! oLock.Lock( 250 ) ) return false; auto_ptr< CFileList > pFiles( Library.Search( m_pSearch, nMaximum, FALSE, // Ghost files only for G2 m_nProtocol != PROTOCOL_G2 ) ); if ( pFiles.get() ) { CFileList oFilesInPacket; for ( POSITION pos = pFiles->GetHeadPosition() ; pos && ( ! nMaximum || ( nHits + oFilesInPacket.GetCount() < nMaximum ) ); ) { CLibraryFile* pFile = pFiles->GetNext( pos ); if ( IsValidForHit( pFile ) ) { oFilesInPacket.AddTail( pFile ); } } SendHits( oFilesInPacket ); nHits += oFilesInPacket.GetCount(); } // Is it a browser request? if ( ! m_pSearch && m_nProtocol == PROTOCOL_G2 ) { // Send virtual tree DispatchPacket( AlbumToPacket( Library.GetAlbumRoot() ) ); // Send physical tree DispatchPacket( FoldersToPacket() ); } return true; }
CFileList* CLibraryMaps::Browse(int nMaximum) const { ASSUME_LOCK( Library.m_pSection ); CFileList* pHits = NULL; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); if ( pFile->IsAvailable() && pFile->IsShared() && pFile->m_oSHA1 ) { if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pFile ); if ( nMaximum && pHits->GetCount() >= nMaximum ) break; } } return pHits; }
void CLibraryDictionary::ProcessWord(CLibraryFile& oFile, const CString& strWord, bool bAdd, bool bCanUpload) { ASSUME_LOCK( Library.m_pSection ); CFileList* pList = NULL; if ( m_oWordMap.Lookup( strWord, pList ) ) { if ( POSITION pos = pList->Find( &oFile ) ) { if ( ! bAdd ) { pList->RemoveAt( pos ); if ( pList->IsEmpty() ) { delete pList; VERIFY( m_oWordMap.RemoveKey( strWord ) ); if ( bCanUpload && m_bValid ) Invalidate(); } } } else { if ( bAdd ) { pList->AddTail( &oFile ); if ( bCanUpload && m_bValid ) m_pTable->AddExactString( strWord ); } } } else if ( bAdd ) { pList = new CFileList; if ( pList ) { pList->AddTail( &oFile ); m_oWordMap.SetAt( strWord, pList ); if ( bCanUpload && m_bValid ) m_pTable->AddExactString( strWord ); } } }
void CFileBrowser::ChangeDir(const std::string & filename, int selection) { std::string newpath; if((m_Mode != ModeSC) && (filename == "..")) { std::string::size_type pos = Path.substr(0,Path.length()-1).rfind('/'); #ifdef ENABLE_MOVIEPLAYER_VLC bool is_vlc = (strncmp(Path.c_str(), VLC_URI, strlen(VLC_URI)) == 0); #endif if (pos == std::string::npos) { newpath = Path; } else { #ifdef ENABLE_MOVIEPLAYER_VLC if (is_vlc && (pos < strlen(VLC_URI) - 1)) newpath = VLC_URI; else #endif newpath = Path.substr(0, pos + 1); } #ifdef ENABLE_MOVIEPLAYER_VLC if (strncmp(is_vlc ? &(newpath.c_str()[strlen(VLC_URI)]) : newpath.c_str(), base.c_str(), base.length()) != 0) return; #endif } else { newpath=filename; } if(m_Mode != ModeSC && (newpath.rfind('/') != newpath.length()-1 || newpath.length() == 0)) { newpath += '/'; } filelist.clear(); Path = newpath; name = newpath; CFileList allfiles; readDir(newpath, &allfiles); // filter CFileList::iterator file = allfiles.begin(); for(; file != allfiles.end() ; file++) { if(Filter != NULL && (!S_ISDIR(file->Mode)) && use_filter) { if(!Filter->matchFilter(file->Name)) { continue; } if(Hide_records) { int ext_pos = file->Name.rfind('.'); if( ext_pos > 0) { std::string extension = file->Name.substr(ext_pos + 1, name.length() - ext_pos); if(strcasecmp(extension.c_str(), "ts") == 0) { std::string fname = file->Name.substr(0, ext_pos) + ".xml"; if(access(fname.c_str(), F_OK) == 0) continue; } } } } if(Dir_Mode && (!S_ISDIR(file->Mode))) { continue; } filelist.push_back(*file); } // sort result sort(filelist.begin(), filelist.end(), sortBy[g_settings.filebrowser_sortmethod]); selected = 0; if ((selection != -1) && (selection < (int)filelist.size())) selected = selection; paintHead(); paint(); }
CFileList* CLibraryMaps::LookupFilesByHash(const CPeerProjectFile* pFilter, BOOL bSharedOnly, BOOL bAvailableOnly, int nMaximum) const { CQuickLock oLock( Library.m_pSection ); CFileList* pFiles = NULL; if ( pFilter->m_oSHA1 ) { for ( CLibraryFile* pFile = m_pSHA1Map[ pFilter->m_oSHA1[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextSHA1 ) { if ( validAndEqual( pFile->m_oSHA1, pFilter->m_oSHA1 ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( pFilter->m_oED2K ) { for ( CLibraryFile* pFile = m_pED2KMap[ pFilter->m_oED2K[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextED2K ) { if ( validAndEqual( pFile->m_oED2K, pFilter->m_oED2K ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) return pFiles; } } } return pFiles; } if ( pFilter->m_oTiger ) { for ( CLibraryFile* pFile = m_pTigerMap[ pFilter->m_oTiger[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextTiger ) { if ( validAndEqual( pFile->m_oTiger, pFilter->m_oTiger ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( pFilter->m_oBTH ) { for ( CLibraryFile* pFile = m_pBTHMap[ pFilter->m_oBTH[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextBTH ) { if ( validAndEqual( pFile->m_oBTH, pFilter->m_oBTH ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) return pFiles; } } } return pFiles; } if ( pFilter->m_oMD5 ) { // Since MD5 is not commonly used for searches we use it for the duplicate file search // which requires getting a list of files not to return only 1 file. See CLibrary::CheckDuplicates for ( CLibraryFile* pFile = m_pMD5Map[ pFilter->m_oMD5[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextMD5 ) { if ( validAndEqual( pFile->m_oMD5, pFilter->m_oMD5 ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( ! pFilter->m_sName.IsEmpty() && pFilter->m_nSize != SIZE_UNKNOWN && pFilter->m_nSize != 0 ) { if ( CLibraryFile* pFile = LibraryMaps.LookupFileByName( pFilter->m_sName, pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); } } return pFiles; } return pFiles; // Null }
LOCAL_C void Test5() // // Test OpenFileScan // { test.Next(_L("Scan for open files - mixed RDirs and RFiles")); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; TInt r=file1.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(TheFs,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(TheFs,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); RDir dir1,dir2,dir3,dir4; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir1.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir2.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir3.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir4.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); dir1.Close(); dir2.Close(); dir3.Close(); dir4.Close(); }
CFileList* CLibraryDictionary::Search(const CQuerySearch* pSearch, const int nMaximum, const bool bLocal, const bool bAvailableOnly) { ASSUME_LOCK( Library.m_pSection ); if ( ! m_bValid ) { BuildHashTable(); if ( ! m_bValid ) return NULL; } // Only check the hash when a search comes from other client. if ( ! bLocal && ! m_pTable->Check( pSearch ) ) return NULL; ++m_nSearchCookie; CLibraryFile* pHit = NULL; CQuerySearch::const_iterator pWordEntry = pSearch->begin(); const CQuerySearch::const_iterator pLastWordEntry = pSearch->end(); for ( ; pWordEntry != pLastWordEntry; ++pWordEntry ) { if ( pWordEntry->first[ 0 ] == L'-' ) continue; CString strWord( pWordEntry->first, static_cast< int >( pWordEntry->second ) ); CFileList* pList = NULL; if ( m_oWordMap.Lookup( strWord, pList ) ) { for ( POSITION pos = pList->GetHeadPosition(); pos; ) { CLibraryFile* pFile = pList->GetNext( pos ); if ( bAvailableOnly && ! pFile->IsAvailable() ) continue; if ( ! bLocal && ! pFile->IsShared() ) continue; if ( pFile->m_nSearchCookie == m_nSearchCookie ) { ++pFile->m_nSearchWords; } else { pFile->m_nSearchCookie = m_nSearchCookie; pFile->m_nSearchWords = 1; pFile->m_pNextHit = pHit; pHit = pFile; } } } } size_t nLowerBound = ( pSearch->tableSize() >= 3 ) ? ( pSearch->tableSize() * 2 / 3 ) : pSearch->tableSize(); CFileList* pHits = NULL; for ( ; pHit; pHit = pHit->m_pNextHit ) { ASSERT( pHit->m_nSearchCookie == m_nSearchCookie ); if ( pHit->m_nSearchWords < nLowerBound ) continue; if ( pSearch->Match( pHit->GetSearchName(), pHit->m_pSchema ? (LPCTSTR)pHit->m_pSchema->GetURI() : NULL, pHit->m_pMetadata, pHit ) ) { if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pHit ); if ( ! bLocal ) { pHit->m_nHitsToday ++; pHit->m_nHitsTotal ++; } if ( pHit->m_nCollIndex ) { CLibraryFile* pCollection = LibraryMaps.LookupFile( pHit->m_nCollIndex, ! bLocal, bAvailableOnly ); if ( pCollection ) { if ( pCollection->m_nSearchCookie != m_nSearchCookie ) { pCollection->m_nSearchCookie = m_nSearchCookie; pHits->AddHead( pCollection ); } } else { // Collection removed without deleting indexes pHit->m_nCollIndex = 0ul; } } if ( nMaximum > 0 && pHits->GetCount() >= nMaximum ) break; } } return pHits; }
LOCAL_C void Test4() // // Test openfilescan - rdirs, empty, full, empty rdirs. // { test.Next(_L("Scan for open files - check RDir sessions are ignored")); RFs fs1,fs2,fs3,fs4; TFileName fn; TInt r=fs1.Connect(); test(r==KErrNone); r=fs2.Connect(); test(r==KErrNone); r=fs3.Connect(); test(r==KErrNone); r=fs4.Connect(); test(r==KErrNone); RDir dir1,dir2,dir3,dir4; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir1.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir2.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir3.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir4.Open(TheFs,fn,KEntryAttMaskSupported); test(r==KErrNone); RFile file1,file2,file3; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file1.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs2,fn,EFileRead); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); RDir dir5,dir6,dir7,dir8; fn = _L("Z:\\TEST\\*.XDE"); fn[0] = gExeFileName[0]; r=dir5.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir6.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir7.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); r=dir8.Open(fs4,fn,KEntryAttMaskSupported); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); dir1.Close(); dir2.Close(); dir3.Close(); dir4.Close(); dir5.Close(); dir6.Close(); dir7.Close(); dir8.Close(); fs1.Close(); fs2.Close(); fs3.Close(); fs4.Close(); }
LOCAL_C void Test3() // // Test openfilescan - empty, full, empty full // { test.Next(_L("Scan for open files - multiple sessions")); RFs fs1,fs2,fs3,fs4; TInt r=fs1.Connect(); test(r==KErrNone); r=fs2.Connect(); test(r==KErrNone); r=fs3.Connect(); test(r==KErrNone); r=fs4.Connect(); test(r==KErrNone); RFile file1,file2,file3; TFileName fn; fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file1.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs2,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); r=file1.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FILE.CPP"); fn[0] = gExeFileName[0]; r=file2.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); fn = _L("Z:\\TEST\\T_FSRV.CPP"); fn[0] = gExeFileName[0]; r=file3.Open(fs4,fn,EFileRead|EFileShareReadersOnly); test(r==KErrNone); CFileList* list; TOpenFileScan fileScan(TheFs); fileScan.NextL(list); if (gRunByBatch) { test(list!=NULL); test(list->Count()==1); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L(".BAT"))>=0); delete list; fileScan.NextL(list); } test(list!=NULL); TInt count=list->Count(); test(count==3); TEntry entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); TThreadId threadId=fileScan.ThreadId(); RThread current; TThreadId currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list!=NULL); count=list->Count(); test(count==3); entry=(*list)[0]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); entry=(*list)[1]; test(entry.iName.FindF(_L("T_FILE.CPP"))>=0); entry=(*list)[2]; test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0); threadId=fileScan.ThreadId(); currentId=current.Id(); test(threadId==currentId); delete list; fileScan.NextL(list); test(list==NULL); file1.Close(); file2.Close(); file3.Close(); fs1.Close(); fs2.Close(); fs3.Close(); fs4.Close(); }
//! Creates a list of files and directories in the current working directory IFileList* CFileSystem::createFileList() { CFileList* r = 0; io::path Path = getWorkingDirectory(); Path.replace('\\', '/'); if (Path.lastChar() != '/') Path.append('/'); //! Construct from native filesystem if (FileSystemType == FILESYSTEM_NATIVE) { io::path fullPath; // -------------------------------------------- //! Windows version #ifdef _IRR_WINDOWS_API_ #if !defined ( _WIN32_WCE ) r = new CFileList(Path, true, false); struct _finddata_t c_file; long hFile; if( (hFile = _findfirst( "*", &c_file )) != -1L ) { do { fullPath = Path + c_file.name; r->addItem(fullPath, c_file.size, (_A_SUBDIR & c_file.attrib) != 0, 0); } while( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); } #endif //TODO add drives //entry.Name = "E:\\"; //entry.isDirectory = true; //Files.push_back(entry); #endif // -------------------------------------------- //! Linux version #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) r = new CFileList(Path, false, false); r->addItem(Path + "..", 0, true, 0); //! We use the POSIX compliant methods instead of scandir DIR* dirHandle=opendir(Path.c_str()); if (dirHandle) { struct dirent *dirEntry; while ((dirEntry=readdir(dirHandle))) { u32 size = 0; bool isDirectory = false; fullPath = Path + dirEntry->d_name; if((strcmp(dirEntry->d_name, ".")==0) || (strcmp(dirEntry->d_name, "..")==0)) { continue; } struct stat buf; if (stat(dirEntry->d_name, &buf)==0) { size = buf.st_size; isDirectory = S_ISDIR(buf.st_mode); } #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__) // only available on some systems else { isDirectory = dirEntry->d_type == DT_DIR; } #endif r->addItem(fullPath, size, isDirectory, 0); } closedir(dirHandle); } #endif } else { //! create file list for the virtual filesystem r = new CFileList(Path, false, false); //! add relative navigation SFileListEntry e2; SFileListEntry e3; //! PWD r->addItem(Path + ".", 0, true, 0); //! parent r->addItem(Path + "..", 0, true, 0); //! merge archives for (u32 i=0; i < FileArchives.size(); ++i) { const IFileList *merge = FileArchives[i]->getFileList(); for (u32 j=0; j < merge->getFileCount(); ++j) { if (core::isInSameDirectory(Path, merge->getFullFileName(j)) == 0) { io::path fullPath = merge->getFullFileName(j); r->addItem(fullPath, merge->getFileSize(j), merge->isDirectory(j), 0); } } } } if (r) r->sort(); return r; }
void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, bool bRootCall) { neutrino_msg_t msg; neutrino_msg_data_t data; int n; dprintf(DEBUG_INFO, "CFileBrowser::addRecursiveDir %s\n", rpath.c_str()); if (bRootCall) bCancel = false; g_RCInput->getMsg_us(&msg, &data, 1); if (msg == CRCInput::RC_home) { // home key cancel scan bCancel = true; } else if (msg != CRCInput::RC_timeout) { // other event, save to low priority queue g_RCInput->postMsg( msg, data, false ); } if(bCancel) return; if ( ((rpath.empty()) || ((*rpath.rbegin()) != '/'))) { rpath += '/'; } CFileList tmplist; if(!readDir(rpath, &tmplist)) { perror(("Recursive scandir: " + rpath).c_str()); } else { n = tmplist.size(); for(int i = 0; i < n;i++) { std::string basename = tmplist[i].Name.substr(tmplist[i].Name.rfind('/')+1); if( basename != ".." ) { if(Filter != NULL && (!S_ISDIR(tmplist[i].Mode)) && use_filter) { if(!Filter->matchFilter(tmplist[i].Name)) { continue; } } if(!S_ISDIR(tmplist[i].Mode)) re_filelist->push_back(tmplist[i]); else addRecursiveDir(re_filelist,tmplist[i].Name, false); } } } }
void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, bool bRootCall, CProgressWindow * progress) { neutrino_msg_t msg; neutrino_msg_data_t data; int n; //printf("addRecursiveDir %s\n",rpath.c_str()); if (bRootCall) bCancel=false; g_RCInput->getMsg_us(&msg, &data, 1); if (msg==CRCInput::RC_home) { // home key cancel scan bCancel=true; } else if (msg!=CRCInput::RC_timeout) { // other event, save to low priority queue g_RCInput->postMsg( msg, data, false ); } if(bCancel) return; if ((m_Mode != ModeSC) && ((rpath.empty()) || ((*rpath.rbegin()) != '/'))) { rpath += '/'; } CFileList tmplist; if(!readDir(rpath, &tmplist)) { perror(("Recursive scandir: "+rpath).c_str()); } else { n = tmplist.size(); if(progress) { progress->showStatusMessageUTF(FILESYSTEM_ENCODING_TO_UTF8_STRING(rpath)); } for(int i = 0; i < n;i++) { if(progress) { progress->showGlobalStatus(100/n*i); } std::string basename = tmplist[i].Name.substr(tmplist[i].Name.rfind('/')+1); if( basename != ".." ) { if(Filter != NULL && (!S_ISDIR(tmplist[i].Mode)) && use_filter) { if(!Filter->matchFilter(tmplist[i].Name)) { continue; } } if(!S_ISDIR(tmplist[i].Mode)) re_filelist->push_back(tmplist[i]); else addRecursiveDir(re_filelist,tmplist[i].Name, false, progress); } } } }
void CTorrent::SetupPartMap() { ASSERT(!m_TorrentInfo->IsEmpty()); CFile* pFile = GetFile(); // Single File if(!m_TorrentInfo->IsMultiFile()) { if(!pFile->GetPartMap()) pFile->SetPartMap(CPartMapPtr(new CSynced<CPartMap>(m_TorrentInfo->GetTotalLength()))); return; } // Multi File: CJoinedPartMap* pParts = qobject_cast<CJoinedPartMap*>(pFile->GetPartMap()); if(pParts) { ASSERT(!pParts->GetLinks().isEmpty()); return; // is already set up } pParts = new CJoinedPartMap(pFile->GetFileSize()); pFile->GetInspector()->SetIndexSource(HashTorrent); CFileList* pList = pFile->GetList(); uint64 Offset = 0; foreach(const CTorrentInfo::SFileInfo& SubFile, m_TorrentInfo->GetFiles()) { if(SubFile.Length == 0) { LogLine(LOG_DEBUG | LOG_WARNING, tr("Ignoring empty file '%1' in torrent '%2'").arg(SubFile.FileName).arg(pFile->GetFileName())); continue; } CFile* pSubFile = new CFile(); if(pFile->GetProperty("Temp").toBool()) pSubFile->SetProperty("Temp", true); QString Dir = pFile->GetFileDir(); Dir += pFile->GetFileName() + "/"; if(!SubFile.FilePath.isEmpty()) Dir += SubFile.FilePath.join("/") + "/"; pSubFile->SetFileDir(Dir); pSubFile->AddEmpty(HashTorrent, SubFile.FileName, SubFile.Length, pFile->IsPending()); // Note: SubFile->MasterHash is set in MasterFile->Resume uint64 uBegin = Offset; uint64 uEnd = Offset + SubFile.Length; Offset += SubFile.Length; CSharedPartMap* pSubParts = new CSharedPartMap(uEnd - uBegin); pSubFile->SetPartMap(CPartMapPtr(pSubParts)); pParts->SetupLink(uBegin, uEnd, pSubFile->GetFileID()); pSubParts->SetupLink(uBegin, uEnd, pFile->GetFileID()); pList->AddFile(pSubFile); if(!pSubFile->IsPending()) pSubFile->Resume(); if(pFile->IsPaused(true)) pSubFile->Pause(); else if(pFile->IsStarted()) pSubFile->Start(); } pFile->SetPartMap(CPartMapPtr(pParts)); }
void CFileBrowser::ChangeDir(const std::string& filename, int selection) { dprintf(DEBUG_INFO, "CFileBrowser::ChangeDir %s\n", filename.c_str()); std::string newpath; if((filename == "..")) { std::string::size_type pos = Path.substr(0, Path.length()-1).rfind('/'); if (pos == std::string::npos) { newpath = Path; } else { newpath = Path.substr(0, pos + 1); } if (strncmp(newpath.c_str(), base.c_str(), base.length()) != 0) return; } else { newpath = filename; } if((newpath.rfind('/') != newpath.length()-1 || newpath.length() == 0)) { newpath += '/'; } Path = newpath; name = newpath; CFileList allfiles; readDir(newpath, &allfiles); filelist.clear(); // filter CFileList::iterator file = allfiles.begin(); for(; file != allfiles.end() ; file++) { if(Filter != NULL && (!S_ISDIR(file->Mode)) && use_filter) { if(!Filter->matchFilter(file->Name)) { continue; } // ts filter if(Hide_records) { int ext_pos = file->Name.rfind('.'); if( ext_pos > 0) { std::string extension = file->Name.substr(ext_pos + 1, name.length() - ext_pos); if(strcasecmp(extension.c_str(), "ts") == 0) { std::string fname = file->Name.substr(0, ext_pos) + ".xml"; if(access(fname.c_str(), F_OK) == 0) continue; } } } } if(Dir_Mode && (!S_ISDIR(file->Mode))) { continue; } filelist.push_back(*file); } // sort result sort(filelist.begin(), filelist.end(), sortBy[g_settings.filebrowser_sortmethod]); selected = 0; if ((selection != -1) && (selection < (int)filelist.size())) selected = selection; paintHead(); paint(); }