status_t TElementsSorter::EvaluateRef(entry_ref &ref) { struct stat st; BEntry entry; // Can we create a BEntry? if (entry.SetTo(&ref, false) != B_OK) return B_ERROR; // Can we get a BStatable? if (entry.GetStat(&st) != B_OK) return B_ERROR; // Is it a SymLink? if (S_ISLNK(st.st_mode)) return HandleLink(ref, st); // How about a File? else if (S_ISREG(st.st_mode)) return HandleFile(ref, st); // A Directory? else if (S_ISDIR(st.st_mode)) { BDirectory dir; if (dir.SetTo(&ref) != B_OK) return B_ERROR; if (dir.IsRootDirectory()) return HandleVolume(ref, st, dir); else return HandleDirectory(ref, st, dir); } // No luck return B_ERROR; }
void ImportBinary::on_Browse__released () { QString startingPath = QFileInfo (Ui_.File_->text ()).path (); if (startingPath.isEmpty ()) startingPath = QDir::homePath (); QString filename = QFileDialog::getOpenFileName (this, tr ("Select binary file"), startingPath, tr ("Aggregator exchange files (*.lcae);;" "All files (*.*)")); if (filename.isEmpty ()) { QTimer::singleShot (0, this, SLOT (reject ())); return; } Reset (); Ui_.File_->setText (filename); Ui_.ButtonBox_->button (QDialogButtonBox::Open)-> setEnabled (HandleFile (filename)); }
AudioClip::AudioClip(const AudioClip & clip) { mClipType = clip.mClipType; mFileStreamPtr = clip.mFileStreamPtr; mFilePath = clip.mFilePath; mAudioSource = clip.mAudioSource; // Only used if the audio is type::memory mOpenALBufferID = 0; // Can't copy that *mType = *clip.mType; mSize = clip.mSize; mChunckSize = clip.mChunckSize; mFormatType = clip.mFormatType; mNumChannels = clip.mNumChannels; mBytesPerSample = clip.mBytesPerSample; mBitsPerSample = clip.mBitsPerSample; mSampleRate = clip.mSampleRate; mByteRate = clip.mByteRate; mDataSize = clip.mDataSize; if (mAudioData) *mAudioData = *clip.mAudioData; HandleFile(); CreateOpenALBuffer(); }
//************************************************************************ // Method: EnumDFS // Purpose: 非递归深度优先搜索 // Access: protected // Returns: BOOL // Qualifier: // Parameter: LPCTSTR lpszDirectory // 要遍历的目录 // Parameter: FindDataInfo & fdi // 搜索信息 // Parameter: HANDLE hStopEvent // 停止信号量 //************************************************************************ BOOL CFileEnumBase::EnumDFS(LPCTSTR lpszDirectory, FindDataInfo& fdi, HANDLE hStopEvent) { CDFSFinder fileFinder(lpszDirectory, fdi); if (!fileFinder.FindCurDirFirst()) { return FALSE; } while (!fileFinder.IsFinished() && !IsStopEventSignaled()) { const FindDataInfo& fileInfo = fileFinder.GetFileInfo(); // 如果不是已解析过的节点 if (!fileFinder.IsReparsePoint()) { // 如果是文件目录 if (fileFinder.IsDirectory()) { // 如果不是.和..目录 if (!fileFinder.IsDot()) { if (CheckUseDir(fileFinder.GetPath(), fileInfo)) { // 处理找到的目录 HandleDir(fileFinder.GetPath(), fileInfo); if (!fileFinder.FindSubDirFirst()) { return FALSE; } } } } else { // 如果是文件 if (CheckUseFile(fileFinder.GetPath(), fileInfo)) { // 处理找到的文件 HandleFile(fileFinder.GetPath(), fileInfo); // TRACE(_T("%s\n"), fileFinder.GetPath()); } } } // 如果找不到下一个文件时 if (!fileFinder.FindCurDirNext()) { // 查找下一个父节点目录 do { FinishedDir(fileFinder.GetPath()); } while (!fileFinder.FindParentDirNext() && !fileFinder.IsFinished() && !IsStopEventSignaled()); } } return TRUE; }
void ImportOPML::on_File__textEdited (const QString& newFilename) { Reset (); if (QFile (newFilename).exists ()) Ui_.ButtonBox_->button (QDialogButtonBox::Open)-> setEnabled (HandleFile (newFilename)); else Reset (); }
//************************************************************************ // Method: EnumRecursively // Purpose: 深度优先递归搜索 // Access: protected // Returns: BOOL // Qualifier: // Parameter: LPCTSTR lpszDirectory // 要遍历的目录 // Parameter: FindDataInfo & fdi // 搜索信息 // Parameter: BOOL bFindSubDir // 是否查找子目录 // Parameter: HANDLE hStopEvent // 停止信号量 //************************************************************************ BOOL CFileEnumBase::EnumRecursively(LPCTSTR lpszDirectory, FindDataInfo& fdi, BOOL bFindSubDir, HANDLE hStopEvent) { CBaseFileFinder fileFinder(lpszDirectory, fdi); // 寻找遍历的根节点 BOOL bRet = fileFinder.FindCurDirFirst(); if (bRet == FALSE) { return FALSE; } while (!fileFinder.IsFinished() && !IsStopEventSignaled()) { const FindDataInfo& fileInfo = fileFinder.GetFileInfo(); // 如果不是已解析过的节点 if (!fileFinder.IsReparsePoint()) { // 如果是文件目录 if (fileFinder.IsDirectory()) { // 如果不是.和..目录 if (!fileFinder.IsDot() && bFindSubDir) { if (CheckUseDir(fileFinder.GetPath(), fileInfo)) { // 处理找到的目录 HandleDir(fileFinder.GetPath(), fileInfo); bRet &= EnumRecursively(fileFinder.GetPath(), fdi, bFindSubDir); } } } else { // 如果是文件 if (CheckUseFile(fileFinder.GetPath(), fileInfo)) { // 处理找到的文件 HandleFile(fileFinder.GetPath(), fileInfo); // TRACE(_T("%s\n"), fileFinder.GetPath()); } } } // 如果找不到下一个目标时,退出查找 if (!fileFinder.FindCurDirNext()) { FinishedDir(fileFinder.GetPath()); break; } } return bRet; }
status_t TElementsSorter::HandleLink(entry_ref &theRef, struct stat &st) { // Resolve possible symlink... BEntry entry(&theRef, true); if ( entry.InitCheck() == B_OK ) { entry.GetRef(&theRef); return HandleFile(theRef, st); } return B_ERROR; }
void PackageProcessor::Install (int packageId) { QUrl url = GetURLFor (packageId); ExternalResourceManager *erm = PrepareResourceManager (); if (QFile::exists (erm->GetResourcePath (url))) HandleFile (packageId, url, MInstall); else { URL2Id_ [url] = packageId; URL2Mode_ [url] = MInstall; erm->GetResourceData (url); } }
void PackageProcessor::Update (int toPackageId) { QUrl url = GetURLFor (toPackageId); ExternalResourceManager *erm = PrepareResourceManager (); if (QFile::exists (erm->GetResourcePath (url))) HandleFile (toPackageId, url, MUpdate); else { URL2Id_ [url] = toPackageId; URL2Mode_ [url] = MUpdate; erm->GetResourceData (url); } }
BOOL CFileEnumBase::EnumFiles(LPCTSTR lpszDirectory, BOOL bFindSubDir, HANDLE hStopEvent) { if (!lpszDirectory || !*lpszDirectory) { return FALSE; } BOOL bRet = TRUE; FindDataInfo fdi = {0}; #ifdef __RECURSION // 递归搜索 bRet = EnumRecursively(lpszDirectory, fdi, bFindSubDir, hStopEvent); #else if (bFindSubDir) { #ifdef __BFS // 广度优先搜索 bRet = EnumBFS(lpszDirectory, fdi, hStopEvent); #else // 深度优先搜索 bRet = EnumDFS(lpszDirectory, fdi, hStopEvent); #endif // __BFS } else { // 不搜索子目录 CBaseFileFinder fileFinder(lpszDirectory, fdi); if (!fileFinder.FindCurDirFirst()) { return FALSE; } for (; !fileFinder.IsFinished() && !IsStopEventSignaled(); fileFinder.FindCurDirNext()) { const FindDataInfo& fileInfo = fileFinder.GetFileInfo(); if (CheckUseFile(fileFinder.GetPath(), fileInfo)) { HandleFile(fileFinder.GetPath(), fileInfo); } } } #endif // __RECURSION return bRet; }
AudioClip::AudioClip(const std::string & filePath, AudioClipType audioClipType) : mClipType{ audioClipType }, mFilePath(filePath), mFileStreamPtr{ nullptr }, mSize{ 0 }, mChunckSize{ 0 }, mFormatType{ 0 }, mNumChannels{ 0 }, mBytesPerSample{ 0 }, mBitsPerSample{ 0 }, mSampleRate{ 0 }, mByteRate{ 0 }, mDataSize{ 0 }, mAudioData{ nullptr } { HandleFile(); CreateOpenALBuffer(); }
status_t TQueueDialog::EvaluateRef(entry_ref &ref) { struct stat st; BEntry entry; // Can we create a BEntry? if (entry.SetTo(&ref, false) != B_OK) { ERROR("TQueueDialog::HandleRefsMessage() - BEntry SetTo() failure -\n"); return B_ERROR; } // Can we get a BStatable? if (entry.GetStat(&st) != B_OK) { ERROR("TQueueDialog::HandleRefsMessage() - BEntry GetStat() failure -\n"); return B_ERROR; } // Is it a SymLink? if (S_ISLNK(st.st_mode)) return HandleLink(ref, st); // How about a File? else if (S_ISREG(st.st_mode)) return HandleFile(ref, st); // A Directory? else if (S_ISDIR(st.st_mode)) { BDirectory dir; if (dir.SetTo(&ref) != B_OK) { return B_ERROR; } if (dir.IsRootDirectory()) return HandleVolume(ref, st, dir); else return HandleDirectory(ref, st, dir); } // No luck return B_ERROR; }
// // Here's the thread's actual execution path... // void FileThread::run(void) { QDir romDir(vjs.ROMPath); QFileInfoList list = romDir.entryInfoList(); for(int i=0; i<list.size(); i++) { if (abort) #ifdef VERBOSE_LOGGING { printf("FileThread: Aborting!!!\n"); #endif return; #ifdef VERBOSE_LOGGING } #endif HandleFile(list.at(i)); } }
Cue ParseCue (const QString& cue) { QFile file (cue); if (!file.open (QIODevice::ReadOnly)) { qWarning () << Q_FUNC_INFO << "unable to parse" << cue; return Cue (); } Cue result; const auto& lines = file.readAll ().split ('\n'); for (auto i = lines.begin (), end= lines.end (); i != end; ) { const auto& line = i->trimmed (); if (line.startsWith ("REM ")) { HandleREM (line, result); ++i; } else if (line.startsWith ("PERFORMER ")) { result.Performer_ = ChopQuotes (QString::fromUtf8 (line.mid (10))); ++i; } else if (line.startsWith ("TITLE ")) { result.Album_ = ChopQuotes (QString::fromUtf8 (line.mid (6))); ++i; } else if (line.startsWith ("FILE ")) i = HandleFile (line.mid (5), i + 1, end, result); } return result; }
//************************************************************************ // Method: EnumBFS // Purpose: 非递归广度优先搜索 // Access: protected // Returns: BOOL // Qualifier: // Parameter: LPCTSTR lpszDirectory // 要遍历的目录 // Parameter: FindDataInfo & fdi // 搜索信息 // Parameter: HANDLE hStopEvent // 停止信号量 //************************************************************************ BOOL CFileEnumBase::EnumBFS(LPCTSTR lpszDirectory, FindDataInfo& fdi, HANDLE hStopEvent) { CBaseFileFinder *pFinder = NULL; try { pFinder = new CBaseFileFinder(lpszDirectory, fdi); } catch (...) { DELETE_OBJECT(pFinder); return FALSE; } BOOL bRet = pFinder->FindCurDirFirst(); if (bRet == FALSE) { DELETE_OBJECT(pFinder); return FALSE; } while (!pFinder->IsFinished() && !IsStopEventSignaled()) { const FindDataInfo& fileInfo = pFinder->GetFileInfo(); // 如果不是已解析过的节点 if (!pFinder->IsReparsePoint()) { // 如果是文件目录 if (pFinder->IsDirectory()) { // 如果不是.和..目录 if (!pFinder->IsDot()) { if (CheckUseDir(pFinder->GetPath(), fileInfo)) { // 处理找到的目录 HandleDir(pFinder->GetPath(), fileInfo); // TRACE(_T("%s\n"), pFinder->GetPath()); CBaseFileFinder *pNewFinder = NULL; try { // 添加到队列中 pNewFinder = new CBaseFileFinder(pFinder->GetPath(), fdi); m_queueFinder.push(pNewFinder); } catch (...) { DELETE_OBJECT(pNewFinder); } } } } else { // 如果是文件 if (CheckUseFile(pFinder->GetPath(), fileInfo)) { // 处理找到的文件 HandleFile(pFinder->GetPath(), fileInfo); //TRACE(_T("%s\n"), pFinder->GetPath()); } } } // 如果找不到下一个目标时,退出查找 if (!pFinder->FindCurDirNext()) { FinishedDir(pFinder->GetPath()); if (m_queueFinder.empty()) { break; } else { // 如果管理队列未空 while (!IsStopEventSignaled()) { // 取出队首元素 CBaseFileFinder *pNextFinder = m_queueFinder.front(); m_queueFinder.pop(); DELETE_OBJECT(pFinder); pFinder = pNextFinder; // 查找第一个目录 if (!pFinder->FindCurDirFirst()) { // 查找失败,清空队列 DELETE_OBJECT(pFinder); while (!m_queueFinder.empty()) { pFinder = m_queueFinder.front(); m_queueFinder.pop(); DELETE_OBJECT(pFinder); } } else { break; } } // 如果管理队列未空 } } // 如果找不到下一个目标时,退出查找 } // 清空队列 DELETE_OBJECT(pFinder); while (!m_queueFinder.empty()) { pFinder = m_queueFinder.front(); m_queueFinder.pop(); DELETE_OBJECT(pFinder); } return bRet; }
void PackageProcessor::handleResourceFetched (const QUrl& url) { if (URL2Id_.contains (url)) HandleFile (URL2Id_.take (url), url, URL2Mode_.take (url)); }
void ReBuildDPT(char* sz_file_path) { char* sz_tmp = NULL; dbr_list* p_dbr_temp = NULL; dbr_list* p_dbr_temp_tmp = NULL; unsigned char sign[2] = {0x55, 0xAA}; __int64 tmp = 0; int k = 0; int i = 0; rebuild_content_t* rebuild_list = CreateReBuildHead(); if (g_n_part <= 4) { sz_tmp = (char*)malloc(4 * sizeof(PartTableRecord) + 2); memset(sz_tmp, 0, 4 * sizeof(PartTableRecord) + 2); for(p_dbr_temp = g_dbr_list_head->p_next; p_dbr_temp != NULL;) { if (p_dbr_temp->flag) // 是否需可用信息 { *(sz_tmp + k * 16 + 4) = (p_dbr_temp->n_type == 1) ? 0x07 : 0x0B; // byPartType memcpy(sz_tmp + k * 16 + 8, (char *)&(p_dbr_temp->ll_start_sector), sizeof(__int64)); // dwStartSector memcpy(sz_tmp + k * 16 + 12, (char *)&(p_dbr_temp->ll_total_sector), sizeof(__int64)); // dwTotalSector k++; if (p_dbr_temp->n_is_org) // 是否起始扇区 { InsertRebuildList(rebuild_list, p_dbr_temp->dbr, SECTOR_SIZE, p_dbr_temp->ll_start_sector * SECTOR_SIZE, i++); } } p_dbr_temp = p_dbr_temp->p_next; } memcpy(sz_tmp + 64, sign, 2); InsertRebuildList(rebuild_list, sz_tmp, 4 * sizeof(PartTableRecord) + 2, 446, i++); } else { sz_tmp = (char*)malloc(4 * sizeof(PartTableRecord) + 2); memset(sz_tmp, 0, 4 * sizeof(PartTableRecord) + 2); for(p_dbr_temp = g_dbr_list_head->p_next; p_dbr_temp != NULL;) { if (p_dbr_temp->flag) // 是否需可用信息 { if (k < 3) { if (k != 2) { *(sz_tmp + k * 16 + 4) = (p_dbr_temp->n_type == 1) ? 0x07 : 0x0B; // byPartType memcpy(sz_tmp + k * 16 + 8, (char *)&(p_dbr_temp->ll_start_sector), sizeof(__int64)); // dwStartSector tmp = p_dbr_temp->ll_total_sector + 1; memcpy(sz_tmp + k * 16 + 12, (char *)&tmp, sizeof(__int64)); // dwTotalSector k++; } else { *(sz_tmp + k * 16 + 4) = (p_dbr_temp->n_type == 1) ? 0x07 : 0x0B; // byPartType memcpy(sz_tmp + k * 16 + 8, (char *)&(p_dbr_temp->ll_start_sector), sizeof(__int64)); // dwStartSector tmp = p_dbr_temp->ll_total_sector + 1; memcpy(sz_tmp + k * 16 + 12, (char *)&tmp, sizeof(__int64)); // dwTotalSector k++; for (p_dbr_temp_tmp = p_dbr_temp->p_next; p_dbr_temp_tmp != NULL;) { if (p_dbr_temp_tmp->flag) { *(sz_tmp + k * 16 + 4) = 0x05; // byPartType tmp = p_dbr_temp_tmp->ll_start_sector - 1; memcpy(sz_tmp + k * 16 + 8, (char *)&tmp, sizeof(__int64)); // dwStartSector tmp = (g_ll_file_size/SECTOR_SIZE) - p_dbr_temp_tmp->ll_start_sector + 1; memcpy(sz_tmp + k * 16 + 12, (char *)&tmp, sizeof(__int64)); // dwTotalSector k++; memcpy(sz_tmp + 64, sign, 2); InsertRebuildList(rebuild_list, sz_tmp, 4 * sizeof(PartTableRecord) + 2, 446, i++); break; } p_dbr_temp_tmp = p_dbr_temp_tmp->p_next; } } } else { sz_tmp = NULL; sz_tmp = (char*)malloc(4 * sizeof(PartTableRecord) + 2); memset(sz_tmp, 0, 4 * sizeof(PartTableRecord) + 2); *(sz_tmp + 4) = (p_dbr_temp->n_type == 1) ? 0x07 : 0x0B; // byPartType tmp = 1; // 扩展分区偏移地址从当前地址算起(相对地址) memcpy(sz_tmp + 8, (char *)&tmp, sizeof(__int64)); // dwStartSector memcpy(sz_tmp + 12, (char *)&(p_dbr_temp->ll_total_sector), sizeof(__int64)); // dwTotalSector if (p_dbr_temp->p_next != NULL) { for (p_dbr_temp_tmp = p_dbr_temp->p_next; p_dbr_temp_tmp != NULL;) { if (p_dbr_temp_tmp->flag) { *(sz_tmp + 16 + 4) = 0x05; // byPartType tmp = p_dbr_temp_tmp->ll_start_sector - p_dbr_temp->ll_start_sector; //tmp = 1; memcpy(sz_tmp + 16 + 8, (char *)&tmp, sizeof(__int64)); // dwStartSector tmp = (g_ll_file_size/SECTOR_SIZE) - p_dbr_temp_tmp->ll_start_sector; memcpy(sz_tmp + 16 + 12, (char *)&tmp, sizeof(__int64)); // dwTotalSector break; } p_dbr_temp_tmp = p_dbr_temp_tmp->p_next; } } memcpy(sz_tmp + 64, sign, 2); InsertRebuildList(rebuild_list, sz_tmp, 66, (p_dbr_temp->ll_start_sector - 1) * SECTOR_SIZE + 446, i++); } if (p_dbr_temp->n_is_org) // 是否起始扇区 { InsertRebuildList(rebuild_list, p_dbr_temp->dbr, SECTOR_SIZE, p_dbr_temp->ll_start_sector * SECTOR_SIZE, i++); } } p_dbr_temp = p_dbr_temp->p_next; } } HandleFile(sz_file_path, rebuild_list); FreeRebuildList(rebuild_list); }
static void HandleDir(char *dirpath, DIR *d, DocTable *doctable, MemIndex *index) { // Loop through the directory. while (1) { char *newfile; int res, charsize; struct stat nextstat; struct dirent *dirent = NULL; // entry is not used. // STEP 1. // Use the "readdir()" system call to read the next directory entry. // (man 3 readdir). If we hit the end of the directory, return back // out of this function. dirent = readdir(d); if (dirent == NULL) return; // STEP 2. // If the directory entry is named "." or "..", ignore it. (Use the C // "continue;" expression to begin the next iteration of the while() // loop.) You can find out the name of the directory entry through the // "d_name" field of the struct dirent returned by readdir(), and you can // use strcmp() to compare it to "." or ".." if ((strcmp(dirent->d_name, ".") == 0) || (strcmp(dirent->d_name, "..") == 0)) continue; // We need to append the name of the file to the name of the directory // we're in to get the full filename. So, we'll malloc space for: // // dirpath + "/" + dirent->d_name + '\0' charsize = strlen(dirpath) + 1 + strlen(dirent->d_name) + 1; newfile = (char *) malloc(charsize); Verify333(newfile != NULL); if (dirpath[strlen(dirpath)-1] == '/') { // no need to add an additional '/' snprintf(newfile, charsize, "%s%s", dirpath, dirent->d_name); } else { // we do need to add an additional '/' snprintf(newfile, charsize, "%s/%s", dirpath, dirent->d_name); } // Use the "stat()" system call to ask the operating system // to give us information about the file named by the // directory entry. ("man stat") res = stat(newfile, &nextstat); if (res == 0) { // STEP 3. // Test to see if the file is a "regular file" using the S_ISREG() macro // described in the stat man page. If so, process the file by invoking // the HandleFile() private helper function. // // On the other hand, if the file turns out to be a directory (which you // can find out using the S_ISDIR() macro described on the same page, // then you need to open the directory using opendir() (man 3 opendir) // and recursively invoke HandleDir to handle it. Be sure to call the // "closedir()" system call when the recursive HandleDir() returns to // close the opened directory. // Case when the file is a regular file. if (S_ISREG(nextstat.st_mode)) HandleFile(newfile, doctable, index); // Case when the file is a directory. if (S_ISDIR(nextstat.st_mode)) { // Open directory. DIR *dir = opendir(newfile); if (dir == NULL) { free(newfile); continue; } // Handle the directory recursively. HandleDir(newfile, dir, doctable, index); // Close the directory. res = closedir(dir); Verify333(res == 0); } } // Done with this file. Fall back up to the next // iteration of the while() loop. free(newfile); } }