Esempio n. 1
0
	void config_cache::write_file(std::string path, const config& cfg)
	{
		scoped_ostream stream = ostream_file(path);
		const bool gzip = true;
		config_writer writer(*stream, gzip, game_config::cache_compression_level);
		writer.write(cfg);
	}
Esempio n. 2
0
void set_addon_info(const std::string& addon_name, const config& cfg)
{
	const std::string parentd = get_addon_campaigns_dir();

	scoped_ostream stream = ostream_file(parentd + "/" + addon_name + ".pbl");
	write(*stream, cfg);
}
Esempio n. 3
0
void write_preferences()
{
    #ifndef _WIN32

    bool prefs_file_existed = access(get_prefs_file().c_str(), F_OK) == 0;

    #endif

	try {
		scoped_ostream prefs_file = ostream_file(get_prefs_file());
		write(*prefs_file, prefs);
	} catch(io_exception&) {
		ERR_FS << "error writing to preferences file '" << get_prefs_file() << "'\n";
	}


    #ifndef _WIN32

    if(!prefs_file_existed) {

        if(chmod(get_prefs_file().c_str(), 0600) == -1) {
			ERR_FS << "error setting permissions of preferences file '" << get_prefs_file() << "'\n";
        }

    }

    #endif


}
Esempio n. 4
0
void save_index::write_save_index()
{
	log_scope("write_save_index()");
	try {
		scoped_ostream stream = ostream_file(get_save_index_file());
		write(*stream, load());
	} catch(io_exception& e) {
		ERR_SAVE << "error writing to save index file: '" << e.what() << "'\n";
	}
}
Esempio n. 5
0
// Throws game::save_game_failed
scoped_ostream savegame::open_save_game(const std::string &label)
{
	std::string name = label;
	replace_space2underbar(name);

	try {
		return scoped_ostream(ostream_file(get_saves_dir() + "/" + name));
	} catch(io_exception& e) {
		throw game::save_game_failed(e.what());
	}
}
static std::string create_random_sendfile(size_t size)
{
	char buffer[1024];
	const int buffer_size = sizeof(buffer)/sizeof(buffer[0]);
	int *begin = reinterpret_cast<int*>(&buffer[0]);
	int *end = begin + sizeof(buffer)/sizeof(int);
	std::string filename = "sendfile.tmp";
	scoped_ostream file = ostream_file(filename);
	std::generate(begin,end,std::rand);
	while( size > 0
		&& !file->bad())
	{
		file->write(buffer, buffer_size);
		size -= buffer_size;
	}
	return filename;
}
Esempio n. 7
0
	void config_cache::write_file(std::string path, const preproc_map& defines_map)
	{
		if (defines_map.empty())
		{
			if (file_exists(path))
			{
				delete_directory(path);
			}
			return;
		}
		scoped_ostream stream = ostream_file(path);
		const bool gzip = true;
		config_writer writer(*stream, gzip, game_config::cache_compression_level);

		// write all defines to stream
		BOOST_FOREACH(const preproc_map::value_type &define, defines_map) {
			define.second.write(writer, define.first);
		}
Esempio n. 8
0
rwops_ptr make_write_RWops(const std::string &path) {
	rwops_ptr rw(SDL_AllocRW(), &SDL_FreeRW);

	rw->size = &ofs_size;
	rw->seek = &ofs_seek;
	rw->read = &ofs_read;
	rw->write = &ofs_write;
	rw->close = &ofs_close;

	rw->type = write_type;

	scoped_ostream ofs = ostream_file(path);
	if(!ofs) {
		ERR_FS << "make_write_RWops: ostream_file returned NULL on " << path << '\n';
		rw.reset();
		return rw;
	}

	rw->hidden.unknown.data1 = ofs.release();

	return rw;
}
Esempio n. 9
0
bool persist_file_context::save_context() {
	bool success = false;

	std::string cfg_name = get_persist_cfg_name(namespace_.root_);
	if (!cfg_name.empty()) {
		if (cfg_.empty()) {
			success = delete_directory(cfg_name);
		} else {
			scoped_ostream out = ostream_file(cfg_name);
			if (!out->fail())
			{
				config_writer writer(*out,false);
				try {
					writer.write(cfg_);
					success = true;
				} catch(config::error &err) {
					LOG_PERSIST << err.message;
					success = false;
				}
			}
		}
	}
	return success;
}
Esempio n. 10
0
void set_addon_pbl_info(const std::string& addon_name, const config& cfg)
{
	scoped_ostream stream = ostream_file(get_pbl_file_path(addon_name));
	write(*stream, cfg);
}