void BookmarkPropertiesDialog::reloadFolders() { m_model->clear(); QStandardItem *item = new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), tr("Bookmarks")); item->setData(0, Qt::UserRole); item->setToolTip(tr("Bookmarks")); m_model->invisibleRootItem()->appendRow(item); m_index = item->index(); populateFolder(BookmarksManager::getFolder(0), item); QTreeView *view = qobject_cast<QTreeView*>(m_ui->folderComboBox->view()); if (view) { view->setCurrentIndex(m_index); view->expandAll(); m_ui->folderComboBox->setRootModelIndex(m_index.parent()); m_ui->folderComboBox->setModelColumn(0); m_ui->folderComboBox->setCurrentIndex(m_index.row()); m_ui->folderComboBox->setRootModelIndex(QModelIndex()); } }
void SystemData::populateFolder(FolderData* folder) { std::string folderPath = folder->getPath(); if(!fs::is_directory(folderPath)) { std::cerr << "Error - folder with path \"" << folderPath << "\" is not a directory!\n"; return; } for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir) { fs::path filePath = (*dir).path(); if(fs::is_directory(filePath)) { FolderData* newFolder = new FolderData(this, filePath.string(), filePath.stem().string()); populateFolder(newFolder); folder->pushFileData(newFolder); }else{ if(filePath.extension().string() == mSearchExtension) { GameData* newGame = new GameData(this, filePath.string(), filePath.stem().string()); folder->pushFileData(newGame); } } } }
SystemData::SystemData(std::string name, std::string startPath, std::string extension, std::string command) { mName = name; //expand home symbol if the startpath contains it if(startPath[0] == '~') { startPath.erase(0, 1); std::string home = getenv("HOME"); if(home.empty()) { std::cerr << "ERROR - System start path contains ~ but $HOME is not set!\n"; return; }else{ startPath.insert(0, home); } } mStartPath = startPath; mSearchExtension = extension; mLaunchCommand = command; mRootFolder = new FolderData(this, mStartPath, "Search Root"); if(!PARSEGAMELISTONLY) populateFolder(mRootFolder); parseGamelist(this); mRootFolder->sort(); }
SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions, const std::string& command, const std::vector<PlatformIds::PlatformId>& platformIds, const std::string& themeFolder) { mName = name; mFullName = fullName; mStartPath = startPath; //expand home symbol if the startpath contains ~ if(mStartPath[0] == '~') { mStartPath.erase(0, 1); mStartPath.insert(0, getHomePath()); } mSearchExtensions = extensions; mLaunchCommand = command; mPlatformIds = platformIds; mThemeFolder = themeFolder; mRootFolder = new FileData(FOLDER, mStartPath, this); mRootFolder->metadata.set("name", mFullName); if(!Settings::getInstance()->getBool("ParseGamelistOnly")) populateFolder(mRootFolder); if(!Settings::getInstance()->getBool("IgnoreGamelist")) parseGamelist(this); mRootFolder->sort(FileSorts::SortTypes.at(0)); loadTheme(); }
SystemData::SystemData(std::string name, std::string descName, std::string startPath, std::string extension, std::string command) { mName = name; mDescName = descName; //expand home symbol if the startpath contains ~ if(startPath[0] == '~') { startPath.erase(0, 1); std::string home = getHomePath(); startPath.insert(0, home); } mStartPath = startPath; mSearchExtension = extension; mLaunchCommand = command; mRootFolder = new FolderData(this, mStartPath, "Search Root"); if(!PARSEGAMELISTONLY) populateFolder(mRootFolder); if(!IGNOREGAMELIST) parseGamelist(this); mRootFolder->sort(); }
void SystemData::populateFolder(FolderData* folder) { std::string folderPath = folder->getPath(); if(!fs::is_directory(folderPath)) { std::cerr << "Error - folder with path \"" << folderPath << "\" is not a directory!\n"; return; } for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir) { fs::path filePath = (*dir).path(); if(filePath.stem().string().empty()) continue; if(fs::is_directory(filePath)) { FolderData* newFolder = new FolderData(this, filePath.string(), filePath.stem().string()); populateFolder(newFolder); //ignore folders that do not contain games if(newFolder->getFileCount() == 0) delete newFolder; else folder->pushFileData(newFolder); }else{ //this is a little complicated because we allow a list of extensions to be defined (delimited with a space) //we first get the extension of the file itself: std::string extension = filePath.extension().string(); std::string chkExt; size_t extPos = 0; do { //now we loop through every extension in the list size_t cpos = extPos; extPos = mSearchExtension.find(" ", extPos); chkExt = mSearchExtension.substr(cpos, ((extPos == std::string::npos) ? mSearchExtension.length() - cpos: extPos - cpos)); //if it matches, add it if(chkExt == extension) { GameData* newGame = new GameData(this, filePath.string(), filePath.stem().string()); folder->pushFileData(newGame); break; }else if(extPos != std::string::npos) //if not, add one to the "next position" marker to skip the space when reading the next extension { extPos++; } } while(extPos != std::string::npos && chkExt != "" && chkExt.find(".") != std::string::npos); } } }
void BookmarkPropertiesDialog::populateFolder(const QList<BookmarkInformation*> bookmarks, QStandardItem *parent) { for (int i = 0; i < bookmarks.count(); ++i) { if (bookmarks.at(i)->type == FolderBookmark) { const QString title = (bookmarks.at(i)->title.isEmpty() ? tr("(Untitled)") : bookmarks.at(i)->title); QStandardItem *item = new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), title); item->setData(bookmarks.at(i)->identifier, Qt::UserRole); item->setToolTip(title); parent->appendRow(item); populateFolder(BookmarksManager::getFolder(bookmarks.at(i)->identifier), item); if (bookmarks.at(i)->identifier == m_folder) { m_index = item->index(); } } } }
void SystemData::populateFolder(FileData* folder) { const fs::path& folderPath = folder->getPath(); if(!fs::is_directory(folderPath)) { LOG(LogWarning) << "Error - folder with path \"" << folderPath << "\" is not a directory!"; return; } const std::string folderStr = folderPath.generic_string(); //make sure that this isn't a symlink to a thing we already have if(fs::is_symlink(folderPath)) { //if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse if(folderStr.find(fs::canonical(folderPath).generic_string()) == 0) { LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\""; return; } } fs::path filePath; std::string extension; bool isGame; for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir) { filePath = (*dir).path(); if(filePath.stem().empty()) continue; //this is a little complicated because we allow a list of extensions to be defined (delimited with a space) //we first get the extension of the file itself: extension = filePath.extension().string(); //fyi, folders *can* also match the extension and be added as games - this is mostly just to support higan //see issue #75: https://github.com/Aloshi/EmulationStation/issues/75 isGame = false; if(std::find(mSearchExtensions.begin(), mSearchExtensions.end(), extension) != mSearchExtensions.end()) { FileData* newGame = new FileData(GAME, filePath.generic_string(), this); folder->addChild(newGame); isGame = true; } //add directories that also do not match an extension as folders if(!isGame && fs::is_directory(filePath)) { FileData* newFolder = new FileData(FOLDER, filePath.generic_string(), this); populateFolder(newFolder); //ignore folders that do not contain games if(newFolder->getChildren().size() == 0) delete newFolder; else folder->addChild(newFolder); } } }