// This function writes all the data from the CPlayGame and CMenu Instances to a file,
// closes it and flushes the data block.
bool CSaveGameController::save()
{
    std::ofstream StateFile;
    std::string fullpath = GetFullFileName(m_statefilename);
    bool open = OpenGameFileW( StateFile, m_statefilename, std::ofstream::binary );

    if (!open)
    {
        g_pLogFile->textOut("Error saving \"" + fullpath + "\". Please check the status of that path.\n" );
        return false;
    }

    // Convert everything to a primitive data structure
    // First pass the header, which is only version,
    // sizeofname and name of slot itself
    Uint32 offset = 0;
    Uint32 size = sizeof(SAVEGAMEVERSION)
                  + sizeof(char)
                  + m_statename.size()*sizeof(char);

    size += m_datablock.size();
    // Headersize + Datablock size
    std::vector<char> primitive_buffer(size);

    // Write the header
    primitive_buffer[offset++] = SAVEGAMEVERSION;
    primitive_buffer[offset++] = m_statename.size();

    for( Uint32 i=0; i<m_statename.size() ; i++ )
    {
        primitive_buffer[offset++] = m_statename[i];
    }

    // Write the collected data block
    std::vector<byte>::iterator pos = m_datablock.begin();
    for( size_t i=0; i<m_datablock.size() ; i++ )
    {
        primitive_buffer[offset++] = *pos;
        pos++;
    }

    // TODO: Compression has still to be done!

    // Now write all the data to the file
    StateFile.write( &primitive_buffer[0], size );
    StateFile.close();

    m_datablock.clear();

    // Done!
    g_pLogFile->textOut("File \""+ fullpath +"\" was sucessfully saved. Size: "+itoa(size)+"\n");
    m_statefilename.clear();
    m_statename.clear();

    return true;
}
void CGameLauncher::putLabels()
{
    Uint16 i;
    std::string line;
    std::ofstream gamescfg;

    OpenGameFileW(gamescfg, GAMESCFG);
    if (gamescfg.is_open())
    {
        for ( i=0; i<m_Entries.size(); i++ )
        {
            line = GAMESCFG_DIR + m_Entries.at(i).exefilename;
            gamescfg << line << std::endl;
            line = GAMESCFG_NAME + m_Entries.at(i).name;
            gamescfg << line << std::endl << std::endl;
        }
        gamescfg.close();
    }
}
예제 #3
0
bool CConfiguration::saveCfgFile()
{
	std::ofstream file;
	if(!OpenGameFileW(file, m_filename))
		return false;

	SectionMap::iterator sect = m_sections.begin();
	for(; sect != m_sections.end() ; sect++)
	{
		file << "[" + sect->first + "]";
		file << std::endl;

		Section &current = sect->second;
		Section::iterator keyword = current.begin();
		for(; keyword != current.end() ; keyword++)
		{
			file << (keyword->first + " = " + keyword->second + "\n");
		}
		file << std::endl;
	}
	file.close();
	return true;
}