bool saveTextureHost( const std::string & filename, const dp::sg::core::TextureHostSharedPtr & tih ) { // load the saver plug-in - this should be configured dp::util::UPIID piid = dp::util::UPIID(dp::util::getFileExtension( filename ).c_str(), dp::util::UPITID(UPITID_TEXTURE_SAVER, UPITID_VERSION) ); dp::util::FileFinder fileFinder( dp::util::getCurrentPath() ); fileFinder.addSearchPath( dp::util::getModulePath() ); bool retval = false; // // MMM - TODO - Update me for stereo images // { dp::util::PlugInSharedPtr plug; if ( getInterface( fileFinder, piid, plug ) ) { TextureSaverSharedPtr ts = std::static_pointer_cast<TextureSaver>(plug); retval = ts->save( tih, filename ); } } // FIXME interface needs to be released since the cleanup order (first dp::sg::core, then dp::util) causes problems upon destruction. dp::util::releaseInterface(piid); return retval; }
bool saveScene( std::string const& filename, dp::sg::ui::ViewStateSharedPtr const& viewState, dp::util::PlugInCallback *callback ) { bool result = false; // define a unique plug-interface ID for SceneLoader const dp::util::UPITID PITID_SCENE_SAVER(UPITID_SCENE_SAVER, UPITID_VERSION); dp::util::FileFinder fileFinder( dp::util::getCurrentPath() ); fileFinder.addSearchPath( dp::util::getModulePath() ); #if defined(DP_OS_WINDOWS) fileFinder.addSearchPath( dp::util::getModulePath( reinterpret_cast<HMODULE>(&__ImageBase) ) ); #endif dp::util::UPIID piid = dp::util::UPIID(dp::util::getFileExtension( filename ).c_str(), PITID_SCENE_SAVER); { dp::util::PlugInSharedPtr plug; if ( getInterface( fileFinder, piid, plug ) ) { SceneSaverSharedPtr ss = std::static_pointer_cast<SceneSaver>(plug); try { dp::sg::core::SceneSharedPtr scene( viewState->getScene() ); // DAR HACK Change SceneSaver interface later. result = ss->save( scene, viewState, filename ); } catch(...) // catch all others { } } } // FIXME interface needs to be released since the cleanup order (first dp::sg::core, then dp::util) causes problems upon destruction. dp::util::releaseInterface(piid); return result; }
static TInt CheckTaskFilesL() { RFs fs; User::LeaveIfError(fs.Connect()); //Get the correct system drive TBuf<32> taskFilePath(KTaskFileScanDir); taskFilePath[0] = RFs::GetSystemDriveChar(); // Search for task files using wildcard file name TFindFile fileFinder(fs); CDir* fileList = NULL; TInt rel = fileFinder.FindWildByDir(KTaskFileWildname, taskFilePath, fileList); // delete file list, we won't use it if (fileList != NULL) delete fileList; // When any task file found left, leave with error code KErrGeneral if (rel == KErrNone) rel = KErrGeneral; // When there's no task file left, return KErrNone if (rel == KErrNotFound) rel = KErrNone; // Leave with KErrGeneral or any other error User::LeaveIfError(rel); return rel; }
TEST_F(FileFinderTest, FileFinderStrict_has_file) { FileFinder::FileFinderStrict fileFinder(mTestDir); ASSERT_TRUE(fileFinder.has(mTestFile)); ASSERT_FALSE(fileFinder.has(mTestFileUppercase)); ASSERT_TRUE(fileFinder.lookup(mTestFile) == std::string(mTestDir + mTestFile)); ASSERT_FALSE(fileFinder.lookup(mTestFileUppercase) == std::string(mTestDir + mTestFile)); }
//************************************************************************ // 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; }
//----------------------------------------------------------------------- FileInfoListPtr UnicodeFileSystemArchive::listFileInfo(bool _recursive, bool _dirs) { // Note that we have to tell the SharedPtr to use OGRE_DELETE_T not OGRE_DELETE by passing category FileInfoListPtr lst(OGRE_NEW_T(FileInfoList, MEMCATEGORY_GENERAL)(), SPFM_DELETE_T); FileFinder fileFinder(this, mWName, getIgnoreHidden()); fileFinder.run(L"*", _recursive, _dirs, nullptr, lst.getPointer()); return lst; }
//----------------------------------------------------------------------- StringVectorPtr UnicodeFileSystemArchive::list(bool _recursive, bool _dirs) { // directory change requires locking due to saved returns // Note that we have to tell the SharedPtr to use OGRE_DELETE_T not OGRE_DELETE by passing category StringVectorPtr lst(OGRE_NEW_T(StringVector, MEMCATEGORY_GENERAL)(), SPFM_DELETE_T); FileFinder fileFinder(this, mWName, getIgnoreHidden()); fileFinder.run(L"*", _recursive, _dirs, lst.getPointer(), nullptr); return lst; }
//----------------------------------------------------------------------- FileInfoListPtr UnicodeFileSystemArchive::findFileInfo(const String& _pattern, bool _recursive, bool _dirs) const { // Note that we have to tell the SharedPtr to use OGRE_DELETE_T not OGRE_DELETE by passing category FileInfoListPtr lst(OGRE_NEW_T(FileInfoList, MEMCATEGORY_GENERAL)(), SPFM_DELETE_T); WString wpattern = toWString(_pattern); FileFinder fileFinder(const_cast<UnicodeFileSystemArchive*>(this), mWName, getIgnoreHidden()); fileFinder.run(wpattern, _recursive, _dirs, nullptr, lst.getPointer()); return lst; }
//************************************************************************ // 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; }
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; }
static bool initialize() { // the search path for loader DLLs #if defined(_WIN32) std::string appPath = dp::util::getModulePath( GetModuleHandle( NULL ) ); #elif defined(LINUX) std::string appPath = dp::util::getModulePath(); #endif // TextureHost::createFromFile() relies on this to be set correctly! dp::util::addPlugInSearchPath( appPath ); // load standard effects required for the scenegraph bool success = true; dp::util::FileFinder fileFinder( dp::home() + "/media/dpfx" ); success &= dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/standard_lights.xml", fileFinder ); success &= dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/standard_material.xml", fileFinder ); success &= dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/collada.xml", fileFinder ); DP_ASSERT(success && "EffectLibrary::loadLibrary failed."); return success; }
int main(int argc, char * argv[]) { //char path[] = NULL; //if (strcmp(argv[1], "-name") == 0 || strcmp(argv[1], "-user") == 0 || strcmp(argv[1], "-type") == 0) { //printf("erfolgreich"); fileFinder("/home/ic15b081/", "bla.c"); //} //else if (strcmp(argv[1], path) == 0) { // if (strcmp(argv[2], "-name") == 0 || strcmp(argv[2], "-user") == 0 || strcmp(argv[2], "-type") == 0) { // } //else //error_1(); getchar(); return 0; } // End of Main
void AutoMounter::UpdateState() { MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); // If the following preconditions are met: // - UMS is available (i.e. compiled into the kernel) // - UMS is enabled // - AutoMounter is enabled // - USB cable is plugged in // then we will try to unmount and share // otherwise we will try to unshare and mount. if (VolumeManager::State() != VolumeManager::VOLUMES_READY) { // The volume manager isn't in a ready state, so there // isn't anything else that we can do. LOG("UpdateState: VolumeManager not ready yet"); return; } if (mResponseCallback->IsPending()) { // We only deal with one outstanding volume command at a time, // so we need to wait for it to finish. return; } bool umsAvail = false; bool umsEnabled = false; if (access(ICS_SYS_USB_FUNCTIONS, F_OK) == 0) { umsAvail = (access(ICS_SYS_UMS_DIRECTORY, F_OK) == 0); if (umsAvail) { char functionsStr[60]; if (ReadSysFile(ICS_SYS_USB_FUNCTIONS, functionsStr, sizeof(functionsStr))) { umsEnabled = strstr(functionsStr, "mass_storage") != NULL; } else { ERR("Error reading file '%s': %s", ICS_SYS_USB_FUNCTIONS, strerror(errno)); umsEnabled = false; } } else { umsEnabled = false; } } else { umsAvail = ReadSysFile(GB_SYS_UMS_ENABLE, &umsEnabled); } bool usbCablePluggedIn = IsUsbCablePluggedIn(); bool enabled = (mMode == AUTOMOUNTER_ENABLE); if (mMode == AUTOMOUNTER_DISABLE_WHEN_UNPLUGGED) { enabled = usbCablePluggedIn; if (!usbCablePluggedIn) { mMode = AUTOMOUNTER_DISABLE; } } bool tryToShare = (umsAvail && umsEnabled && enabled && usbCablePluggedIn); LOG("UpdateState: umsAvail:%d umsEnabled:%d mode:%d usbCablePluggedIn:%d tryToShare:%d", umsAvail, umsEnabled, mMode, usbCablePluggedIn, tryToShare); VolumeArray::index_type volIndex; VolumeArray::size_type numVolumes = VolumeManager::NumVolumes(); for (volIndex = 0; volIndex < numVolumes; volIndex++) { RefPtr<Volume> vol = VolumeManager::GetVolume(volIndex); Volume::STATE volState = vol->State(); if (vol->State() == nsIVolume::STATE_MOUNTED) { LOG("UpdateState: Volume %s is %s and %s @ %s gen %d locked %d sharing %c", vol->NameStr(), vol->StateStr(), vol->MediaPresent() ? "inserted" : "missing", vol->MountPoint().get(), vol->MountGeneration(), (int)vol->IsMountLocked(), vol->CanBeShared() ? (vol->IsSharingEnabled() ? 'y' : 'n') : 'x'); } else { LOG("UpdateState: Volume %s is %s and %s", vol->NameStr(), vol->StateStr(), vol->MediaPresent() ? "inserted" : "missing"); } if (!vol->MediaPresent()) { // No media - nothing we can do continue; } if (tryToShare && vol->IsSharingEnabled()) { // We're going to try to unmount and share the volumes switch (volState) { case nsIVolume::STATE_MOUNTED: { if (vol->IsMountLocked()) { // The volume is currently locked, so leave it in the mounted // state. LOGW("UpdateState: Mounted volume %s is locked, not sharing", vol->NameStr()); break; } // Check to see if there are any open files on the volume and // don't initiate the unmount while there are open files. OpenFileFinder::Info fileInfo; OpenFileFinder fileFinder(vol->MountPoint()); if (fileFinder.First(&fileInfo)) { LOGW("The following files are open under '%s'", vol->MountPoint().get()); do { LOGW(" PID: %d file: '%s' app: '%s' comm: '%s' exe: '%s'\n", fileInfo.mPid, fileInfo.mFileName.get(), fileInfo.mAppName.get(), fileInfo.mComm.get(), fileInfo.mExe.get()); } while (fileFinder.Next(&fileInfo)); LOGW("UpdateState: Mounted volume %s has open files, not sharing", vol->NameStr()); // Check again in 5 seconds to see if the files are closed. Since // we're trying to share the volume, this implies that we're // plugged into the PC via USB and this in turn implies that the // battery is charging, so we don't need to be too concerned about // wasting battery here. MessageLoopForIO::current()-> PostDelayedTask(FROM_HERE, NewRunnableMethod(this, &AutoMounter::UpdateState), 5000); break; } // Volume is mounted, we need to unmount before // we can share. LOG("UpdateState: Unmounting %s", vol->NameStr()); vol->StartUnmount(mResponseCallback); return; // UpdateState will be called again when the Unmount command completes } case nsIVolume::STATE_IDLE: { // Volume is unmounted. We can go ahead and share. LOG("UpdateState: Sharing %s", vol->NameStr()); vol->StartShare(mResponseCallback); return; // UpdateState will be called again when the Share command completes } default: { // Not in a state that we can do anything about. break; } } } else { // We're going to try and unshare and remount the volumes switch (volState) { case nsIVolume::STATE_SHARED: { // Volume is shared. We can go ahead and unshare. LOG("UpdateState: Unsharing %s", vol->NameStr()); vol->StartUnshare(mResponseCallback); return; // UpdateState will be called again when the Unshare command completes } case nsIVolume::STATE_IDLE: { // Volume is unmounted, try to mount. LOG("UpdateState: Mounting %s", vol->NameStr()); vol->StartMount(mResponseCallback); return; // UpdateState will be called again when Mount command completes } default: { // Not in a state that we can do anything about. break; } } } } }
TEST_F(FileFinderTest, FileFinderStrict_does_not_have_file) { FileFinder::FileFinderStrict fileFinder(mTestDir); ASSERT_FALSE(fileFinder.has(mTestFileNotFound)); ASSERT_TRUE(fileFinder.lookup(mTestFileNotFound).empty()); }
int fileFinder(char *dir,char inputname[]) { struct dirent *entry; DIR *dirpointer; struct stat fileInfo; if (((dirpointer = opendir(dir)) == NULL) && (errno != 0)) { switch (errno) { case 1: printf("Operation not permitted \n"); break; case 2: printf("No such file or directory\n"); break; case 3: printf("No such process\n"); break; case 4: printf("Interrupted function call\n"); break; case 5: printf("Input/output error\n"); break; case 6: printf("No such device or address\n"); break; case 7: printf("Argument list too long\n"); break; case 8: printf("Exec format error\n"); break; case 9: printf("Bad file descriptor\n"); break; case 10: printf("No child processes\n"); break; case 11: printf("Resource temporarily unavailable\n"); break; case 12: printf("Not enough space\n"); break; case 13: printf("Permission denied\n"); break; case 14: printf("Bad address\n"); break; case 16: printf("Device or resource busy\n"); break; case 17: printf("File exists\n"); break; case 18: printf("Improper link\n"); break; case 19: printf("No such device\n"); break; case 20: printf("Not a directory\n"); break; case 21: printf("Is a directory\n"); break; case 23: printf("Too many open files in system\n"); break; case 24: printf("Too many open files\n"); break; case 25: printf("Inappropriate I/O control operation\n"); break; case 27: printf("File too large\n"); break; case 28: printf("No space left on device\n"); break; case 29: printf("Invalid seek\n"); break; case 30: printf("Read-only filesystem\n"); break; case 31: printf("Too many links\n"); break; case 32: printf("Broken pipe\n"); break; case 33: printf("Mathematics argument out of domain of function\n"); break; case 36: printf("Resource deadlock avoided\n"); break; case 38: printf("Filename too long\n"); break; case 39: printf("No locks available\n"); break; case 40: printf("Function not implemented\n"); break; case 41: printf("Directory not empty\n"); break; default: printf("Unknown Error\n"); break; } return -1; // fprintf(stderr, "Dir cannot open: %s\n", dir); // return; } else chdir(dir); while ((entry = readdir(dirpointer)) != NULL) { lstat(entry->d_name, &fileInfo); if (S_ISDIR(fileInfo.st_mode) == 1) // Wenn Verzeichnis dann oeffnen { if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0) continue; fileFinder(entry->d_name, inputname); } if(strcmp(inputname, entry->d_name) == 0) { printf(" %s/%s \n", get_current_dir_name(), inputname); if (0 /*Eingabe -ls*/) { fprintf("%zu ", fileInfo.st_ino); fprintf("%zu ", fileInfo.st_blksize); fprintf("%zu ", fileInfo.st_mode); fprintf("%zu ", fileInfo.st_nlink); fprintf("%zu ", fileInfo.st_uid); fprintf("%zu ", fileInfo.st_gid); fprintf("%zu ", fileInfo.st_mtime); fprintf("%zu ", fileInfo.st_dev); } } } chdir(".."); closedir(dirpointer); return 0; }