void TestRunnerModel::loadHistory() { m_history.clear(); int idx = 1; do { CString testName = loadHistoryEntry( idx++ ); if ( testName.IsEmpty() ) break; try { m_history.push_back( m_rootTest->findTest( toAnsiString(testName ) ) ); } catch ( std::invalid_argument &) { } } while ( true ); }
String::operator std::string() const { return toAnsiString(); }
int Game::loadGamestate(const XMLReader& reader, const sf::String& GSname, const SFG::Pointer<GameState>& included) { SFG::Pointer<GameState> GS_ptr; sf::String GSxmlpath = L"xml/gamestate[" + GSname + L"]"; auto str = reader.getValue(GSxmlpath, 0); if (str == L"__xml_failure") { printf("[Error] Unspecified startup gamestate in %s:%d.\n", __FILE__, __LINE__); return -2; } else { if (str == L"#included") { //Use default GS_ptr.reset(included); if (!GS_ptr.isValid() && included.getElement() != nullptr) { printf("[Critical] Failed to allocate memory for \"%s\" in %s:%d\n",GSname.toAnsiString().c_str(), __FILE__, __LINE__); return -1; } } else { //Use specified //#TODO STILL_TO_DO(__FILE__, __LINE__); //We first need an instance of a DLLLoadedGameState GS_ptr.reset(new DLLLoadedGameState()); //Set the name GS_ptr->setName(GSname); if (GS_ptr->getName() == "__xml_failure") { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to get Gamestate name, aborting."); return -1; } //Then, load the specified file if (GS_ptr.cast<DLLLoadedGameState>()->loadFromDll(str.toAnsiString().c_str()) != 0) { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load gamestate \"%s\" from DLL", str.toAnsiString().c_str()); return -2; } //We actually should be done } //Get all modules sf::String uses = reader.getValue(GSxmlpath + L"uses."); if (uses != L"__xml_failure") { //We have specifiers size_t begin = 0; size_t last = 0; //Begin needs to be checked as the last module wouldn't be counted otherwise while ((last = uses.find(L',', last)) != sf::String::InvalidPos || begin != sf::String::InvalidPos) { sf::String string; if (last == sf::String::InvalidPos) { //If the end would otherwise exceed the string length, set it to the maximum (sf::String::end()). //string = sf::String(uses.begin() + begin, uses.end()); string = uses.substring(begin, uses.getSize() - begin); } else { //If a ',' was found, use its position //string = sf::String(uses.begin() + begin, uses.begin() + last); string = uses.substring(begin, last - begin); } //Check for module names if (string == L"G2D") { SFG::Pointer<ModuleG2D> ptr(new ModuleG2D()); if (!ptr.isValid()) { char buf[512]; #ifdef _WIN32 strerror_s(buf, errno); #else strerror_r(errno, buf, 512); #endif // _WIN32 printf("[Error] Failed to create Module G2D in %s:%d: %s\n", __FILE__, __LINE__, buf); return -3; } GS_ptr->addModule(ptr); } else { //#TODO: Add more modules (sound etc.) STILL_TO_DO(__FILE__, __LINE__); } if(last != sf::String::InvalidPos) begin = last + 1; //if a ',' was found, go search on for the next one else begin = last; //Meaning begin is sf::String::npos } } //Check for external asset list auto ext_assets = reader.getValue(GSxmlpath + "assets."); if (ext_assets != "__xml_failure") { //We found external assets, load them } auto assets = reader.getXMLGroupHandle(L"xml/assetlist[" + GSname + L"]"); if (assets == nullptr) { printf("[Warning] No assets for Gamestate \"%s\" found. This is not encouraged and might be an error. Please check the game.xml file. In: %s:%d\n", GSname.toAnsiString().c_str(), __FILE__, __LINE__); //return 1; } else { auto ret = GS_ptr->loadAssets(XMLReader(*assets)); if (ret != 0) { printf("[Error] Failed to load assets for Gamestate \"%s\" in %s:%d.\n", GSname.toAnsiString().c_str(), __FILE__, __LINE__); } } //Empty path to tell the gamestate to just update what it has (or do nothing if nothing has to be done) GS_ptr->load(L""); //this->g_gamestates.push_back(GS_ptr); this->addGamestate(GS_ptr); } return 0; }