Ran umcpropfix.
This commit is contained in:
parent
54c3e1d98d
commit
fdca91028e
1 changed files with 85 additions and 85 deletions
|
@ -1,85 +1,85 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2010 by Jody Northup
|
Copyright (C) 2010 by Jody Northup
|
||||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License version 2
|
it under the terms of the GNU General Public License version 2
|
||||||
or at your option any later version.
|
or at your option any later version.
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY.
|
but WITHOUT ANY WARRANTY.
|
||||||
|
|
||||||
See the COPYING file for more details.
|
See the COPYING file for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "filesystem.hpp"
|
#include "filesystem.hpp"
|
||||||
#include "persist_context.hpp"
|
#include "persist_context.hpp"
|
||||||
#include "persist_manager.hpp"
|
#include "persist_manager.hpp"
|
||||||
#include "serialization/binary_or_text.hpp"
|
#include "serialization/binary_or_text.hpp"
|
||||||
|
|
||||||
static std::string get_persist_cfg_name(const std::string &name_space) {
|
static std::string get_persist_cfg_name(const std::string &name_space) {
|
||||||
return (get_dir(get_user_data_dir() + "/persist/") + name_space + ".cfg");
|
return (get_dir(get_user_data_dir() + "/persist/") + name_space + ".cfg");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool persist_manager::save_data(const std::string &name_space, config &cfg) {
|
bool persist_manager::save_data(const std::string &name_space, config &cfg) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
std::string cfg_name = get_persist_cfg_name(name_space);
|
std::string cfg_name = get_persist_cfg_name(name_space);
|
||||||
if (!cfg_name.empty()) {
|
if (!cfg_name.empty()) {
|
||||||
if (cfg.empty()) {
|
if (cfg.empty()) {
|
||||||
success = delete_directory(cfg_name);
|
success = delete_directory(cfg_name);
|
||||||
} else {
|
} else {
|
||||||
scoped_ostream out = ostream_file(cfg_name);
|
scoped_ostream out = ostream_file(cfg_name);
|
||||||
if (!out->fail())
|
if (!out->fail())
|
||||||
{
|
{
|
||||||
config_writer writer(*out,false);
|
config_writer writer(*out,false);
|
||||||
try {
|
try {
|
||||||
writer.write(cfg);
|
writer.write(cfg);
|
||||||
success = true;
|
success = true;
|
||||||
} catch(config::error &err) {
|
} catch(config::error &err) {
|
||||||
LOG_SAVE << err.message;
|
LOG_SAVE << err.message;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool persist_manager::load_data(const std::string &name_space, config &cfg, const bool create_if_missing) {
|
bool persist_manager::load_data(const std::string &name_space, config &cfg, const bool create_if_missing) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
std::string cfg_dir = get_dir(get_user_data_dir() + "/persist");
|
std::string cfg_dir = get_dir(get_user_data_dir() + "/persist");
|
||||||
create_directory_if_missing(cfg_dir);
|
create_directory_if_missing(cfg_dir);
|
||||||
|
|
||||||
std::string cfg_name = get_persist_cfg_name(name_space);
|
std::string cfg_name = get_persist_cfg_name(name_space);
|
||||||
if (!cfg_name.empty()) {
|
if (!cfg_name.empty()) {
|
||||||
scoped_istream file_stream = istream_file(cfg_name);
|
scoped_istream file_stream = istream_file(cfg_name);
|
||||||
if (file_stream->fail()) {
|
if (file_stream->fail()) {
|
||||||
if (create_if_missing) {
|
if (create_if_missing) {
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
detect_format_and_read(cfg,*file_stream);
|
detect_format_and_read(cfg,*file_stream);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (config::error &err) {
|
} catch (config::error &err) {
|
||||||
LOG_SAVE << err.message;
|
LOG_SAVE << err.message;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
persist_context &persist_manager::get_context(const std::string &ns)
|
persist_context &persist_manager::get_context(const std::string &ns)
|
||||||
{
|
{
|
||||||
persist_context::name_space name(ns,true);
|
persist_context::name_space name(ns,true);
|
||||||
std::string key(name.root_);
|
std::string key(name.root_);
|
||||||
context_map::iterator i = contexts_.find(key);
|
context_map::iterator i = contexts_.find(key);
|
||||||
if (i == contexts_.end()) {
|
if (i == contexts_.end()) {
|
||||||
contexts_[key] = new persist_context(key);
|
contexts_[key] = new persist_context(key);
|
||||||
}
|
}
|
||||||
persist_context *ret = contexts_[key];
|
persist_context *ret = contexts_[key];
|
||||||
if (ret->get_node() != ns)
|
if (ret->get_node() != ns)
|
||||||
ret->set_node(name.descendants_);
|
ret->set_node(name.descendants_);
|
||||||
return *ret;
|
return *ret;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue