コード例 #1
0
void persist_file_context::load()
{
	std::string cfg_name = get_persist_cfg_name(namespace_.root_);
	if (filesystem::file_exists(cfg_name) && !filesystem::is_directory(cfg_name)) {
		filesystem::scoped_istream file_stream = filesystem::istream_file(cfg_name);
		if (!(file_stream->fail())) {
			try {
				read(cfg_,*file_stream);
			} catch (config::error &err) {
				LOG_PERSIST << err.message << std::endl;
			}
		}
	}
}
コード例 #2
0
void persist_file_context::load() {
	std::string cfg_dir = get_dir(get_user_data_dir() + "/persist");

	std::string cfg_name = get_persist_cfg_name(namespace_.root_);
	if (file_exists(cfg_name) && !is_directory(cfg_name)) {
		scoped_istream file_stream = istream_file(cfg_name);
		if (!(file_stream->fail())) {
			try {
				read(cfg_,*file_stream);
			} catch (config::error &err) {
				LOG_PERSIST << err.message;
			}
		}
	}
}
コード例 #3
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;
}