diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index e5c10f885..e308d4b4f 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -10,15 +10,6 @@ string cfgPath; -struct vitem -{ - string s; - string n; - string v; - vitem(string a,string b,string c){s=a;n=b;v=c;} -}; -vector vlist; - ConfigFile cfgdb; void savecfgf() @@ -98,11 +89,6 @@ bool cfgOpen() cfgdb.parse(cfgfile); - /*for (size_t i=0;iSetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); - }*/ - if (cfgfile) { cfgdb.save(cfgfile); @@ -160,7 +146,5 @@ s32 cfgLoadInt(const wchar * Section, const wchar * Key,s32 Default) void cfgSetVirtual(const wchar * Section, const wchar * Key, const wchar * String) { - //vlist.push_back(vitem(Section,Key,String)); - //cfgdb.GetEntry(Section,CEM_VIRTUAL)->SetEntry(Key,String,CEM_VIRTUAL); + cfgdb.set(string(Section), string(Key), string(String), true); } - diff --git a/core/cfg/ini.cpp b/core/cfg/ini.cpp index b900aada6..e155228ae 100644 --- a/core/cfg/ini.cpp +++ b/core/cfg/ini.cpp @@ -53,49 +53,76 @@ ConfigEntry* ConfigSection::get_entry(string name) return NULL; }; -void ConfigSection::set(string name, string value, int flags) +void ConfigSection::set(string name, string value) { - ConfigEntry new_entry = { value, flags }; + ConfigEntry new_entry = { value }; this->entries[name] = new_entry; }; /* ConfigFile */ -bool ConfigFile::has_section(string name) -{ - return (this->sections.count(name) == 1); -}; - -bool ConfigFile::has_entry(string section_name, string entry_name) -{ - ConfigSection* section = this->get_section(section_name); - return ((section != NULL) && section->has_entry(entry_name)); -} - -ConfigSection* ConfigFile::add_section(string name) +ConfigSection* ConfigFile::add_section(string name, bool is_virtual) { ConfigSection new_section; + if (is_virtual) + { + this->virtual_sections.insert(std::make_pair(name, new_section)); + return &this->virtual_sections[name]; + } this->sections.insert(std::make_pair(name, new_section)); return &this->sections[name]; }; -ConfigSection* ConfigFile::get_section(string name) +bool ConfigFile::has_section(string name) { - if(this->has_section(name)) + return (this->virtual_sections.count(name) == 1 || this->sections.count(name) == 1); +} + +bool ConfigFile::has_entry(string section_name, string entry_name) +{ + ConfigSection* section = this->get_section(section_name, true); + if ((section != NULL) && section->has_entry(entry_name)) { - return &this->sections[name]; + return true; + } + section = this->get_section(section_name, false); + return ((section != NULL) && section->has_entry(entry_name)); +} + +ConfigSection* ConfigFile::get_section(string name, bool is_virtual) +{ + if(is_virtual) + { + if (this->virtual_sections.count(name) == 1) + { + return &this->virtual_sections[name]; + } + } + else + { + if (this->sections.count(name) == 1) + { + return &this->sections[name]; + } } return NULL; }; ConfigEntry* ConfigFile::get_entry(string section_name, string entry_name) { - ConfigSection* section = this->get_section(section_name); - if(section == NULL) + ConfigSection* section = this->get_section(section_name, true); + if(section != NULL) { - return NULL; + return section->get_entry(entry_name); } - return section->get_entry(entry_name); + + section = this->get_section(section_name, false); + if(section != NULL) + { + return section->get_entry(entry_name); + } + return NULL; + } string ConfigFile::get(string section_name, string entry_name, string default_value) @@ -137,27 +164,27 @@ bool ConfigFile::get_bool(string section_name, string entry_name, bool default_v } } -void ConfigFile::set(string section_name, string entry_name, string value, int flags) +void ConfigFile::set(string section_name, string entry_name, string value, bool is_virtual) { - ConfigSection* section = this->get_section(section_name); + ConfigSection* section = this->get_section(section_name, is_virtual); if(section == NULL) { - section = this->add_section(section_name); + section = this->add_section(section_name, is_virtual); } - section->set(entry_name, value, flags); + section->set(entry_name, value); }; -void ConfigFile::set_int(string section_name, string entry_name, int value, int flags) +void ConfigFile::set_int(string section_name, string entry_name, int value, bool is_virtual) { std::stringstream str_value; str_value << value; - this->set(section_name, entry_name, str_value.str()); + this->set(section_name, entry_name, str_value.str(), is_virtual); } -void ConfigFile::set_bool(string section_name, string entry_name, bool value, int flags) +void ConfigFile::set_bool(string section_name, string entry_name, bool value, bool is_virtual) { string str_value = (value ? "yes" : "no"); - this->set(section_name, entry_name, str_value); + this->set(section_name, entry_name, str_value, is_virtual); } void ConfigFile::parse(FILE* file) @@ -237,6 +264,7 @@ void ConfigFile::save(FILE* file) { string section_name = section_it->first; ConfigSection section = section_it->second; + fprintf(file, "[%s]\n", section_name.c_str()); for(std::map::iterator entry_it = section.entries.begin(); @@ -250,4 +278,3 @@ void ConfigFile::save(FILE* file) fputs("\n", file); } } - diff --git a/core/cfg/ini.h b/core/cfg/ini.h index cc0f53d76..8cbc80d46 100644 --- a/core/cfg/ini.h +++ b/core/cfg/ini.h @@ -2,21 +2,8 @@ #include "types.h" #include -//A config remains virtual only as long as a write at it -//doesn't override the virtual value.While a config is virtual, a copy of its 'real' value is held and preserved - -//Is this a virtual entry ? -#define CEM_VIRTUAL 1 -//Should the value be saved ? -#define CEM_SAVE 2 -//is this entry readonly ? -#define CEM_READONLY 4 -//the move is from loading ? -#define CEM_LOAD 8 - struct ConfigEntry { string value; - int flags; //TODO: These have no effect right now string get_string(); int get_int(); bool get_bool(); @@ -25,15 +12,16 @@ struct ConfigEntry { struct ConfigSection { std::map entries; bool has_entry(string name); - void set(string name, string value, int flags); + void set(string name, string value); ConfigEntry* get_entry(string name); }; struct ConfigFile { private: std::map sections; - ConfigSection* add_section(string name); - ConfigSection* get_section(string name); + std::map virtual_sections; + ConfigSection* add_section(string name, bool is_virtual); + ConfigSection* get_section(string name, bool is_virtual); ConfigEntry* get_entry(string section_name, string entry_name); @@ -49,7 +37,7 @@ struct ConfigFile { int get_int(string section_name, string entry_name, int default_value = 0); bool get_bool(string section_name, string entry_name, bool default_value = false); /* setting values */ - void set(string section_name, string entry_name, string value, int flags = 0); - void set_int(string section_name, string entry_name, int value, int flags = 0); - void set_bool(string section_name, string entry_name, bool value, int flags = 0); + void set(string section_name, string entry_name, string value, bool is_virtual = false); + void set_int(string section_name, string entry_name, int value, bool is_virtual = false); + void set_bool(string section_name, string entry_name, bool value, bool is_virtual = false); }; diff --git a/core/oslib/logtest b/core/oslib/logtest new file mode 100755 index 000000000..92ca35fb7 Binary files /dev/null and b/core/oslib/logtest differ