void ViewController::reloadGameListView(IGameListView* view, bool reloadTheme) { for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) { if(it->second.get() == view) { bool isCurrent = (mCurrentView == it->second); SystemData* system = it->first; FileData* cursor = view->getCursor(); mGameListViews.erase(it); if(reloadTheme) system->loadTheme(); std::shared_ptr<IGameListView> newView = getGameListView(system); // to counter having come from a placeholder if (!cursor->isPlaceHolder()) { newView->setCursor(cursor); } if(isCurrent) mCurrentView = newView; break; } } // Redisplay the current view if (mCurrentView) mCurrentView->onShow(); }
void ViewController::goToPrevGameList() { assert(mState.viewing == GAME_LIST); SystemData* system = getState().getSystem(); assert(system); goToGameList(system->getPrev()); }
GuiGamelistOptions::~GuiGamelistOptions() { // save and apply sort SystemData* system = getGamelist()->getCursor()->getSystem(); FileData* root = system->getRootFolder(); system->sortId = mListSort->getSelectedId(); // this will break if mListSort isn't in the same order as FileSorts:typesArr root->sort(*mListSort->getSelected()); // will also recursively sort children // notify that the root folder was sorted getGamelist()->onFileChanged(root, FILE_SORTED); }
bool wxIDataObject::HasSystemData(wxDataFormat format) const { for ( SystemData::const_iterator it = m_systemData.begin(); it != m_systemData.end(); ++it ) { FORMATETC* formatEtc = (*it)->pformatetc; if ( formatEtc->cfFormat == format ) return true; } return false; }
void GuiFastSelect::updateGameListSort() { const FileData::SortType& sort = FileSorts::SortTypes.at(mSortId); SystemData* system = mGameList->getCursor()->getSystem(); FileData* root = system->getRootFolder(); system->sortId = mSortId; // update system sort setting root->sort(sort); // will also recursively sort children // notify that the root folder was sorted mGameList->onFileChanged(root, FILE_SORTED); }
bool SystemView::input(InputConfig* config, Input input) { if(input.value != 0) { if(config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_r && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) { LOG(LogInfo) << " Reloading SystemList view"; // reload themes for(auto it = mEntries.begin(); it != mEntries.end(); it++) it->object->loadTheme(); populate(); updateHelpPrompts(); return true; } if(config->isMappedTo("left", input)) { listInput(-1); return true; } if(config->isMappedTo("right", input)) { listInput(1); return true; } if(config->isMappedTo("a", input)) { stopScrolling(); SystemData *systemData = getSelected(); // decide whether to show game list or launch the command directly if ( !systemData->getDirectLaunch() ) { ViewController::get()->goToGameList(getSelected()); }else{ systemData->launchGame( mWindow, nullptr ); } return true; } }else{ if(config->isMappedTo("left", input) || config->isMappedTo("right", input)) listInput(0); } return GuiComponent::input(config, input); }
STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDir, IEnumFORMATETC **ppenumFormatEtc) { wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::EnumFormatEtc")); wxDataObject::Direction dir = dwDir == DATADIR_GET ? wxDataObject::Get : wxDataObject::Set; // format count is total of user specified and system formats. const size_t ourFormatCount = m_pDataObject->GetFormatCount(dir); const size_t sysFormatCount = m_systemData.size(); const ULONG nFormatCount = wx_truncate_cast(ULONG, ourFormatCount + sysFormatCount); // fill format array with formats ... wxScopedArray<wxDataFormat> formats(nFormatCount); // ... from content data (supported formats) m_pDataObject->GetAllFormats(formats.get(), dir); // ... from system data for ( size_t j = 0; j < sysFormatCount; j++ ) { SystemDataEntry* entry = m_systemData[j]; wxDataFormat& format = formats[ourFormatCount + j]; format = entry->pformatetc->cfFormat; } wxIEnumFORMATETC *pEnum = new wxIEnumFORMATETC(formats.get(), nFormatCount); pEnum->AddRef(); *ppenumFormatEtc = pEnum; return S_OK; }
void CollectionSystemManager::loadAutoCollectionSystems() { for(std::map<std::string, CollectionSystemDecl>::iterator it = mCollectionSystemDecls.begin() ; it != mCollectionSystemDecls.end() ; it++ ) { CollectionSystemDecl sysDecl = it->second; if (!sysDecl.isCustom && !findCollectionSystem(sysDecl.name)) { SystemData* newSys = new SystemData(sysDecl.name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true); FileData* rootFolder = newSys->getRootFolder(); FileFilterIndex* index = newSys->getIndex(); for(auto sysIt = SystemData::sSystemVector.begin(); sysIt != SystemData::sSystemVector.end(); sysIt++) { if ((*sysIt)->isGameSystem()) { std::vector<FileData*> files = (*sysIt)->getRootFolder()->getFilesRecursive(GAME); for(auto gameIt = files.begin(); gameIt != files.end(); gameIt++) { bool include = includeFileInAutoCollections((*gameIt)); switch(sysDecl.type) { case AUTO_LAST_PLAYED: include = include && (*gameIt)->metadata.get("playcount") > "0"; break; case AUTO_FAVORITES: // we may still want to add files we don't want in auto collections in "favorites" include = (*gameIt)->metadata.get("favorite") == "true"; break; } if (include) { CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys); rootFolder->addChild(newGame); index->addToIndex(newGame); } } } } rootFolder->sort(getSortType(sysDecl.defaultSort)); mAutoCollectionSystems.push_back(newSys); CollectionSystemData newCollectionData; newCollectionData.system = newSys; newCollectionData.decl = sysDecl; newCollectionData.isEnabled = false; mAllCollectionSystems[sysDecl.name] = newCollectionData; } } }
bool wxIDataObject::GetSystemData(wxDataFormat format, STGMEDIUM *pmedium) const { for ( SystemData::const_iterator it = m_systemData.begin(); it != m_systemData.end(); ++it ) { FORMATETC* formatEtc = (*it)->pformatetc; if ( formatEtc->cfFormat == format ) { wxCopyStgMedium((*it)->pmedium, pmedium); return true; } } return false; }
// save system data HRESULT wxIDataObject::SaveSystemData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) { if ( pformatetc == NULL || pmedium == NULL ) return E_INVALIDARG; // remove entry if already available for ( SystemData::iterator it = m_systemData.begin(); it != m_systemData.end(); ++it ) { if ( pformatetc->tymed & (*it)->pformatetc->tymed && pformatetc->dwAspect == (*it)->pformatetc->dwAspect && pformatetc->cfFormat == (*it)->pformatetc->cfFormat ) { delete (*it); m_systemData.erase(it); break; } } // create new format/medium FORMATETC* pnewformatEtc = new FORMATETC; STGMEDIUM* pnewmedium = new STGMEDIUM; wxZeroMemory(*pnewformatEtc); wxZeroMemory(*pnewmedium); // copy format *pnewformatEtc = *pformatetc; // copy or take ownerschip of medium if ( fRelease ) *pnewmedium = *pmedium; else wxCopyStgMedium(pmedium, pnewmedium); // save entry m_systemData.push_back(new SystemDataEntry(pnewformatEtc, pnewmedium)); return S_OK; }
void ViewController::reloadGameListView(IGameListView* view, bool reloadTheme) { for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++) { if(it->second.get() == view) { bool isCurrent = (mCurrentView == it->second); SystemData* system = it->first; FileData* cursor = view->getCursor(); mGameListViews.erase(it); if(reloadTheme) system->loadTheme(); std::shared_ptr<IGameListView> newView = getGameListView(system); newView->setCursor(cursor); if(isCurrent) mCurrentView = newView; break; } } }
//creates systems from information located in a config file void SystemData::loadConfig() { deleteSystems(); std::string path = getConfigPath(); std::cout << "Loading system config file \"" << path << "\"...\n"; std::ifstream file(path.c_str()); if(file.is_open()) { std::string line; std::string sysName, sysPath, sysExtension, sysCommand; while(file.good()) { std::getline(file, line); //skip blank lines and comments if(line.empty() || line[0] == *"#") continue; //find the name (left of the equals sign) and the value (right of the equals sign) bool lineValid = false; std::string varName, varValue; for(unsigned int i = 0; i < line.length(); i++) { if(line[i] == *"=") { lineValid = true; varName = line.substr(0, i); varValue = line.substr(i + 1, line.length() - 1); std::cout << " " << varName << " = " << varValue << "\n"; break; } } if(lineValid) { //map the value to the appropriate variable if(varName == "NAME") sysName = varValue; else if(varName == "PATH") sysPath = varValue; else if(varName == "EXTENSION") sysExtension = varValue; else if(varName == "COMMAND") sysCommand = varValue; else std::cerr << "Error reading config file - unknown variable name \"" << varName << "\"!\n"; //we have all our variables - create the system object if(!sysName.empty() && !sysPath.empty() &&!sysExtension.empty() && !sysCommand.empty()) { SystemData* newSystem = new SystemData(sysName, sysPath, sysExtension, sysCommand); if(newSystem->getRootFolder()->getFileCount() == 0) { std::cerr << "Error - system \"" << sysName << "\" has no games! Deleting.\n"; delete newSystem; }else{ sSystemVector.push_back(newSystem); } //reset the variables for the next block (should there be one) sysName = ""; sysPath = ""; sysExtension = ""; sysCommand = ""; } }else{ std::cerr << "Error reading config file \"" << path << "\" - no equals sign found on line \"" << line << "\"!\n"; return; } } }else{ std::cerr << "Error - could not load config file \"" << path << "\"!\n"; return; } std::cout << "Finished loading config file - created " << sSystemVector.size() << " systems.\n"; return; }
//creates systems from information located in a config file bool SystemData::loadConfig() { deleteSystems(); std::string path = getConfigPath(false); LOG(LogInfo) << "Loading system config file " << path << "..."; if(!fs::exists(path)) { LOG(LogError) << "es_systems.cfg file does not exist!"; writeExampleConfig(getConfigPath(true)); return false; } pugi::xml_document doc; pugi::xml_parse_result res = doc.load_file(path.c_str()); if(!res) { LOG(LogError) << "Could not parse es_systems.cfg file!"; LOG(LogError) << res.description(); return false; } //actually read the file pugi::xml_node systemList = doc.child("systemList"); if(!systemList) { LOG(LogError) << "es_systems.cfg is missing the <systemList> tag!"; return false; } for(pugi::xml_node system = systemList.child("system"); system; system = system.next_sibling("system")) { std::string name, fullname, path, cmd, themeFolder; PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN; name = system.child("name").text().get(); fullname = system.child("fullname").text().get(); path = system.child("path").text().get(); // convert extensions list from a string into a vector of strings std::vector<std::string> extensions = readList(system.child("extension").text().get()); cmd = system.child("command").text().get(); // platform id list const char* platformList = system.child("platform").text().get(); std::vector<std::string> platformStrs = readList(platformList); std::vector<PlatformIds::PlatformId> platformIds; for(auto it = platformStrs.begin(); it != platformStrs.end(); it++) { const char* str = it->c_str(); PlatformIds::PlatformId platformId = PlatformIds::getPlatformId(str); if(platformId == PlatformIds::PLATFORM_IGNORE) { // when platform is ignore, do not allow other platforms platformIds.clear(); platformIds.push_back(platformId); break; } // if there appears to be an actual platform ID supplied but it didn't match the list, warn if(str != NULL && str[0] != '\0' && platformId == PlatformIds::PLATFORM_UNKNOWN) LOG(LogWarning) << " Unknown platform for system \"" << name << "\" (platform \"" << str << "\" from list \"" << platformList << "\")"; else if(platformId != PlatformIds::PLATFORM_UNKNOWN) platformIds.push_back(platformId); } // theme folder themeFolder = system.child("theme").text().as_string(name.c_str()); //validate if(name.empty() || path.empty() || extensions.empty() || cmd.empty()) { LOG(LogError) << "System \"" << name << "\" is missing name, path, extension, or command!"; continue; } //convert path to generic directory seperators boost::filesystem::path genericPath(path); path = genericPath.generic_string(); SystemData* newSys = new SystemData(name, fullname, path, extensions, cmd, platformIds, themeFolder); if(newSys->getRootFolder()->getChildren().size() == 0) { LOG(LogWarning) << "System \"" << name << "\" has no games! Ignoring it."; delete newSys; }else{ sSystemVector.push_back(newSys); } } return true; }