From a3546484975a53f23721451ff89d86cedf6235e1 Mon Sep 17 00:00:00 2001 From: Dimitrije Jankov Date: Fri, 28 Feb 2014 15:32:38 +0100 Subject: [PATCH] Fix for Author: hikerstk Atm the user config.xml file is in UTF (since previously it stored the name of players which requires special characters). The player information is now stored in a separate file, so the config.xml can be written as ascii now (avoiding problems some people have that they can't see or edit the file) --- src/config/user_config.cpp | 117 +++++++++++++++++++------------------ src/config/user_config.hpp | 36 ++++++------ 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 50811c5e3..b054999d9 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -62,11 +62,11 @@ UserConfigParam::~UserConfigParam() * \param stream the xml writer. * \param level determines indentation level. */ -void UserConfigParam::writeInner(UTFWriter& stream, int level) const +void UserConfigParam::writeInner(std::ofstream& stream, int level) const { std::string tab(level * 4,' '); - stream << L" " << tab.c_str() << m_param_name.c_str() << L"=\"" - << toString() << L"\"\n"; + stream << " " << tab.c_str() << m_param_name.c_str() << "=\"" + << toString().c_str() << "\"\n"; } // writeInner // ============================================================================ @@ -89,7 +89,7 @@ GroupUserConfigParam::GroupUserConfigParam(const char* group_name, } // GroupUserConfigParam // ---------------------------------------------------------------------------- -void GroupUserConfigParam::write(UTFWriter& stream) const +void GroupUserConfigParam::write(std::ofstream& stream) const { const int attr_amount = m_attributes.size(); @@ -98,41 +98,41 @@ void GroupUserConfigParam::write(UTFWriter& stream) const for(int n=0; nm_comment.size() > 0) - stream << L"\n " << m_attributes[n]->m_param_name.c_str() - << L" : " << m_attributes[n]->m_comment.c_str(); + stream << "\n " << m_attributes[n]->m_param_name.c_str() + << " : " << m_attributes[n]->m_comment.c_str(); } - stream << L" -->\n <" << m_param_name.c_str() << "\n"; + stream << " -->\n <" << m_param_name.c_str() << "\n"; // actual values for (int n=0; nwriteInner(stream, 1); } - stream << L" >\n"; + stream << " >\n"; const int children_amount = m_children.size(); for (int n=0; nwriteInner(stream, 1); } - stream << L" \n\n"; + stream << " \n\n"; } // write // ---------------------------------------------------------------------------- -void GroupUserConfigParam::writeInner(UTFWriter& stream, int level) const +void GroupUserConfigParam::writeInner(std::ofstream& stream, int level) const { std::string tab(level * 4,' '); for(int i = 0; i < level; i++) tab =+ " "; const int children_amount = m_attributes.size(); - stream << L" " << tab.c_str() << "<" << m_param_name.c_str() << "\n"; + stream << " " << tab.c_str() << "<" << m_param_name.c_str() << "\n"; // actual values for (int n=0; nwriteInner(stream, level+1); } - stream << L" " << tab.c_str() << "/>\n"; + stream << " " << tab.c_str() << "/>\n"; } // writeInner // ---------------------------------------------------------------------------- @@ -160,7 +160,7 @@ void GroupUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node) } // findYourDataInAnAttributeOf // ---------------------------------------------------------------------------- -irr::core::stringw GroupUserConfigParam::toString() const +irr::core::stringc GroupUserConfigParam::toString() const { return ""; } // toString @@ -246,22 +246,22 @@ ListUserConfigParam::ListUserConfigParam(const char* param_name, // ---------------------------------------------------------------------------- template -void ListUserConfigParam::write(UTFWriter& stream) const +void ListUserConfigParam::write(std::ofstream& stream) const { const int elts_amount = m_elements.size(); // comment if(m_comment.size() > 0) stream << " \n <" << m_param_name.c_str() << "\n"; + stream << " -->\n <" << m_param_name.c_str() << "\n"; - stream << L" Size=\"" << elts_amount << "\"\n"; + stream << " Size=\"" << elts_amount << "\"\n"; // actual elements for (int n=0; n\n"; - stream << L" \n\n"; + stream << " >\n"; + stream << " \n\n"; } // write // ---------------------------------------------------------------------------- @@ -319,7 +319,7 @@ void ListUserConfigParam::addElement(T element) // ---------------------------------------------------------------------------- template -irr::core::stringw ListUserConfigParam::toString() const +core::stringc ListUserConfigParam::toString() const { return ""; } // toString @@ -352,19 +352,20 @@ IntUserConfigParam::IntUserConfigParam(int default_value, } // IntUserConfigParam // ---------------------------------------------------------------------------- -void IntUserConfigParam::write(UTFWriter& stream) const +void IntUserConfigParam::write(std::ofstream& stream) const { - if(m_comment.size() > 0) stream << L" \n"; - stream << L" <" << m_param_name.c_str() << L" value=\"" << m_value - << L"\" />\n\n"; + if(m_comment.size() > 0) stream << " \n"; + stream << " <" << m_param_name.c_str() << " value=\"" << m_value + << "\" />\n\n"; } // write // ---------------------------------------------------------------------------- -irr::core::stringw IntUserConfigParam::toString() const +irr::core::stringc IntUserConfigParam::toString() const { - irr::core::stringw tmp; + irr::core::stringc tmp; tmp += m_value; + return tmp; } // toString @@ -414,18 +415,18 @@ TimeUserConfigParam::TimeUserConfigParam(StkTime::TimeType default_value, } // TimeUserConfigParam // ---------------------------------------------------------------------------- -void TimeUserConfigParam::write(UTFWriter& stream) const +void TimeUserConfigParam::write(std::ofstream& stream) const { - if(m_comment.size() > 0) stream << L" \n"; + if(m_comment.size() > 0) stream << " \n"; std::ostringstream o; o<\n\n"; + stream << " <" << m_param_name.c_str() << " value=\"" + << o.str().c_str() << "\" />\n\n"; } // write // ---------------------------------------------------------------------------- -irr::core::stringw TimeUserConfigParam::toString() const +irr::core::stringc TimeUserConfigParam::toString() const { // irrString does not have a += with a 64-bit int type, so // we can't use an irrlicht's stringw directly. Since it's only a @@ -433,7 +434,7 @@ irr::core::stringw TimeUserConfigParam::toString() const std::ostringstream o; o< 0) stream << L" \n"; - stream << L" <" << m_param_name.c_str() << L" value=\"" - << m_value.c_str() << L"\" />\n\n"; + if(m_comment.size() > 0) stream << " \n"; + stream << " <" << m_param_name.c_str() << " value=\"" + << m_value.c_str() << "\" />\n\n"; } // write // ---------------------------------------------------------------------------- @@ -537,12 +538,12 @@ BoolUserConfigParam::BoolUserConfigParam(bool default_value, // ---------------------------------------------------------------------------- -void BoolUserConfigParam::write(UTFWriter& stream) const +void BoolUserConfigParam::write(std::ofstream& stream) const { - if(m_comment.size() > 0) stream << L" \n"; - stream << L" <" << m_param_name.c_str() << L" value=\"" - << (m_value ? L"true" : L"false" ) << L"\" />\n\n"; + if(m_comment.size() > 0) stream << " \n"; + stream << " <" << m_param_name.c_str() << " value=\"" + << (m_value ? "true" : "false" ) << "\" />\n\n"; } // write // ---------------------------------------------------------------------------- @@ -591,9 +592,9 @@ void BoolUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node) } // findYourDataInAnAttributeOf // ---------------------------------------------------------------------------- -irr::core::stringw BoolUserConfigParam::toString() const +irr::core::stringc BoolUserConfigParam::toString() const { - return (m_value ? L"true" : L"false" ); + return (m_value ? "true" : "false" ); } // toString // ============================================================================ @@ -624,12 +625,12 @@ FloatUserConfigParam::FloatUserConfigParam(float default_value, } // FloatUserConfigParam // ---------------------------------------------------------------------------- -void FloatUserConfigParam::write(UTFWriter& stream) const +void FloatUserConfigParam::write(std::ofstream& stream) const { - if(m_comment.size() > 0) stream << L" \n"; - stream << L" <" << m_param_name.c_str() << L" value=\"" << m_value - << L"\" />\n\n"; + if(m_comment.size() > 0) stream << " \n"; + stream << " <" << m_param_name.c_str() << " value=\"" << m_value + << "\" />\n\n"; } // write // ---------------------------------------------------------------------------- @@ -648,9 +649,9 @@ void FloatUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node) } // findYourDataInAnAttributeOf // ---------------------------------------------------------------------------- -irr::core::stringw FloatUserConfigParam::toString() const +core::stringc FloatUserConfigParam::toString() const { - irr::core::stringw tmp; + irr::core::stringc tmp; tmp += m_value; return tmp; } // toString @@ -751,11 +752,11 @@ void UserConfig::saveConfig() try { - UTFWriter configfile(filename.c_str()); + std::ofstream configfile (filename.c_str(), std::ofstream::out); - configfile << L"\n"; - configfile << L"\n\n"; + configfile << "\n"; + configfile << "\n\n"; const int paramAmount = all_params.size(); for(int i=0; i\n"; + configfile << "\n"; configfile.close(); } catch (std::runtime_error& e) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index dba5855dd..10affd8ae 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -68,11 +68,11 @@ protected: std::string m_comment; public: virtual ~UserConfigParam(); - virtual void write(UTFWriter& stream) const = 0; - virtual void writeInner(UTFWriter& stream, int level = 0) const; + virtual void write(std::ofstream & stream) const = 0; + virtual void writeInner(std::ofstream & stream, int level = 0) const; virtual void findYourDataInAChildOf(const XMLNode* node) = 0; virtual void findYourDataInAnAttributeOf(const XMLNode* node) = 0; - virtual irr::core::stringw toString() const = 0; + virtual irr::core::stringc toString() const = 0; }; // UserConfigParam // ============================================================================ @@ -85,8 +85,8 @@ public: GroupUserConfigParam(const char* param_name, GroupUserConfigParam* group, const char* comment = NULL); - void write(UTFWriter& stream) const; - void writeInner(UTFWriter& stream, int level = 0) const; + void write(std::ofstream& stream) const; + void writeInner(std::ofstream& stream, int level = 0) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -94,7 +94,7 @@ public: void addChild(GroupUserConfigParam* child); void clearChildren(); - irr::core::stringw toString() const; + irr::core::stringc toString() const; }; // GroupUserConfigParam // ============================================================================ @@ -119,13 +119,13 @@ public: int nb_elts, ...); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); void addElement(T element); - irr::core::stringw toString() const; + irr::core::stringc toString() const; operator std::vector() const { return m_elements; } @@ -150,11 +150,11 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); - irr::core::stringw toString() const; + irr::core::stringc toString() const; void revertToDefaults() { m_value = m_default_value; } operator int() const { return m_value; } @@ -177,11 +177,11 @@ public: TimeUserConfigParam(StkTime::TimeType default_value, const char* param_name, GroupUserConfigParam* group, const char* comment=NULL); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); - irr::core::stringw toString() const; + irr::core::stringc toString() const; void revertToDefaults() { m_value = m_default_value; } operator StkTime::TimeType() const { return m_value; } StkTime::TimeType& operator=(const StkTime::TimeType& v) @@ -204,7 +204,7 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -212,7 +212,7 @@ public: std::string getDefaultValue() const { return m_default_value; } - irr::core::stringw toString() const { return m_value.c_str(); } + irr::core::stringc toString() const { return m_value.c_str(); } operator std::string() const { return m_value; } std::string& operator=(const std::string& v) @@ -235,11 +235,11 @@ public: BoolUserConfigParam(bool default_value, const char* param_name, GroupUserConfigParam* group, const char* comment = NULL); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); - irr::core::stringw toString() const; + irr::core::stringc toString() const; void revertToDefaults() { m_value = m_default_value; } operator bool() const { return m_value; } @@ -261,11 +261,11 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(UTFWriter& stream) const; + void write(std::ofstream& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); - irr::core::stringw toString() const; + irr::core::stringc toString() const; void revertToDefaults() { m_value = m_default_value; } operator float() const { return m_value; }