void ComicStripFileResource::checkCreateStructure() { QDir dir = QDir(dirPath()); if (!dir.exists()) dir.mkpath(dirPath()); }
void CustomFileDialog::bookmarkChosen(int i) { if(i == clearId) { bookmarkList.clear(); bookmarkMenu->clear(); addId = bookmarkMenu->insertItem("Add bookmark"); clearId = bookmarkMenu->insertItem("Clear bookmarks"); bookmarkMenu->insertSeparator(); return; } if(i == addId) { bookmarkList << dirPath(); const char *book_pix[] = {"12 16 3 1", ". c None", "a c #000000", "# c #008080", "............", "............", "........##..", ".......#####", "......#####a", ".....#####a.", "....#####a..", "...#####a...", "..#####a....", ".#####a.....", "aaa##a......", "...#a.......", "...a........", "............", "............", "............"}; bookmarkMenu->insertItem(QIconSet(book_pix), dirPath()); return; } setDir(bookmarkMenu->text(i)); }
bool Process::getLocalSaveDirectory() { QDir dir(m_jobInfo->get(JobInfo::LocalWorkingDirectory)); dir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); while (1) { QString dirName(dir.dirName()); dir.cdUp(); QString dirPath(dir.path()); qDebug() << "LocalServer::getSaveDirectory() dirPath: " << dirPath; qDebug() << "LocalServer::getSaveDirectory() dirName: " << dirName; QFileDialog dialog(0, "Save As", dirPath); dialog.selectFile(dirName); dialog.setOption(QFileDialog::ShowDirsOnly, true); // dialog.setFileMode(QFileDialog::DirectoryOnly); dialog.setFileMode(QFileDialog::Directory); if (dialog.exec() == QDialog::Rejected) return false; QStringList list(dialog.selectedFiles()); if (list.isEmpty()) return false; dir.setPath(list.first()); if (dir.path().isEmpty()) return false; if (dir.dirName().contains(" ")) { QMsgBox::warning(0, "IQmol", "Directory name cannot contain spaces"); }else { if (dir.count() == 0) break; QString msg("Directory "); msg += dir.dirName() + " exists, overwrite?"; if (QMsgBox::question(0, "IQmol", msg, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { break; } } } QString dirPath(dir.path()); while (dirPath.endsWith("/")) { dirPath.chop(1); } m_jobInfo->set(JobInfo::LocalWorkingDirectory, dirPath); QFileInfo info(dir, m_jobInfo->get(JobInfo::InputFileName)); Preferences::LastFileAccessed(info.filePath()); return true; }
//------------------------------------------------------------------------------------------------- inline bool_t Dir::isExists() const { xCHECK_RET(dirPath().empty(), false); FileType type(dirPath()); xCHECK_RET(type.get() == FileType::faInvalid, false); bool_t bRv = type.isExists(FileType::faDirectory); xCHECK_RET(!bRv, false); return true; }
Path Path::parent() const { QString dp( dirPath() ); if( dp != mPath ) return dp; return dp.section("/", 0, -3) + "/"; }
KexiStartupFileDialogBase::KexiStartupFileDialogBase( const QString & dirName, const QString & filter, QWidget * parent, const char * name, bool modal) : Q3FileDialog(realStartDir(dirName), filter, parent, name, modal) , d(new KexiStartupFileDialogBasePrivate()) { // QString _dirName = dirName; QString _dirName = dirPath(); //make default 'My Documents' folder //TODO: store changes in the app's config file? if (_dirName.isEmpty()) _dirName = KGlobalSettings::documentPath(); init(_dirName, filter, parent); //find "OK" button QObjectList *l = queryList("QPushButton", "OK", false); m_okBtn = dynamic_cast<QPushButton*>(l->first()); delete l; l = queryList("QLineEdit", "name/filter editor", false); m_lineEdit = dynamic_cast<QLineEdit*>(l->first()); delete l; adjustSize(); }
std::string DataDirsAccess::LocateDir(std::string _dir, int flags) const { if (!FileSystem::CheckFile(_dir)) { return ""; } // if it's an absolute path, don't look for it in the data directories if (FileSystem::IsAbsolutePath(_dir)) { return _dir; } std::string dir = _dir; FileSystem::FixSlashes(dir); if (flags & FileQueryFlags::WRITE) { std::string writeableDir = dataDirLocater.GetWriteDirPath() + dir; FileSystem::FixSlashes(writeableDir); if (flags & FileQueryFlags::CREATE_DIRS) { FileSystem::CreateDirectory(writeableDir); } return writeableDir; } else { const std::vector<std::string>& datadirs = dataDirLocater.GetDataDirPaths(); std::vector<std::string>::const_iterator dd; for (dd = datadirs.begin(); dd != datadirs.end(); ++dd) { std::string dirPath((*dd) + dir); if (FileSystem::DirExists(dirPath)) { return dirPath; } } return dir; } }
void ImageProcessDialog::on_butAddtoInputFileNames_clicked() { QString path = ImageProcess::getDataSetPath(); if(path == NULL) return; QDir dirPath(path); dirPath.setFilter(QDir::NoDotAndDotDot | QDir::Files); QFileDialog dialog(this); dialog.setDirectory(dirPath); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setOption(QFileDialog::DontUseNativeDialog, true); dialog.setNameFilter(tr("Images(*.ppm *.png *.jpeg *.jpg)")); QStringList fileNames; if(this->imageFileNames.size() > 0) this->imageFileNames.clear(); if (dialog.exec()) this->imageFileNames = dialog.selectedFiles(); QAbstractItemModel* mod = new QStringListModel(this->imageFileNames); ui->listViewInputFileNames->setModel(mod); }
void ImageProcessDialog::on_butAddtoFilterNames_clicked() { QString path = ImageProcess::getDataSetPath(); if(path == NULL) return; QString fileName = ui->lEditCloudFileName->text(); QDir dirPath(path); dirPath.setFilter(QDir::NoDotAndDotDot | QDir::Files); //dirPath.setNameFilters(); QFileDialog dialog(this); dialog.setDirectory(dirPath); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setNameFilter("All filter files (*.txt)"); if (dialog.exec()) this->filters = dialog.selectedFiles(); QAbstractItemModel* mod = new QStringListModel(this->filters); ui->listViewVisFilterNames->setModel(mod); }
void addPath( const std::string& path ) { StringTokenizer st( path, PATH_SEPARATORS ); while( st.nextToken() ) { std::string dirPath( st.getToken() ); if( dirPath.empty() ) continue; // normalize & absolutize the path OS::makeAbs( dirPath ); if( !OS::isDir( dirPath ) ) { CORAL_LOG(WARNING) << "cannot add '" << dirPath << "' to the Coral path (not a dir)"; continue; } /* Check whether the dir is not in the CORAL_PATH already. This makes addPath() quadratic (what should never be a problem). */ if( std::find( sg_paths.begin(), sg_paths.end(), dirPath ) == sg_paths.end() ) sg_paths.push_back( dirPath ); } }
static WatchedFile* NewWatchedFile(const WCHAR* filePath, const std::function<void()>& onFileChangedCb) { bool isManualCheck = PathIsNetworkPath(filePath); AutoFreeW dirPath(path::GetDir(filePath)); WatchedDir* wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile* wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->onFileChangedCb = onFileChangedCb; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer) { bool isManualCheck = PathIsNetworkPath(filePath); ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile *wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->observer = observer; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
void ResourcesBrowser::showFilesystemBrowserPopupMenu( QTreeWidgetItem* node, QMenu& menu ) { // create additional save actions providing the item we clicked is a directory FSDirNode* dirNode = dynamic_cast< FSDirNode* >( node ); if ( dirNode ) { menu.addSeparator(); QAction* addBookmarkAction = new AddBookmarkAction( QIcon( m_iconsDir + "addBookmark.png" ), "Add bookmark", this, FilePath( dirNode->getRelativePath() ), *this ); menu.addAction( addBookmarkAction ); if ( m_activeProject != NULL ) { menu.addSeparator(); // if there's an active project, we might want to add or remove directories to/from it FilePath dirPath( dirNode->getRelativePath() ); bool isMember = m_activeProject->isMember( dirPath ); if ( !isMember ) { QAction* addProjectDir = new ManageProjectDirAction( QIcon( m_iconsDir + "addProjectDir.png" ), "Add to project", this, m_activeProject, dirPath, true ); menu.addAction( addProjectDir ); } } } }
void ProDef::write(const std::string &path, const std::string &ns, uint32_t tabCount) const { std::string dirPath(path); if (!dirPath.empty()) { if (path.find_last_of('/') != (path.size() - 1)) // no '/' at end dirPath += '/'; } // volatile part std::string volatileFilePath(dirPath); volatileFilePath += m_name; FILE *volatileFile = fopen(volatileFilePath.c_str(), "w+"); assert(NULL != volatileFile); writeVolatile(volatileFile, tabCount); fclose(volatileFile); // steady part std::string steadyFilePath(dirPath); steadyFilePath += m_name + ".h"; if (access(steadyFilePath.c_str(), F_OK) != 0) { FILE *steadyFile = fopen(steadyFilePath.c_str(), "w+"); assert(NULL != steadyFile); writeSteady(steadyFile, ns, 0); } }
static UString findSubDirectory_internal(const UString &directory, const UString &subDirectory, bool caseInsensitive) { try { path dirPath(directory.c_str()); path subDirPath(subDirectory.c_str()); // Iterator over the directory's contents directory_iterator itEnd; for (directory_iterator itDir(dirPath); itDir != itEnd; ++itDir) { if (is_directory(itDir->status())) { // It's a directory. Check if it's the one we're looking for if (caseInsensitive) { if (iequals(itDir->path().filename(), subDirectory.c_str())) return itDir->path().string(); } else { if (equals(itDir->path().filename(), subDirectory.c_str())) return itDir->path().string(); } } } } catch (...) { } return ""; }
static WatchedDir *GetOrFindDirForFile(const WCHAR *filePath) { ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = FindExistingWatchedDir(dirPath); if (!wd) wd = NewWatchedDir(dirPath); return wd; }
//------------------------------------------------------------------------------------------------- inline bool_t Dir::isDir() const { bool_t bRv = FileType( dirPath() ).isExists(FileType::faDirectory); xCHECK_RET(!bRv, false); return true; }
std::string FileFinder::findRecursive( std::string const& file ) const { boost::filesystem::path filePath( file ); if ( boost::filesystem::is_regular_file( filePath ) ) { return( filePath.string() ); } while ( !filePath.empty() ) { if ( !m_latestHit.empty() ) { boost::filesystem::path dirPath( m_latestHit ); dirPath /= filePath.filename(); if ( boost::filesystem::is_regular_file( dirPath ) ) { return( dirPath.string() ); } } for ( std::vector<boost::filesystem::path>::const_iterator pit = m_searchPaths.begin() ; pit != m_searchPaths.end() ; ++pit ) { DP_ASSERT( boost::filesystem::exists( *pit ) ); boost::filesystem::path dirPath( *pit ); dirPath /= filePath; if ( boost::filesystem::is_regular_file( dirPath ) ) { m_latestHit = *pit; return( dirPath.string() ); } for ( boost::filesystem::recursive_directory_iterator it( *pit ) ; it != boost::filesystem::recursive_directory_iterator() ; ++it ) { dirPath = it->path(); // checking is_regular_file only if is_directory(*pit) is substantially slower !! dirPath /= filePath; if ( boost::filesystem::is_regular_file( dirPath ) ) { m_latestHit = it->path(); return( dirPath.string() ); } } } chopOffFirstElement( filePath ); } return( "" ); }
/* * Search the plugins directory for a plugin that supports the scheme * specified by uuid * * If found: * mLibrary holds a strong pointer to the dlopen'd library * mFactory is set to the library's factory method * mInitCheck is set to OK * * If not found: * mLibrary is cleared and mFactory are set to NULL * mInitCheck is set to an error (!OK) */ void Crypto::findFactoryForScheme(const uint8_t uuid[16]) { closeFactory(); // lock static maps Mutex::Autolock autoLock(mMapLock); // first check cache Vector<uint8_t> uuidVector; uuidVector.appendArray(uuid, sizeof(uuid)); ssize_t index = mUUIDToLibraryPathMap.indexOfKey(uuidVector); if (index >= 0) { if (loadLibraryForScheme(mUUIDToLibraryPathMap[index], uuid)) { mInitCheck = OK; return; } else { ALOGE("Failed to load from cached library path!"); mInitCheck = ERROR_UNSUPPORTED; return; } } // no luck, have to search String8 dirPath("/vendor/lib/mediadrm"); String8 pluginPath; DIR* pDir = opendir(dirPath.string()); if (pDir) { struct dirent* pEntry; while ((pEntry = readdir(pDir))) { pluginPath = dirPath + "/" + pEntry->d_name; if (pluginPath.getPathExtension() == ".so") { if (loadLibraryForScheme(pluginPath, uuid)) { mUUIDToLibraryPathMap.add(uuidVector, pluginPath); mInitCheck = OK; closedir(pDir); return; } } } closedir(pDir); } // try the legacy libdrmdecrypt.so pluginPath = "libdrmdecrypt.so"; if (loadLibraryForScheme(pluginPath, uuid)) { mUUIDToLibraryPathMap.add(uuidVector, pluginPath); mInitCheck = OK; return; } mInitCheck = ERROR_UNSUPPORTED; }
void PoorManWindow::SetDirLabel(const char* name) { BString dirPath(B_TRANSLATE("Directory: ")); dirPath.Append(name); if (Lock()) { fDirView->SetText(dirPath.String()); Unlock(); } }
HANDLE _CreateDirectoryAndFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpsa, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile ) { HANDLE hFile = ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, lpsa, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile ); if( hFile == INVALID_HANDLE_VALUE ){ const TCHAR* p = _tcsrchr(lpFileName, _T('\\')); if( p != NULL ){ vector<TCHAR> dirPath(lpFileName, p + 1); dirPath.back() = _T('\0'); _CreateDirectory(&dirPath.front()); hFile = ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, lpsa, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile ); } } return hFile; }
//------------------------------------------------------------------------------------------------- inline void_t Dir::pathCreate() const { std::vec_tstring_t pathParts; std::tstring_t buildPath; // split dirPath into parts String::split( Path(dirPath()).toNative(false), Const::slash(), &pathParts ); // create dirs by steps xFOREACH_CONST(std::vec_tstring_t, it, pathParts) { buildPath.append(*it).append(Const::slash()); Dir(buildPath).create(); }
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer) { ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = FindExistingWatchedDir(dirPath); if (!wd) wd = NewWatchedDir(dirPath); WatchedFile *wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->watchedDir = wd; wf->observer = observer; wf->token = g_currentToken++; wf->next = g_firstFile; g_firstFile = wf; return wf; }
void DialogObjectEdit::fillObjectGraphicsList() { QString dirPath(QString(EDITOR_FILEPATH)+"/data/images/sprites/objects/"); QDir *dir = new QDir(dirPath); dir->setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot); dir->setSorting(QDir::Size | QDir::Reversed); QFileInfoList list = dir->entryInfoList(); //qDebug (QString (">> fillObjectGraphicsList - dir: " + dirPath + ", list.size: " + QString::number(list.size ())).toAscii()); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); if (i == 0) { sprintf(dataExchanger->addNpcFilename, "%s/data/images/sprites/objects/%s", EDITOR_FILEPATH, qPrintable(fileInfo.fileName())); } ui->objectListCombobox->addItem(fileInfo.fileName()); } ui->npcPreviewAreaWidget->repaint(); }
bool FilePath::getSubDirectories(const UString &directory, std::list<UString> &subDirectories) { path dirPath(directory.c_str()); try { // Iterate over the directory's contents directory_iterator itEnd; for (directory_iterator itDir(dirPath); itDir != itEnd; ++itDir) { if (is_directory(itDir->status())) { subDirectories.push_back(itDir->path().generic_string()); } } } catch (...) { return false; } return true; }
void Wc::ensureAdm(const char * dir, const char *uuid, const char * url, const Revision & revision) { Pool pool; Path dirPath(dir); Path urlPath(url); svn_error_t * error = svn_wc_ensure_adm(dirPath.c_str(), // path uuid, // UUID urlPath.c_str(), // url revision.revnum(), // revision pool); if (error != NULL) throw ClientException(error); }
void ResourcesBrowser::showProjectBrowserPopupMenu( QTreeWidgetItem* node, QMenu& menu ) { ResourcesManager& resMgr = ResourcesManager::getInstance(); // create additional save actions, providing the item we clicked // is a loaded resource ProjectLeafNode* nodeItem = dynamic_cast< ProjectLeafNode* >( node ); if ( nodeItem ) { Resource* resource = resMgr.findResource( nodeItem->getRelativePath() ); if ( resource != NULL ) { menu.addSeparator(); QAction* saveNodeAction = new SaveResourceAction( QIcon( m_iconsDir + "saveFile.png" ), "Save", this, *resource, false ); menu.addAction( saveNodeAction ); QAction* saveHierarchyAction = new SaveResourceAction( QIcon( m_iconsDir + "saveFile.png" ), "Save All", this, *resource, true ); menu.addAction( saveHierarchyAction ); } } // create additional save actions providing the item we clicked // is a directory ProjectDirNode* dirNode = dynamic_cast< ProjectDirNode* >( node ); if ( dirNode ) { menu.addSeparator(); QAction* addBookmarkAction = new AddBookmarkAction( QIcon( m_iconsDir + "addBookmark.png" ), "Add bookmark", this, FilePath( dirNode->getRelativePath() ), *this ); menu.addAction( addBookmarkAction ); if ( m_activeProject != NULL ) { menu.addSeparator(); // we might also want ot remove directories from a project FilePath dirPath( dirNode->getRelativePath() ); QAction* removeProjectDir = new ManageProjectDirAction( QIcon( m_iconsDir + "removeProjectDir.png" ), "Remove from project", this, m_activeProject, dirPath, false ); menu.addAction( removeProjectDir ); } } }
// returns the path's parent Path Path::parent() const { std::string opPathRep; if (!fileName().empty()) opPathRep = dirPath().pathRep; else opPathRep = pathRep; uint lastSepIdx = opPathRep.rfind(PLATFORM_SEPARATOR); if (lastSepIdx == std::string::npos) { return *this; } else { return Path(opPathRep.substr(0, lastSepIdx)); } }
bool CollectPathsFromDirectory(const TCHAR *pattern, StrVec& paths, bool dirsInsteadOfFiles) { ScopedMem<TCHAR> dirPath(path::GetDir(pattern)); WIN32_FIND_DATA fdata; HANDLE hfind = FindFirstFile(pattern, &fdata); if (INVALID_HANDLE_VALUE == hfind) return false; do { bool append = !dirsInsteadOfFiles; if ((fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) append = dirsInsteadOfFiles && !IsSpecialDir(fdata.cFileName); if (append) paths.Append(path::Join(dirPath, fdata.cFileName)); } while (FindNextFile(hfind, &fdata)); FindClose(hfind); return paths.Count() > 0; }
void C批量文本替换Dlg::OnBnClickedButton4() { // TODO: 在此添加控件通知处理程序代码 UpdateData(); if( !载入替换表() )return; CWQSG_DirDlg dlg( m_hWnd ); WCHAR path[ MAX_PATH * 2 ]; if( !dlg.GetPath( path ) ) return; CString dirPath( path ); 替换目录( path ); if( m_完成数量 > 0 ) { CString str; str.Format( L"已经替换 %u 个文件" , m_完成数量 ); MessageBox( str ); } }