From 42f7919c488d69a25557c73bdbe4d9e01a09deed Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Wed, 19 Aug 2015 04:43:54 +0200 Subject: [PATCH] cfg: Add virtual entry support --- core/cfg/cfg.cpp | 18 +--------- core/cfg/ini.cpp | 87 +++++++++++++++++++++++++++++---------------- core/cfg/ini.h | 26 ++++---------- core/oslib/logtest | Bin 0 -> 7952 bytes 4 files changed, 65 insertions(+), 66 deletions(-) create mode 100755 core/oslib/logtest 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 0000000000000000000000000000000000000000..92ca35fb7527a30fd26596dced51d08747968520 GIT binary patch literal 7952 zcmcIpeQaCR6~DIg)wHplQc9uSYCg&uSWQww2_IXZlQ?-PZj$Arh(Y?|+HT^_ACdjs zrq#w$(x6(wkZDxf_Q%vewh6(cb!ZzM6T@A%hHYpn2)1e)QZx;e(lQ0;x{5))bM8CG zd46$FrD<1sKKK02$36GHd+$5<`Wya0huvlqTE39u_hh3E!@6HGZmq}bkKQK)LrSgpY_6~ZF{ zw8L1(NIq6OEODk26vq*chwP9=yCY#XDlrJ=>b^h=sSrqKVA-mhqNtTedZO z(@F1E89(ab*mZUfN(&wj4{#Xg8hG$sqWsZ?Z=SAw=f;oza=4;C_~)AUYoB{^E!y$} z)vGQ!&|Fg>sUHImseAoDMP;>EqLjj$L` z{2KxvRJSYuQ711u)$H5*)}H`xGTi#1mr+od1LeaAilI{&e?IKfo{##&IboM?P6wVBtI|w#dR}Woigkj3Qbm2;&pk{wIC&|&XlH|?+nUtc6 z{jJkeQfIp2w=*y}g*kQBe|ZpU=Nqy1FxGCxS_o?!ur`Xd)mTeltp;oRpr%eAMbGMV zPPUVqT9D2CQO(ZI2eF#VNo4w{3}@PZSSS3~@at06PzYWVuX z>{JVAt^>ETQ};uy5o&7A?^d%@3b1N!suxLiN|js=wV_M0&1o6I^c02zz4?wQ(&@^f zN{@K)1P%an2b@xOnx%c^c98z!O_08Lc8N+osK~w>Gs*X$Zu;QrrvWt z^DZv1hlhNR_=bGDecGwLi}UqESa;GNEkPUY2IEalVkDeO#)Tdf{=UARKJlQhue+tLtYGzAl?gzS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