void GuiFilesystemList::refresh() { // Clear old widgets clear(); buttonPathMap.clear(); highlightedElement = NULL; // Add a slight background background = new GuiColorRect(0, 0, width, height); background->set_rgba(0, 0, 0, 0.0); add(background); GLfloat padding = 5; GLfloat runningY = height/2-padding; // Iterate over directory fs::directory_iterator endOfDirectory; for(fs::directory_iterator dirIter(directory); dirIter != endOfDirectory; dirIter++) { fs::path fullPath = dirIter->path(); std::string pathString = fullPath.string(); if (pathString.substr(pathString.length()-extension.length(),extension.length()) == extension) { Log::message("GuiFilesystemList","Appending \"%s\"",pathString.c_str(),Log::DEBUG); GuiFlatButton *fileButton = new GuiFlatButton(fs::basename(fullPath) + fs::extension(fullPath), 0, 0); buttonPathMap[fileButton] = fullPath; add(fileButton); fileButton->set_width(width); fileButton->set_y(runningY - fileButton->get_height()/2); runningY -= fileButton->get_height() + padding; } else { Log::message("GuiFilesystemList","Ignoring \"%s\"",pathString.c_str(),Log::DEBUG); } } }
static void load_directory_fonts(const SkTypeface_FreeType::Scanner& scanner, const SkString& directory, const char* suffix, SkFontMgr_Custom::Families* families) { SkOSFile::Iter iter(directory.c_str(), suffix); SkString name; while (iter.next(&name, false)) { SkString filename(SkOSPath::Join(directory.c_str(), name.c_str())); SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(filename.c_str())); if (!stream.get()) { SkDebugf("---- failed to open <%s>\n", filename.c_str()); continue; } int numFaces; if (!scanner.recognizedFont(stream, &numFaces)) { SkDebugf("---- failed to open <%s> as a font\n", filename.c_str()); continue; } for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { bool isFixedPitch; SkString realname; SkFontStyle style = SkFontStyle(); // avoid uninitialized warning if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch, NULL)) { SkDebugf("---- failed to open <%s> <%d> as a font\n", filename.c_str(), faceIndex); continue; } SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( style, isFixedPitch, true, // system-font (cannot delete) realname, filename.c_str(), faceIndex)); SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str()); if (NULL == addTo) { addTo = new SkFontStyleSet_Custom(realname); families->push_back().reset(addTo); } addTo->appendTypeface(tf); } } SkOSFile::Iter dirIter(directory.c_str()); while (dirIter.next(&name, true)) { if (name.startsWith(".")) { continue; } SkString dirname(SkOSPath::Join(directory.c_str(), name.c_str())); load_directory_fonts(scanner, dirname, suffix, families); } }
INT32 dpsArchiveFileMgr::getTotalSize( INT64& totalSize ) { INT32 rc = SDB_OK ; INT64 size = 0 ; try { fs::path dir ( _archivePath ) ; fs::directory_iterator endIter ; for ( fs::directory_iterator dirIter( dir ) ; dirIter != endIter ; ++dirIter ) { INT64 fileSize = 0 ; const string filePath = dirIter->path().string() ; rc = ossFile::getFileSize( filePath, fileSize ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Failed to get file[%s] size, rc=%d", filePath.c_str(), rc ) ; goto error ; } size += fileSize ; } totalSize = size ; } catch( fs::filesystem_error& e ) { if ( e.code() == boost::system::errc::permission_denied || e.code() == boost::system::errc::operation_not_permitted ) { rc = SDB_PERM ; } else { rc = SDB_IO ; } goto error ; } catch( std::exception& e ) { PD_LOG( PDERROR, "unexpected exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
void ResultProcessor::getDirectoryPaths(const std::string & directory, std::vector<std::string> & dirPaths) { fs::directory_iterator end; fs::directory_iterator dirIter(directory); if (dirIter == end) throw std::runtime_error("given argument is not a path to existing directory: " + directory); //Saves all paths to directories except . and .. for (; dirIter != end; dirIter++){ if (dirIter.is_directory() && dirIter.name().compare(".") != 0 && dirIter.name().compare("..") != 0) { dirPaths.push_back(dirIter.path()); } } sortStrings(dirPaths); }
RepositoryParser::Packages RepositoryParser::getPackages() const { Packages packages; QDirIterator dirIter(m_Dir); while(dirIter.hasNext()) { dirIter.next(); QDebug(QtDebugMsg) << dirIter.filePath(); QDebug(QtDebugMsg) << dirIter.fileName(); packages.unite(getPackages(dirIter.fileName())); } return packages; }
QStringList ProgramFinder::lookupExecutables(const QString& startingDirectory, bool shouldRecurse) { // for some reason, QFileInfo and friends don't like directory paths // that don't end with a separator QString lookupDirectory = startingDirectory; if ( !lookupDirectory.endsWith(QDir::separator()) ) lookupDirectory.append(QDir::separator()); // skip out early if our path is not a directory const QFileInfo fi(lookupDirectory); if ( !fi.exists() || !fi.isDir() ) return QStringList(); QDir dir = fi.dir(); dir.setFilter(QDir::Files | QDir::Executable); QStringList executableFilenames; // if we should recurse through all subdirectories if ( shouldRecurse ) { QDirIterator dirIter(dir, QDirIterator::Subdirectories); while ( dirIter.hasNext() ) { dirIter.next(); const QFileInfo exe = dirIter.fileInfo(); executableFilenames.append( exe.canonicalFilePath() ); } } // otherwise, look in top level only else { const QFileInfoList exes = dir.entryInfoList(); foreach ( const QFileInfo& exe, exes ) executableFilenames.append( exe.canonicalFilePath() ); } // remove all duplicates executableFilenames.removeDuplicates(); // attempt to remove libraries // these are picked up as 'executable' by directory scan, but we can eliminate common lib types QStringList result; foreach ( const QString& exeFn, executableFilenames ) { if ( !isProbablyLibrary(exeFn) ) result.append(exeFn); } // return our resulting filepaths return result; }
void ResultProcessor::getFilePaths(const std::string & directory , std::vector<std::string> & paths , int fileIndex) { fs::directory_iterator end; fs::directory_iterator dirIter(directory); if(dirIter == end) throw std::runtime_error("given argument is not a path to existing directory: " + directory); for(; dirIter != end ; dirIter++) { if(dirIter.is_directory() && dirIter.name().compare(".") != 0 && dirIter.name().compare("..") != 0) { getFilePaths(dirIter.path() , paths , fileIndex); } if(dirIter.is_file() && Utils::getFileIndex(dirIter.name()) == fileIndex) { paths.push_back(dirIter.path()); } } }
static void load_directory_fonts(const SkString& directory, unsigned int* count) { SkOSFile::Iter iter(directory.c_str(), ".ttf"); SkString name; while (iter.next(&name, false)) { SkString filename(directory); filename.append(name); bool isFixedWidth; SkString realname; SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialized warning if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixedWidth)) { SkDebugf("------ can't load <%s> as a font\n", filename.c_str()); continue; } FamilyRec* family = find_familyrec(realname.c_str()); if (family && family->fFaces[style]) { continue; } // this constructor puts us into the global gFamilyHead llist FamilyTypeface* tf = SkNEW_ARGS(FileTypeface, (style, true, // system-font (cannot delete) family, // what family to join filename.c_str(), isFixedWidth) // filename ); if (NULL == family) { add_name(realname.c_str(), tf->getFamily()); } *count += 1; } SkOSFile::Iter dirIter(directory.c_str()); while (dirIter.next(&name, true)) { if (name.startsWith(".")) { continue; } SkString dirname(directory); dirname.append(name); dirname.append(SK_FONT_FILE_DIR_SEPERATOR); load_directory_fonts(dirname, count); } }
MultiDirCollection::MultiDirCollection(const Files::PathContainer& directories, const std::string& extension, bool foldCase) : mFiles (NameLess (!foldCase)) { NameEqual equal (!foldCase); for (PathContainer::const_iterator iter = directories.begin(); iter!=directories.end(); ++iter) { if (!boost::filesystem::is_directory(*iter)) { std::cout << "Skipping invalid directory: " << (*iter).string() << std::endl; continue; } for (boost::filesystem::directory_iterator dirIter(*iter); dirIter != boost::filesystem::directory_iterator(); ++dirIter) { boost::filesystem::path path = *dirIter; if (!equal (extension, path.extension().string())) continue; std::string filename = path.filename().string(); TIter result = mFiles.find (filename); if (result==mFiles.end()) { mFiles.insert (std::make_pair (filename, path)); } else if (result->first==filename) { mFiles[filename] = path; } else { // handle case folding mFiles.erase (result->first); mFiles.insert (std::make_pair (filename, path)); } } } }
static JSBool filesystem_ls(JSContext* cx, uintN argc, jsval* vp) { JSString* pathStr; if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &pathStr)) { JS_ReportError(cx, "filesystem_ls: failure to parse path arg"); return JS_FALSE; } int numberOfEntries = 1; char* pathCharArr = JS_EncodeString(cx, pathStr); printf("Provided path: %s\n", pathCharArr); fs::path path(pathCharArr); int resultLength = 0; fs::directory_iterator endIter; std::list<std::string> fileList; // iterate over dir contents if(fs::exists(path) && fs::is_directory(path)) { for(fs::directory_iterator dirIter(path); dirIter != endIter; dirIter++) { if(fs::is_regular_file(dirIter->status())) { resultLength++; fileList.push_back(std::string(dirIter->path().c_str())); } } } // turn result list in jsval arr jsval lsResults[resultLength]; //lsResults[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, "baz")); int resultPosCtr = 0; for(std::list<std::string>::iterator iter = fileList.begin(); iter != fileList.end();iter++) { JSString* filePathStr = JS_NewStringCopyZ(cx, (*iter).c_str()); lsResults[resultPosCtr] = STRING_TO_JSVAL(filePathStr); resultPosCtr++; } JSObject* lsArrObj = JS_NewArrayObject(cx, sizeof(lsResults)/sizeof(jsval), lsResults); jsval rVal = OBJECT_TO_JSVAL(lsArrObj); JS_SET_RVAL(cx, vp, rVal); return JS_TRUE; }
int DirectorySearch::SearchThroughDirectory(std::string args, std::string directory, std::vector<std::string> extensions, bool isVerbose) { std::tr2::sys::path fullPath(directory); if( !exists( fullPath)) { return 0; } if( !is_directory( fullPath ) ) { return EXIT_FAILURE; } for( std::tr2::sys::recursive_directory_iterator dirIter( fullPath ), endIter; dirIter != endIter; ++ dirIter ) { if(is_directory( dirIter->path() ) ) { for(unsigned int i = 0; i < extensions.size(); ++i) { std::string test = dirIter->path().extension(); if(dirIter->path().extension() == extensions[i]) { int search = SearchFileForWord(args, dirIter->path(), isVerbose); } } } else { for(unsigned int i = 0; i < extensions.size(); ++i) { std::string test = dirIter->path().extension(); if(dirIter->path().extension() == extensions[i]) { int search = SearchFileForWord(args, dirIter->path(), isVerbose); } } } } return 1; }
/** Loads data from mesh files located in the folder specified in the geometry parameters (command line parameter --mesh-folder) */ void _loadMeshFolder() { #ifdef BRAYNS_USE_ASSIMP GeometryParameters& geometryParameters = _parametersManager->getGeometryParameters(); const boost::filesystem::path& folder = geometryParameters.getMeshFolder( ); BRAYNS_INFO << "Loading meshes from " << folder << std::endl; MeshLoader meshLoader; size_t meshIndex = 0; boost::filesystem::directory_iterator endIter; if( boost::filesystem::exists(folder) && boost::filesystem::is_directory(folder)) { for( boost::filesystem::directory_iterator dirIter( folder ); dirIter != endIter; ++dirIter ) { if( boost::filesystem::is_regular_file(dirIter->status( ))) { const std::string& filename = dirIter->path( ).string( ); BRAYNS_INFO << "- " << filename << std::endl; ScenePtr scene = _engine->getScene(); MeshContainer MeshContainer = { scene->getTriangleMeshes(), scene->getMaterials(), scene->getWorldBounds() }; if(!meshLoader.importMeshFromFile( filename, MeshContainer, MQ_FAST, NO_MATERIAL )) { BRAYNS_ERROR << "Failed to import " << filename << std::endl; } ++meshIndex; } } } #endif }
/** Loads data from SWC and H5 files located in the folder specified in the geometry parameters (command line parameter --morphology-folder) */ void _loadMorphologyFolder() { GeometryParameters& geometryParameters = _parametersManager->getGeometryParameters(); const boost::filesystem::path& folder = geometryParameters.getMorphologyFolder( ); BRAYNS_INFO << "Loading morphologies from " << folder << std::endl; MorphologyLoader morphologyLoader( geometryParameters ); size_t fileIndex = 0; boost::filesystem::directory_iterator endIter; if( boost::filesystem::exists(folder) && boost::filesystem::is_directory(folder)) { for( boost::filesystem::directory_iterator dirIter( folder ); dirIter != endIter; ++dirIter ) { if( boost::filesystem::is_regular_file(dirIter->status( ))) { boost::filesystem::path fileExtension = dirIter->path( ).extension( ); if( fileExtension==".swc" || fileExtension==".h5" ) { const std::string& filename = dirIter->path( ).string( ); servus::URI uri( filename ); if( !morphologyLoader.importMorphology( uri, fileIndex++, *_engine->getScene())) { BRAYNS_ERROR << "Failed to import " << filename << std::endl; } } } } } }
bool ProjectPackager::rmdirRecursive(QString dirName) { QDir dir(dirName); // If the directory is already gone, bail. if (!dir.exists()) return true; bool success = true; // *** Delete all the files QDirIterator fileIter(dir.path(), QDir::Files | QDir::Hidden, QDirIterator::Subdirectories); while (fileIter.hasNext()) { // Create a temp to avoid calling next() twice if we want debug // output. QString currentFile = fileIter.next(); //qDebug() << "rm" << currentFile; // Remove the file if (!QFile::remove(currentFile)) { success = false; } } // *** Delete the empty directories // QDirIterator iterates through the directory tree in reverse order // from that required to properly remove the directories recursively; // it iterates from root to leaf. So we need to do this in two steps. // First, gather the directories into a vector, then go through the // vector in reverse (from leaf to root) and remove them. // It might be better to implement our own recursion so that we can // guarantee that it will always be from leaf to root. Otherwise a // change to the algorithm in QDirIterator could render this code // useless. // Iterate through the directories recursively and collect the names // into a vector. QDirIterator dirIter(dir.path(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); typedef std::vector<QString> QStringVector; QStringVector v; v.push_back(dirName); while (dirIter.hasNext()) { // Create a temp to avoid calling next() twice if we want debug // output. QString currentDir = dirIter.next(); //qDebug() << "push_back" << currentDir; v.push_back(currentDir); } // Have to move back one as rmdir() is relative to QDir's directory. dir.cdUp(); // Now go through the directories in reverse and remove them... for (QStringVector::const_reverse_iterator I = v.rbegin(); I != v.rend(); ++I) { //qDebug() << "rmdir" << *I; if (!dir.rmdir(*I)) { success = false; } } return success; }
int main(int argv, char** argc) { QApplication app(argv, argc); qApp->setOrganizationName("CTK"); qApp->setOrganizationDomain("commontk.org"); qApp->setApplicationName("ctkExampleHost"); ctkPluginFrameworkFactory fwFactory; QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework(); try { framework->init(); } catch (const ctkPluginException& exc) { qCritical() << "Failed to initialize the plug-in framework:" << exc; return EXIT_FAILURE; } #ifdef CMAKE_INTDIR QString pluginPath = qApp->applicationDirPath() + "/../plugins/" CMAKE_INTDIR "/"; #else QString pluginPath = qApp->applicationDirPath() + "/plugins/"; #endif qApp->addLibraryPath(pluginPath); QStringList libFilter; libFilter << "*.dll" << "*.so" << "*.dylib"; QDirIterator dirIter(pluginPath, libFilter, QDir::Files); QStringList pluginsToInstall; pluginsToInstall << "org_commontk_dah_core" << "org_commontk_dah_host" << "org_commontk_dah_examplehost"; QList<QSharedPointer<ctkPlugin> > installedPlugins; while(dirIter.hasNext()) { try { QString fileLocation = dirIter.next(); foreach(QString pluginToInstall, pluginsToInstall) { if (fileLocation.contains(pluginToInstall)) { QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation)); installedPlugins << plugin; break; } } } catch (const ctkPluginException& e) { qCritical() << e.what(); } } framework->start(); foreach(QSharedPointer<ctkPlugin> plugin, installedPlugins) { plugin->start(); } QMainWindow mainWindow; Ui::MainWindow ui; ui.setupUi(&mainWindow); if ( QApplication::argc() > 1 ) { ui.controlWidget->setAppFileName(QApplication::argv()[1]); } // mainWindow.addDockWidget(static_cast<Qt::DockWidgetArea>(4),new ctkHostAppExampleWidget()); // QVBoxLayout* layout = new QVBoxLayout(&mainWindow); // ctkHostAppExampleWidget* placeholder = new ctkHostAppExampleWidget(&mainWindow); // layout->addWidget(placeholder); mainWindow.show(); return app.exec(); }
void RazorDeskManager::updateIconList() { m_fsw->blockSignals(true); qDebug() << "updateIconList"; QDirIterator dirIter(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); QStringList tmpList; while (dirIter.hasNext()) { dirIter.next(); QString df(dirIter.filePath()); // HACK: QDir::NoDotAndDotDot does not work so this fixes it... if (df.endsWith("/..") || df.endsWith("/.")) continue; qDebug() << df; tmpList.append(df); // only non existing icons are created if (m_iconList.contains(df)) { qDebug() << "updateIconList REREAD. Skip:" << df; continue; } QPoint pos(0, 0); RazorDeskIconBase * idata; if (dirIter.filePath().endsWith(".desktop")) //only use .desktop files! { XdgDesktopFile* tmp = new XdgDesktopFile(); tmp->load(df); if (tmp->isShow()) { idata = new RazorDeskIconDesktop(tmp, pos); } else { delete tmp; qDebug() << "Desktop file" << df << "isShow==false"; continue; } } else { idata = new RazorDeskIconFile(df, pos); } idata->setLaunchMode(m_launchMode); connect(idata, SIGNAL(moved(QPoint)), this, SLOT(saveIconState())); m_iconList[df] = idata; } // now remove potentialy deleted icons IconMapIterator iter(m_iconList); while (iter.hasNext()) { iter.next(); if (tmpList.contains(iter.key())) continue; delete m_iconList.take(iter.key()); } qDebug() << "Razordeskmanl: found " << m_iconList.count() << " usable desktop-entries"; restoreIconState(); m_fsw->blockSignals(false); }
int main(int argv, char** argc) { QApplication app(argv, argc); qApp->setOrganizationName("CTK"); qApp->setOrganizationDomain("commontk.org"); qApp->setApplicationName("ctkPluginGenerator"); // init global template defaults QSettings settings; if (!settings.contains(ctkPluginGeneratorConstants::PLUGIN_LICENSE_MARKER)) { QFile license(":/generatordefaults/license.txt"); license.open(QIODevice::ReadOnly); QString licenseText = license.readAll(); bool ok; QString organization = QInputDialog::getText(0, qApp->translate("OrganizationInputDialog", "CTK Plugin Generator"), qApp->translate("OrganizationInputDialog", "Enter the name of your organization:"), QLineEdit::Normal, qApp->translate("OrganizationInputDialog", "<your-organization>"), &ok); if (!ok) { exit(0); } organization.replace("\\n", "\n"); settings.setValue(ctkPluginGeneratorConstants::PLUGIN_LICENSE_MARKER, licenseText.arg(organization)); } ctkPluginFrameworkFactory fwFactory; QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework(); try { framework->init(); } catch (const ctkPluginException& exc) { qCritical() << "Failed to initialize the plug-in framework:" << exc; exit(1); } #ifdef CMAKE_INTDIR QString pluginPath = CTK_PLUGIN_DIR CMAKE_INTDIR "/"; #else QString pluginPath = CTK_PLUGIN_DIR; #endif qApp->addLibraryPath(pluginPath); QStringList libFilter; libFilter << "*.dll" << "*.so" << "*.dylib"; QDirIterator dirIter(pluginPath, libFilter, QDir::Files); while(dirIter.hasNext()) { try { QString fileLocation = dirIter.next(); if (fileLocation.contains("org_commontk_plugingenerator")) { QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation)); plugin->start(ctkPlugin::START_TRANSIENT); } } catch (const ctkPluginException& e) { qCritical() << e.what(); } } framework->start(); ctkPluginGenerator generator(framework.data()); generator.show(); return app.exec(); }
void stackPlotter::plot(TString histname, TString legpos_string) { std::vector<int> colors; //colors.push_back(kAzure+3); //colors.push_back(kOrange+3); //colors.push_back(kSpring-7); //colors.push_back(kOrange-3); //colors.push_back(kCyan-5); //colors.push_back(kPink-6); //colors.push_back(kViolet+6); //colors.push_back(kYellow-9); colors.push_back(kCyan-6); colors.push_back(kYellow-9); colors.push_back(kMagenta-8); colors.push_back(kRed-7); colors.push_back(kAzure-4); colors.push_back(kOrange-3); colors.push_back(kSpring+5); colors.push_back(kMagenta-10); colors.push_back(kGray); colors.push_back(kMagenta-2); colors.push_back(kGreen-8); colors.push_back(kYellow-7); // set legpos: legendposition legpos; if(legpos_string == "t") legpos = lp_top; if(legpos_string == "l") legpos = lp_left; if(legpos_string == "r") legpos = lp_right; if(debug) std::cout << "stackPlotter::plot" << std::endl; TH1::AddDirectory(kFALSE); TDirectory::AddDirectory(kFALSE); gROOT->SetBatch(true); TFile *fIn = new TFile(infile_,"READ"); fIn->cd(); if(debug) std::cout << "stackPlotter::plot || input file '" << infile_ << "' is being read..." << std::endl; TIter dirIter(fIn->GetListOfKeys()); TObject *cDirObj; TKey *key; // iterate over directories and get all stacks int count = 0; while((key = (TKey *) dirIter())) { cDirObj=fIn->Get(key->GetName()); if(!cDirObj->InheritsFrom(TDirectory::Class())) continue; TDirectory* cDir = (TDirectory*) cDirObj; if(debug) std::cout << "stackPlotter::plot || Moving histograms from directory " << cDir->GetName() << " to relevant maps." << std::endl; moveDirHistsToStacks(cDir, histname, colors.at(count)); count++; } if(debug) std::cout << "stackPlotter::plot || input file '" << infile_ << "' has been read. Closing..." << std::endl; // intermediate cleanup fIn->Close(); delete fIn; if(debug) std::cout << "stackPlotter::plot || Closed. Saving output..." << std::endl; // create the outfile if need be if(savecanvases_) { if(debug) std::cout << "stackPlotter::plot || Opening output ROOT file" << std::endl; TString writeOption = rewriteoutfile_ ? "RECREATE" : "UPDATE"; outfile_ = new TFile(outdir_+"/plotter.root",writeOption); } // plot all the stacks & save appropriately if(debug) std::cout << "stackPlotter::plot || Plotting all the canvases" << std::endl; for(const auto& it : stacksLegEntries_) { plotStack(it.first, legpos); } // close, save, and cleanup if(savecanvases_ && outfile_) { if(debug) std::cout << "stackPlotter::plot || Closing the outfile" << std::endl; outfile_->Close(); } if(debug) std::cout << "stackPlotter::plot || Done!" << std::endl; }
ctkPluginBrowser::ctkPluginBrowser(ctkPluginFramework* framework) : framework(framework) { pluginEventTypeToString[ctkPluginEvent::INSTALLED] = "Installed"; pluginEventTypeToString[ctkPluginEvent::LAZY_ACTIVATION] = "Lazy Activation"; pluginEventTypeToString[ctkPluginEvent::RESOLVED] = "Resolved"; pluginEventTypeToString[ctkPluginEvent::STARTED] = "Started"; pluginEventTypeToString[ctkPluginEvent::STARTING] = "Starting"; pluginEventTypeToString[ctkPluginEvent::STOPPED] = "Stopped"; pluginEventTypeToString[ctkPluginEvent::STOPPING] = "Stopping"; pluginEventTypeToString[ctkPluginEvent::UNINSTALLED] = "Uninstalled"; pluginEventTypeToString[ctkPluginEvent::UNRESOLVED] = "Unresolved"; pluginEventTypeToString[ctkPluginEvent::UPDATED] = "Updated"; framework->getPluginContext()->connectFrameworkListener(this, SLOT(frameworkEvent(ctkPluginFrameworkEvent))); framework->getPluginContext()->connectPluginListener(this, SLOT(pluginEvent(ctkPluginEvent))); framework->getPluginContext()->connectServiceListener(this, "serviceEvent"); QStringList pluginDirs; #ifdef CMAKE_INTDIR pluginDirs << CTK_PLUGIN_DIR CMAKE_INTDIR "/"; #else pluginDirs << CTK_PLUGIN_DIR; #endif QStringListIterator dirIt(pluginDirs); while (dirIt.hasNext()) { QApplication::addLibraryPath(dirIt.next()); } QStringList libFilter; libFilter << "*.dll" << "*.so" << "*.dylib"; QDirIterator dirIter(pluginDirs.at(0), libFilter, QDir::Files); while(dirIter.hasNext()) { try { framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(dirIter.next()).toString()); //plugin->start(ctkPlugin::START_ACTIVATION_POLICY); } catch (const ctkPluginException& e) { qCritical() << e.what(); } } framework->start(); ui.setupUi(this); tabifyDockWidget(ui.qtResourcesDockWidget, ui.pluginResourcesDockWidget); editors = new ctkPluginBrowserEditors(ui.centralwidget); QAbstractItemModel* pluginTableModel = new ctkPluginTableModel(framework->getPluginContext(), this); ui.pluginsTableView->setModel(pluginTableModel); QAbstractItemModel* qtresourcesTreeModel = new ctkQtResourcesTreeModel(this); ui.qtResourcesTreeView->setModel(qtresourcesTreeModel); connect(ui.pluginsTableView, SIGNAL(clicked(QModelIndex)), this, SLOT(pluginSelected(QModelIndex))); connect(ui.pluginsTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(pluginDoubleClicked(QModelIndex))); connect(ui.pluginResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(dbResourceDoubleClicked(QModelIndex))); connect(ui.qtResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(qtResourceDoubleClicked(QModelIndex))); startPluginNowAction = new QAction(QIcon(":/pluginbrowser/images/run-now.png"), "Start Plugin (ignore activation policy)", this); startPluginAction = new QAction(QIcon(":/pluginbrowser/images/run.png"), "Start Plugin", this); stopPluginAction = new QAction(QIcon(":/pluginbrowser/images/stop.png"), "Stop Plugin", this); connect(startPluginNowAction, SIGNAL(triggered()), this, SLOT(startPluginNow())); connect(startPluginAction, SIGNAL(triggered()), this, SLOT(startPlugin())); connect(stopPluginAction, SIGNAL(triggered()), this, SLOT(stopPlugin())); startPluginNowAction->setEnabled(false); startPluginAction->setEnabled(false); stopPluginAction->setEnabled(false); ui.pluginToolBar->addAction(startPluginNowAction); ui.pluginToolBar->addAction(startPluginAction); ui.pluginToolBar->addAction(stopPluginAction); QSettings settings; if(settings.contains(SETTINGS_WND_GEOM)) { this->restoreGeometry(settings.value(SETTINGS_WND_GEOM).toByteArray()); } if (settings.contains(SETTINGS_WND_STATE)) { this->restoreState(settings.value(SETTINGS_WND_STATE).toByteArray()); } }
//---------------------------------------------------------------------------- int main(int argv, char** argc) { QApplication app(argv, argc); qApp->setOrganizationName("CTK"); qApp->setOrganizationDomain("commontk.org"); qApp->setApplicationName("ctkExampleHostedApp"); ctkCommandLineParser parser; parser.setArgumentPrefix("--", "-"); // Use Unix-style argument names // Add command line argument names parser.addArgument("hostURL", "", QVariant::String, "Hosting system URL"); parser.addArgument("applicationURL", "", QVariant::String, "Hosted Application URL"); parser.addArgument("help", "h", QVariant::Bool, "Show this help text"); bool ok = false; QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok); if (!ok) { QTextStream(stderr, QIODevice::WriteOnly) << "Error parsing arguments: " << parser.errorString() << "\n"; return EXIT_FAILURE; } // Show a help message if (parsedArgs.contains("help")) { print_usage(); QTextStream(stdout, QIODevice::WriteOnly) << parser.helpText(); return EXIT_SUCCESS; } if(parsedArgs.count() != 2) { qCritical() << "Wrong number of command line arguments."; print_usage(); QTextStream(stdout, QIODevice::WriteOnly) << parser.helpText(); return EXIT_FAILURE; } QString hostURL = parsedArgs.value("hostURL").toString(); QString appURL = parsedArgs.value("applicationURL").toString(); qDebug() << "appURL is: " << appURL << " . Extracted port is: " << QUrl(appURL).port(); // setup the plugin framework ctkProperties fwProps; fwProps.insert("dah.hostURL", hostURL); fwProps.insert("dah.appURL", appURL); ctkPluginFrameworkFactory fwFactory(fwProps); QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework(); try { framework->init(); } catch (const ctkPluginException& exc) { qCritical() << "Failed to initialize the plug-in framework:" << exc; return EXIT_FAILURE; } #ifdef CMAKE_INTDIR QString pluginPath = CTK_PLUGIN_DIR CMAKE_INTDIR "/"; #else QString pluginPath = CTK_PLUGIN_DIR; #endif qApp->addLibraryPath(pluginPath); // Construct the name of the plugin with the business logic // (thus the actual logic of the hosted app) QString pluginName("org_commontk_dah_exampleapp"); if(parser.unparsedArguments().count() > 0) { pluginName = parser.unparsedArguments().at(0); } // try to find the plugin and install all plugins available in // pluginPath containing the string "org_commontk_dah" (but do not start them) QSharedPointer<ctkPlugin> appPlugin; QStringList libFilter; libFilter << "*.dll" << "*.so" << "*.dylib"; QDirIterator dirIter(pluginPath, libFilter, QDir::Files); while(dirIter.hasNext()) { try { QString fileLocation = dirIter.next(); if (fileLocation.contains("org_commontk_dah")) { QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation)); if (fileLocation.contains(pluginName)) { appPlugin = plugin; } //plugin->start(ctkPlugin::START_TRANSIENT); } } catch (const ctkPluginException& e) { qCritical() << e.what(); } } // if we did not find the business logic: abort if(!appPlugin) { qCritical() << "Could not find plugin."; qCritical() << " Plugin name: " << pluginName; qCritical() << " Plugin path: " << pluginPath; return EXIT_FAILURE; } // start the plugin framework framework->start(); // start the plugin with the business logic try { appPlugin->start(); } catch (const ctkPluginException& e) { qCritical() << e; } return app.exec(); }
bool DirScanner::innerScan(boost::filesystem::path dirToScan) { boost::filesystem::directory_iterator dirIter(dirToScan); std::string fileNameStem = ""; std::string floraNifFileStem = ""; std::string pickedNifFileStem = ""; std::string unpickedNifFileStem = ""; std::string filePath = ""; std::string ext = ""; std::string floraString = "flora_"; unsigned long int floraStringLength = floraString.length(); unsigned long int fileNameStemLength = 0; while(dirIter != boost::filesystem::directory_iterator()) { boost::filesystem::path currentPath = dirIter->path(); std::cout << currentPath.string() << std::endl; if(canBeScanned(currentPath)){ innerScan(currentPath); } ext = currentPath.extension().string(); fileNameStem = currentPath.stem().string(); filePath = currentPath.string(); fileNameStemLength = fileNameStem.length(); ++dirIter; if(!boost::iequals(ext,".nif")){ continue; } if(fileNameStem[fileNameStem.length()-1]=='P'&& fileNameStem[fileNameStem.length()-2]=='_'&& filePath.find("GHerb") != std::string::npos) { pickedNifFileStem = fileNameStem.substr(0,fileNameStemLength-2); pickedNifs[pickedNifFileStem]=filePath; continue; } if(fileNameStem[fileNameStem.length()-1]=='U'&& fileNameStem[fileNameStem.length()-2]=='_'&& filePath.find("GHerb") != std::string::npos) { unpickedNifFileStem = fileNameStem.substr(0,fileNameStemLength-2); unpickedNifs[unpickedNifFileStem]=filePath; continue; } if(fileNameStem.length() >= floraString.length()) { std::string tempFlora = fileNameStem.substr(0, floraStringLength); if(boost::iequals(tempFlora, floraString) && filePath.find("GHerb") == std::string::npos) { floraNifFileStem = fileNameStem.erase(0,floraStringLength); originalNifs[floraNifFileStem]=filePath; continue; } } } return true; }
QVector<BootstrapModelPrivate::Lines*> BootstrapModelPrivate::loadDefaultBootstrapServers() { auto servers = QVector<BootstrapModelPrivate::Lines*>(); /* get the bootstrap directory */ QString bootstrapDirPath = QStandardPaths::locate( QStandardPaths::DataLocation, "bootstrap", QStandardPaths::LocateDirectory ); QDir bootstrapDir = QDir(bootstrapDirPath); auto bootstrapFiles = QVector<QFileInfo>(); // Main bootstrap servers file auto mainBootstrapFile = QFileInfo(bootstrapDir.path() + "/servers.json"); if (mainBootstrapFile.exists() && mainBootstrapFile.isFile()) { bootstrapFiles << mainBootstrapFile; } // Secondary bootstrap servers files auto secondaryBootstrapServersDir = QFileInfo(bootstrapDir.path() + "/servers.json.d/"); if (secondaryBootstrapServersDir.exists() && secondaryBootstrapServersDir.isDir()) { QDirIterator dirIter( secondaryBootstrapServersDir.path(), QDirIterator::Subdirectories ); while (dirIter.hasNext()) { dirIter.next(); auto secBootstrapFileInfo = QFileInfo(dirIter.filePath()); if (secBootstrapFileInfo.isFile() && secBootstrapFileInfo.suffix() == "json") { bootstrapFiles << secBootstrapFileInfo; } } } //Parse JSON files foreach(const auto fileInfo, bootstrapFiles) { QFile bootstrapFile(fileInfo.filePath()); if (bootstrapFile.open(QIODevice::ReadOnly | QIODevice::Text)) { auto jsonDoc = QJsonDocument::fromJson(bootstrapFile.readAll()); bootstrapFile.close(); if (jsonDoc.isNull() == false && jsonDoc.isArray() == true) { QJsonArray jsonArray = jsonDoc.array(); foreach(const auto jsonValue, jsonArray) { auto hostObject = jsonValue.toObject(); auto hostValue = hostObject.value("host"); auto portValue = hostObject.value("port"); if (hostValue.isUndefined() == false && hostValue.isString() && portValue.isUndefined() == false && portValue.isDouble()) { BootstrapModelPrivate::Lines* server = new BootstrapModelPrivate::Lines(); server->hostname = hostValue.toString(); server->port = portValue.toInt(-1); servers << server; } }
INT32 dpsArchiveFileMgr::scanArchiveFiles( UINT32& minFileId, UINT32& maxFileId, BOOLEAN allowMoved ) { INT32 rc = SDB_OK ; minFileId = DPS_INVALID_LOG_FILE_ID ; maxFileId = DPS_INVALID_LOG_FILE_ID ; try { fs::path dir ( _archivePath ) ; fs::directory_iterator endIter ; for ( fs::directory_iterator dirIter( dir ) ; dirIter != endIter ; ++dirIter ) { const string fileName = dirIter->path().filename().string() ; if ( !isArchiveFileName( fileName ) ) { continue ; } if ( isFullFileName( fileName ) || isPartialFileName( fileName ) || ( allowMoved && isMovedFileName( fileName ) ) ) { UINT32 fileId = 0 ; rc = getFileId( fileName, fileId ) ; if ( SDB_OK != rc ) { SDB_ASSERT( FALSE, "invalid fileName" ) ; PD_LOG( PDWARNING, "Failed to get file id of file[%s]", fileName.c_str() ) ; continue ; // ignore this file } if ( minFileId > fileId || DPS_INVALID_LOG_FILE_ID == minFileId ) { minFileId = fileId ; } if ( maxFileId < fileId || DPS_INVALID_LOG_FILE_ID == maxFileId ) { maxFileId = fileId ; } } } } catch( fs::filesystem_error& e ) { if ( e.code() == boost::system::errc::permission_denied || e.code() == boost::system::errc::operation_not_permitted ) { rc = SDB_PERM ; } else { rc = SDB_IO ; } goto error ; } catch( std::exception& e ) { PD_LOG( PDERROR, "unexpected exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }