void UnlockManager::save()
{
    std::string filename = file_manager->getChallengeFile("challenges.xml");
    
    std::ofstream challenge_file(filename.c_str(), std::ios::out);

    if (!challenge_file.is_open())
    {
        std::cerr << "Failed to open " << filename << " for writing, challenges won't be saved\n";
        return;
    }

    challenge_file << "<?xml version=\"1.0\"?>\n";
    challenge_file << "<challenges>\n";
    
    std::map<std::string, GameSlot*>::iterator it;
    for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
    {
        it->second->save(challenge_file);
    }
    
    challenge_file << "</challenges>\n\n";
    challenge_file.close();
}   // save
Ejemplo n.º 2
0
void UnlockManager::save()
{
    std::string filename = file_manager->getUserConfigFile("challenges.xml");

    std::ofstream challenge_file(filename.c_str(), std::ios::out);

    if (!challenge_file.is_open())
    {
        Log::warn("unlock_manager",
                  "Failed to open '%s' for writing, challenges won't be saved\n",
                  filename.c_str());
        return;
    }

    challenge_file << "<?xml version=\"1.0\"?>\n";
    challenge_file << "<challenges>\n";

    std::map<std::string, GameSlot*>::iterator it;
    for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
    {
        std::string name = "unknown player";
        for (unsigned int i = 0; i < UserConfigParams::m_all_players.size(); i++)
        {
            if (UserConfigParams::m_all_players[i].getUniqueID() == it->second->getPlayerID())
            {
                name = core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str();
                break;
            }
        }

        it->second->save(challenge_file, name);
    }

    challenge_file << "</challenges>\n\n";
    challenge_file.close();
}   // save