From f1ec7050677c5cb45e3c3c3190a74759ba6448dc Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 18:51:44 +0200 Subject: [PATCH 1/7] cfg: Move actual file parsing code into ParseFile method --- core/cfg/cfg.cpp | 128 ++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index d7dc0b8fb..5a2238f53 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -21,6 +21,16 @@ string cfgPath; //the move is from loading ? #define CEM_LOAD 8 +struct vitem +{ + string s; + string n; + string v; + vitem(string a,string b,string c){s=a;n=b;v=c;} +}; +vector vlist; +wchar* trim_ws(wchar* str); + struct ConfigEntry { ConfigEntry(ConfigEntry* pp) @@ -197,7 +207,56 @@ struct ConfigFile void ParseFile(FILE* file) { - + wchar line[512]; + wchar cur_sect[512]={0}; + int cline=0; + while(file && !feof(file)) + { + fgets(line,512,file); + if (feof(file)) + break; + + cline++; + + if (strlen(line)<3) + continue; + if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') + line[strlen(line)-1]=0; + + wchar* tl=trim_ws(line); + if (tl[0]=='[' && tl[strlen(tl)-1]==']') + { + tl[strlen(tl)-1]=0; + strcpy(cur_sect,tl+1); + trim_ws(cur_sect); + } + else + { + if (cur_sect[0]==0) + continue;//no open section + wchar* str1=strstr(tl,"="); + if (!str1) + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + continue; + } + *str1=0; + str1++; + wchar* v=trim_ws(str1); + wchar* k=trim_ws(tl); + if (v && k) + { + ConfigSection*cs=this->GetEntry(cur_sect); + + //if (!cs->FindEntry(k)) + cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); + } + else + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + } + } + } } void SaveFile(FILE* file) { @@ -277,15 +336,6 @@ void cfgSaveStr(const wchar * Section, const wchar * Key, const wchar * String) ** This will verify there is a working file @ ./szIniFn ** - if not present, it will write defaults */ -struct vitem -{ - string s; - string n; - string v; - vitem(string a,string b,string c){s=a;n=b;v=c;} -}; -vector vlist; -wchar* trim_ws(wchar* str); bool cfgOpen() { @@ -305,61 +355,13 @@ bool cfgOpen() } } - wchar line[512]; - wchar cur_sect[512]={0}; - int cline=0; - while(cfgfile && !feof(cfgfile)) - { - fgets(line,512,cfgfile); - if (feof(cfgfile)) - break; + cfgdb.ParseFile(cfgfile); - cline++; + for (size_t i=0;iSetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); + } - if (strlen(line)<3) - continue; - if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') - line[strlen(line)-1]=0; - - wchar* tl=trim_ws(line); - if (tl[0]=='[' && tl[strlen(tl)-1]==']') - { - tl[strlen(tl)-1]=0; - strcpy(cur_sect,tl+1); - trim_ws(cur_sect); - } - else - { - if (cur_sect[0]==0) - continue;//no open section - wchar* str1=strstr(tl,"="); - if (!str1) - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - continue; - } - *str1=0; - str1++; - wchar* v=trim_ws(str1); - wchar* k=trim_ws(tl); - if (v && k) - { - ConfigSection*cs=cfgdb.GetEntry(cur_sect); - - //if (!cs->FindEntry(k)) - cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); - } - else - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - } - } - } - - for (size_t i=0;iSetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); - } if (cfgfile) { cfgdb.SaveFile(cfgfile); From 78091577ea1b631fa58cc3613eecca954ced12b4 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 19:09:22 +0200 Subject: [PATCH 2/7] cfg: Move more code into the ConfigFile class --- core/cfg/cfg.cpp | 122 +++++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index 5a2238f53..39312c9ae 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -276,6 +276,72 @@ struct ConfigFile stuff[i]->SaveFile(file); } } + s32 Exists(const wchar * Section, const wchar * Key) + { + if (Section==0) + return -1; + //return cfgRead(Section,Key,0); + ConfigSection*cs= this->FindSection(Section); + if (cs == 0) + return 0; + + if (Key==0) + return 1; + + ConfigEntry* ce=cs->FindEntry(Key); + if (ce!=0) + return 2; + else + return 0; + } + void LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) + { + verify(Section!=0 && strlen(Section)!=0); + verify(Key!=0 && strlen(Key)!=0); + verify(Return!=0); + if (Default==0) + Default=""; + ConfigSection* cs= this->GetEntry(Section); + ConfigEntry* ce=cs->FindEntry(Key); + if (!ce) + { + cs->SetEntry(Key,Default,CEM_SAVE); + strcpy(Return,Default); + } + else + { + strcpy(Return,ce->GetValue().c_str()); + } + } + + string LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) + { + verify(Section != 0 && strlen(Section) != 0); + verify(Key != 0 && strlen(Key) != 0); + + if (Default == 0) + Default = ""; + ConfigSection* cs = this->GetEntry(Section); + ConfigEntry* ce = cs->FindEntry(Key); + if (!ce) + { + cs->SetEntry(Key, Default, CEM_SAVE); + return Default; + } + else + { + return ce->GetValue(); + } + } + + s32 LoadInt(const wchar * Section, const wchar * Key,s32 Default) + { + wchar temp_d[30]; + wchar temp_o[30]; + sprintf(temp_d,"%d",Default); + cfgLoadStr(Section,Key,temp_o,temp_d); + return atoi(temp_o); + } }; ConfigFile cfgdb; @@ -378,70 +444,22 @@ bool cfgOpen() //2 : found section & key s32 cfgExists(const wchar * Section, const wchar * Key) { - if (Section==0) - return -1; - //return cfgRead(Section,Key,0); - ConfigSection*cs= cfgdb.FindSection(Section); - if (cs == 0) - return 0; - - if (Key==0) - return 1; - - ConfigEntry* ce=cs->FindEntry(Key); - if (ce!=0) - return 2; - else - return 0; + return cfgdb.Exists(Section, Key); } void cfgLoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) { - verify(Section!=0 && strlen(Section)!=0); - verify(Key!=0 && strlen(Key)!=0); - verify(Return!=0); - if (Default==0) - Default=""; - ConfigSection* cs= cfgdb.GetEntry(Section); - ConfigEntry* ce=cs->FindEntry(Key); - if (!ce) - { - cs->SetEntry(Key,Default,CEM_SAVE); - strcpy(Return,Default); - } - else - { - strcpy(Return,ce->GetValue().c_str()); - } + return cfgdb.LoadStr(Section, Key, Return, Default); } string cfgLoadStr(const wchar * Section, const wchar * Key, const wchar* Default) { - verify(Section != 0 && strlen(Section) != 0); - verify(Key != 0 && strlen(Key) != 0); - - if (Default == 0) - Default = ""; - ConfigSection* cs = cfgdb.GetEntry(Section); - ConfigEntry* ce = cs->FindEntry(Key); - if (!ce) - { - cs->SetEntry(Key, Default, CEM_SAVE); - return Default; - } - else - { - return ce->GetValue(); - } + return cfgdb.LoadStr(Section, Key, Default); } //These are helpers , mainly :) s32 cfgLoadInt(const wchar * Section, const wchar * Key,s32 Default) { - wchar temp_d[30]; - wchar temp_o[30]; - sprintf(temp_d,"%d",Default); - cfgLoadStr(Section,Key,temp_o,temp_d); - return atoi(temp_o); + return cfgdb.LoadInt(Section, Key, Default); } void cfgSaveInt(const wchar * Section, const wchar * Key, s32 Int) From 60e094dbb9efba741dbcfc006da1bec4a6482afe Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 20:25:08 +0200 Subject: [PATCH 3/7] cfg: Make ConfigFile reusable --- core/cfg/cfg.cpp | 59 ++++++++++++++++-------------------------------- core/cfg/cfg.h | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index 39312c9ae..4c7ee30d1 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -31,48 +31,32 @@ struct vitem vector vlist; wchar* trim_ws(wchar* str); -struct ConfigEntry -{ - ConfigEntry(ConfigEntry* pp) +ConfigEntry::ConfigEntry(ConfigEntry* pp) { next=pp; flags=0; } - - - u32 flags; - string name; - string value; - string valueVirtual; - ConfigEntry* next; - void SaveFile(FILE* file) +void ConfigEntry::SaveFile(FILE* file) { if (flags & CEM_SAVE) fprintf(file,"%s=%s\n",name.c_str(),value.c_str()); } - string GetValue() +string ConfigEntry::GetValue() { if (flags&CEM_VIRTUAL) return valueVirtual; else return value; } -}; -struct ConfigSection -{ - u32 flags; - string name; - ConfigEntry* entrys; - ConfigSection* next; - - ConfigSection(ConfigSection* pp) + +ConfigSection::ConfigSection(ConfigSection* pp) { next=pp; flags=0; entrys=0; } - ConfigEntry* FindEntry(string name) +ConfigEntry* ConfigSection::FindEntry(string name) { ConfigEntry* c= entrys; while(c) @@ -83,7 +67,7 @@ struct ConfigSection } return 0; } - void SetEntry(string name,string value,u32 eflags) +void ConfigSection::SetEntry(string name,string value,u32 eflags) { ConfigEntry* c=FindEntry(name); if (c) @@ -131,7 +115,7 @@ struct ConfigSection } } - ~ConfigSection() +ConfigSection::~ConfigSection() { ConfigEntry* n=entrys; @@ -142,7 +126,7 @@ struct ConfigSection delete p; } } - void SaveFile(FILE* file) +void ConfigSection::SaveFile(FILE* file) { if (flags&CEM_SAVE) { @@ -167,11 +151,7 @@ struct ConfigSection } } -}; -struct ConfigFile -{ - ConfigSection* entrys; - ConfigSection* FindSection(string name) +ConfigSection* ConfigFile::FindSection(string name) { ConfigSection* c= entrys; while(c) @@ -182,7 +162,7 @@ struct ConfigFile } return 0; } - ConfigSection* GetEntry(string name) +ConfigSection* ConfigFile::GetEntry(string name) { ConfigSection* c=FindSection(name); if (!c) @@ -193,7 +173,7 @@ struct ConfigFile return c; } - ~ConfigFile() +ConfigFile::~ConfigFile() { ConfigSection* n=entrys; @@ -205,7 +185,7 @@ struct ConfigFile } } - void ParseFile(FILE* file) +void ConfigFile::ParseFile(FILE* file) { wchar line[512]; wchar cur_sect[512]={0}; @@ -258,7 +238,7 @@ struct ConfigFile } } } - void SaveFile(FILE* file) +void ConfigFile::SaveFile(FILE* file) { vector stuff; @@ -276,7 +256,7 @@ struct ConfigFile stuff[i]->SaveFile(file); } } - s32 Exists(const wchar * Section, const wchar * Key) +s32 ConfigFile::Exists(const wchar * Section, const wchar * Key) { if (Section==0) return -1; @@ -294,7 +274,7 @@ struct ConfigFile else return 0; } - void LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) +void ConfigFile::LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) { verify(Section!=0 && strlen(Section)!=0); verify(Key!=0 && strlen(Key)!=0); @@ -314,7 +294,7 @@ struct ConfigFile } } - string LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) +string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) { verify(Section != 0 && strlen(Section) != 0); verify(Key != 0 && strlen(Key) != 0); @@ -334,15 +314,14 @@ struct ConfigFile } } - s32 LoadInt(const wchar * Section, const wchar * Key,s32 Default) +s32 ConfigFile::LoadInt(const wchar * Section, const wchar * Key,s32 Default) { wchar temp_d[30]; wchar temp_o[30]; sprintf(temp_d,"%d",Default); - cfgLoadStr(Section,Key,temp_o,temp_d); + this->LoadStr(Section,Key,temp_o,temp_d); return atoi(temp_o); } -}; ConfigFile cfgdb; diff --git a/core/cfg/cfg.h b/core/cfg/cfg.h index 3278ed777..fe8fa6368 100644 --- a/core/cfg/cfg.h +++ b/core/cfg/cfg.h @@ -19,3 +19,42 @@ s32 cfgExists(const wchar * Section, const wchar * Key); void cfgSetVirtual(const wchar * lpSection, const wchar * lpKey, const wchar * lpString); bool ParseCommandLine(int argc,wchar* argv[]); + +struct ConfigEntry +{ + u32 flags; + string name; + string value; + string valueVirtual; + ConfigEntry* next; + ConfigEntry(ConfigEntry*); + string GetValue(); + void SaveFile(FILE*); +}; + +struct ConfigSection +{ + u32 flags; + string name; + ConfigEntry* entrys; + ConfigSection* next; + ~ConfigSection(); + ConfigSection(ConfigSection*); + ConfigEntry* FindEntry(string); + void SetEntry(string, string, u32); + void SaveFile(FILE*); +}; + +struct ConfigFile +{ + ConfigSection* entrys; + ~ConfigFile(); + void ParseFile(FILE*); + void SaveFile(FILE*); + ConfigSection* FindSection(string); + ConfigSection* GetEntry(string); + s32 Exists(const wchar *, const wchar *); + void LoadStr(const wchar *, const wchar *, wchar *,const wchar*); + string LoadStr(const wchar *, const wchar *, const wchar*); + s32 LoadInt(const wchar *, const wchar *,s32); +}; \ No newline at end of file From 87f7ca0bb4592c3d100a6343c38d30f49669cab9 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 21:05:47 +0200 Subject: [PATCH 4/7] cfg: Allow LoadInt to parse hex strings --- core/cfg/cfg.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index 4c7ee30d1..3822fb5aa 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -320,7 +320,14 @@ s32 ConfigFile::LoadInt(const wchar * Section, const wchar * Key,s32 Default) wchar temp_o[30]; sprintf(temp_d,"%d",Default); this->LoadStr(Section,Key,temp_o,temp_d); - return atoi(temp_o); + if (strstr(temp_o, "0x") != NULL) + { + return strtol(temp_o, NULL, 16); + } + else + { + return atoi(temp_o); + } } ConfigFile cfgdb; From 8744516e52abc8a6e91020e62941e19d3fc798d4 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 21:17:47 +0200 Subject: [PATCH 5/7] cfg: Remove redundant code --- core/cfg/cfg.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index 3822fb5aa..fe3b79ae2 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -276,22 +276,9 @@ s32 ConfigFile::Exists(const wchar * Section, const wchar * Key) } void ConfigFile::LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) { - verify(Section!=0 && strlen(Section)!=0); - verify(Key!=0 && strlen(Key)!=0); verify(Return!=0); - if (Default==0) - Default=""; - ConfigSection* cs= this->GetEntry(Section); - ConfigEntry* ce=cs->FindEntry(Key); - if (!ce) - { - cs->SetEntry(Key,Default,CEM_SAVE); - strcpy(Return,Default); - } - else - { - strcpy(Return,ce->GetValue().c_str()); - } + string value = this->LoadStr(Section, Key, Default); + strcpy(Return, value.c_str()); } string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) From e4527bf531936d983d128fb2753293ba590640a7 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 23:00:05 +0200 Subject: [PATCH 6/7] cfg: Fix indentation --- core/cfg/cfg.cpp | 514 ++++++++++++++++++++++++----------------------- core/cfg/cfg.h | 54 ++--- 2 files changed, 289 insertions(+), 279 deletions(-) diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index fe3b79ae2..69e4d79d1 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -23,227 +23,124 @@ string cfgPath; struct vitem { - string s; - string n; - string v; - vitem(string a,string b,string c){s=a;n=b;v=c;} + string s; + string n; + string v; + vitem(string a,string b,string c){s=a;n=b;v=c;} }; vector vlist; wchar* trim_ws(wchar* str); ConfigEntry::ConfigEntry(ConfigEntry* pp) - { - next=pp; - flags=0; - } +{ + next=pp; + flags=0; +} + void ConfigEntry::SaveFile(FILE* file) - { - if (flags & CEM_SAVE) - fprintf(file,"%s=%s\n",name.c_str(),value.c_str()); - } +{ + if (flags & CEM_SAVE) + fprintf(file,"%s=%s\n",name.c_str(),value.c_str()); +} string ConfigEntry::GetValue() - { - if (flags&CEM_VIRTUAL) - return valueVirtual; - else - return value; - } +{ + if (flags&CEM_VIRTUAL) + return valueVirtual; + else + return value; +} ConfigSection::ConfigSection(ConfigSection* pp) - { - next=pp; - flags=0; - entrys=0; - } +{ + next=pp; + flags=0; + entrys=0; +} + ConfigEntry* ConfigSection::FindEntry(string name) +{ + ConfigEntry* c= entrys; + while(c) { - ConfigEntry* c= entrys; - while(c) - { - if (stricmp(name.c_str(),c->name.c_str())==0) - return c; - c=c->next; - } - return 0; + if (stricmp(name.c_str(),c->name.c_str())==0) + return c; + c=c->next; } + return 0; +} + void ConfigSection::SetEntry(string name,string value,u32 eflags) +{ + ConfigEntry* c=FindEntry(name); + if (c) { - ConfigEntry* c=FindEntry(name); - if (c) + //readonly is read only =) + if (c->flags & CEM_READONLY) + return; + + //virtual : save only if different value + if (c->flags & CEM_VIRTUAL) { - //readonly is read only =) - if (c->flags & CEM_READONLY) + + if(stricmp(c->valueVirtual.c_str(),value.c_str())==0) return; - - //virtual : save only if different value - if (c->flags & CEM_VIRTUAL) - { - - if(stricmp(c->valueVirtual.c_str(),value.c_str())==0) - return; - c->flags&=~CEM_VIRTUAL; - } + c->flags&=~CEM_VIRTUAL; } - else - { - entrys=c= new ConfigEntry(entrys); - c->name=name; - } - - verify(!(c->flags&(CEM_VIRTUAL|CEM_READONLY))); - //Virtual - //Virtual | ReadOnly - //Save - if (eflags & CEM_VIRTUAL) - { - verify(!(eflags & CEM_SAVE)); - c->flags|=eflags; - c->valueVirtual=value; - } - else if (eflags & CEM_SAVE) - { - verify(!(eflags & (CEM_VIRTUAL|CEM_READONLY))); - flags|=CEM_SAVE; - c->flags|=CEM_SAVE; - - c->value=value; - } - else - { - die("Invalid eflags value"); - } - } + else + { + entrys=c= new ConfigEntry(entrys); + c->name=name; + } + + verify(!(c->flags&(CEM_VIRTUAL|CEM_READONLY))); + //Virtual + //Virtual | ReadOnly + //Save + if (eflags & CEM_VIRTUAL) + { + verify(!(eflags & CEM_SAVE)); + c->flags|=eflags; + c->valueVirtual=value; + } + else if (eflags & CEM_SAVE) + { + verify(!(eflags & (CEM_VIRTUAL|CEM_READONLY))); + flags|=CEM_SAVE; + c->flags|=CEM_SAVE; + + c->value=value; + } + else + { + die("Invalid eflags value"); + } + +} + ConfigSection::~ConfigSection() +{ + ConfigEntry* n=entrys; + + while(n) { - ConfigEntry* n=entrys; - - while(n) - { - ConfigEntry* p=n; - n=n->next; - delete p; - } + ConfigEntry* p=n; + n=n->next; + delete p; } +} + void ConfigSection::SaveFile(FILE* file) +{ + if (flags&CEM_SAVE) { - if (flags&CEM_SAVE) - { - fprintf(file,"[%s]\n",name.c_str()); + fprintf(file,"[%s]\n",name.c_str()); - vector stuff; + vector stuff; - ConfigEntry* n=entrys; + ConfigEntry* n=entrys; - while(n) - { - stuff.push_back(n); - n=n->next; - } - - for (int i=stuff.size()-1;i>=0;i--) - { - stuff[i]->SaveFile(file); - } - - fprintf(file,"\n"); - } - } - -ConfigSection* ConfigFile::FindSection(string name) - { - ConfigSection* c= entrys; - while(c) - { - if (stricmp(name.c_str(),c->name.c_str())==0) - return c; - c=c->next; - } - return 0; - } -ConfigSection* ConfigFile::GetEntry(string name) - { - ConfigSection* c=FindSection(name); - if (!c) - { - entrys=c= new ConfigSection(entrys); - c->name=name; - } - - return c; - } -ConfigFile::~ConfigFile() - { - ConfigSection* n=entrys; - - while(n) - { - ConfigSection* p=n; - n=n->next; - delete p; - } - } - -void ConfigFile::ParseFile(FILE* file) - { - wchar line[512]; - wchar cur_sect[512]={0}; - int cline=0; - while(file && !feof(file)) - { - fgets(line,512,file); - if (feof(file)) - break; - - cline++; - - if (strlen(line)<3) - continue; - if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') - line[strlen(line)-1]=0; - - wchar* tl=trim_ws(line); - if (tl[0]=='[' && tl[strlen(tl)-1]==']') - { - tl[strlen(tl)-1]=0; - strcpy(cur_sect,tl+1); - trim_ws(cur_sect); - } - else - { - if (cur_sect[0]==0) - continue;//no open section - wchar* str1=strstr(tl,"="); - if (!str1) - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - continue; - } - *str1=0; - str1++; - wchar* v=trim_ws(str1); - wchar* k=trim_ws(tl); - if (v && k) - { - ConfigSection*cs=this->GetEntry(cur_sect); - - //if (!cs->FindEntry(k)) - cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); - } - else - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - } - } - } - } -void ConfigFile::SaveFile(FILE* file) - { - vector stuff; - - ConfigSection* n=entrys; - while(n) { stuff.push_back(n); @@ -252,70 +149,183 @@ void ConfigFile::SaveFile(FILE* file) for (int i=stuff.size()-1;i>=0;i--) { - if (stuff[i]->name!="emu") - stuff[i]->SaveFile(file); + stuff[i]->SaveFile(file); + } + + fprintf(file,"\n"); + } +} + +ConfigSection* ConfigFile::FindSection(string name) +{ + ConfigSection* c= entrys; + while(c) + { + if (stricmp(name.c_str(),c->name.c_str())==0) + return c; + c=c->next; + } + return 0; +} + +ConfigSection* ConfigFile::GetEntry(string name) +{ + ConfigSection* c=FindSection(name); + if (!c) + { + entrys=c= new ConfigSection(entrys); + c->name=name; + } + + return c; +} + +ConfigFile::~ConfigFile() +{ + ConfigSection* n=entrys; + + while(n) + { + ConfigSection* p=n; + n=n->next; + delete p; + } +} + +void ConfigFile::ParseFile(FILE* file) +{ + wchar line[512]; + wchar cur_sect[512]={0}; + int cline=0; + while(file && !feof(file)) + { + fgets(line,512,file); + if (feof(file)) + break; + + cline++; + + if (strlen(line)<3) + continue; + if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') + line[strlen(line)-1]=0; + + wchar* tl=trim_ws(line); + if (tl[0]=='[' && tl[strlen(tl)-1]==']') + { + tl[strlen(tl)-1]=0; + strcpy(cur_sect,tl+1); + trim_ws(cur_sect); + } + else + { + if (cur_sect[0]==0) + continue;//no open section + wchar* str1=strstr(tl,"="); + if (!str1) + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + continue; + } + *str1=0; + str1++; + wchar* v=trim_ws(str1); + wchar* k=trim_ws(tl); + if (v && k) + { + ConfigSection*cs=this->GetEntry(cur_sect); + + //if (!cs->FindEntry(k)) + cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); + } + else + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + } } } +} + +void ConfigFile::SaveFile(FILE* file) +{ + vector stuff; + + ConfigSection* n=entrys; + + while(n) + { + stuff.push_back(n); + n=n->next; + } + + for (int i=stuff.size()-1;i>=0;i--) + { + if (stuff[i]->name!="emu") + stuff[i]->SaveFile(file); + } +} + s32 ConfigFile::Exists(const wchar * Section, const wchar * Key) - { - if (Section==0) - return -1; - //return cfgRead(Section,Key,0); - ConfigSection*cs= this->FindSection(Section); - if (cs == 0) - return 0; +{ + if (Section==0) + return -1; + //return cfgRead(Section,Key,0); + ConfigSection*cs= this->FindSection(Section); + if (cs == 0) + return 0; - if (Key==0) - return 1; + if (Key==0) + return 1; + + ConfigEntry* ce=cs->FindEntry(Key); + if (ce!=0) + return 2; + else + return 0; +} - ConfigEntry* ce=cs->FindEntry(Key); - if (ce!=0) - return 2; - else - return 0; - } void ConfigFile::LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) - { - verify(Return!=0); - string value = this->LoadStr(Section, Key, Default); - strcpy(Return, value.c_str()); - } +{ + verify(Return!=0); + string value = this->LoadStr(Section, Key, Default); + strcpy(Return, value.c_str()); +} string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) - { - verify(Section != 0 && strlen(Section) != 0); - verify(Key != 0 && strlen(Key) != 0); +{ + verify(Section != 0 && strlen(Section) != 0); + verify(Key != 0 && strlen(Key) != 0); - if (Default == 0) - Default = ""; - ConfigSection* cs = this->GetEntry(Section); - ConfigEntry* ce = cs->FindEntry(Key); - if (!ce) - { - cs->SetEntry(Key, Default, CEM_SAVE); - return Default; - } - else - { - return ce->GetValue(); - } - } + if (Default == 0) + Default = ""; + ConfigSection* cs = this->GetEntry(Section); + ConfigEntry* ce = cs->FindEntry(Key); + if (!ce) + { + cs->SetEntry(Key, Default, CEM_SAVE); + return Default; + } + else + { + return ce->GetValue(); + } +} s32 ConfigFile::LoadInt(const wchar * Section, const wchar * Key,s32 Default) - { - wchar temp_d[30]; - wchar temp_o[30]; - sprintf(temp_d,"%d",Default); - this->LoadStr(Section,Key,temp_o,temp_d); - if (strstr(temp_o, "0x") != NULL) - { - return strtol(temp_o, NULL, 16); - } - else - { - return atoi(temp_o); - } - } +{ + wchar temp_d[30]; + wchar temp_o[30]; + sprintf(temp_d,"%d",Default); + this->LoadStr(Section,Key,temp_o,temp_d); + if (strstr(temp_o, "0x") != NULL) + { + return strtol(temp_o, NULL, 16); + } + else + { + return atoi(temp_o); + } +} ConfigFile cfgdb; @@ -394,12 +404,12 @@ bool cfgOpen() } } - cfgdb.ParseFile(cfgfile); + cfgdb.ParseFile(cfgfile); - for (size_t i=0;iSetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); - } + for (size_t i=0;iSetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); + } if (cfgfile) { diff --git a/core/cfg/cfg.h b/core/cfg/cfg.h index fe8fa6368..30f06789e 100644 --- a/core/cfg/cfg.h +++ b/core/cfg/cfg.h @@ -22,39 +22,39 @@ bool ParseCommandLine(int argc,wchar* argv[]); struct ConfigEntry { - u32 flags; - string name; - string value; - string valueVirtual; - ConfigEntry* next; - ConfigEntry(ConfigEntry*); - string GetValue(); - void SaveFile(FILE*); + u32 flags; + string name; + string value; + string valueVirtual; + ConfigEntry* next; + ConfigEntry(ConfigEntry*); + string GetValue(); + void SaveFile(FILE*); }; struct ConfigSection { - u32 flags; - string name; - ConfigEntry* entrys; - ConfigSection* next; - ~ConfigSection(); - ConfigSection(ConfigSection*); - ConfigEntry* FindEntry(string); - void SetEntry(string, string, u32); - void SaveFile(FILE*); + u32 flags; + string name; + ConfigEntry* entrys; + ConfigSection* next; + ~ConfigSection(); + ConfigSection(ConfigSection*); + ConfigEntry* FindEntry(string); + void SetEntry(string, string, u32); + void SaveFile(FILE*); }; struct ConfigFile { - ConfigSection* entrys; - ~ConfigFile(); - void ParseFile(FILE*); - void SaveFile(FILE*); - ConfigSection* FindSection(string); - ConfigSection* GetEntry(string); - s32 Exists(const wchar *, const wchar *); - void LoadStr(const wchar *, const wchar *, wchar *,const wchar*); - string LoadStr(const wchar *, const wchar *, const wchar*); - s32 LoadInt(const wchar *, const wchar *,s32); + ConfigSection* entrys; + ~ConfigFile(); + void ParseFile(FILE*); + void SaveFile(FILE*); + ConfigSection* FindSection(string); + ConfigSection* GetEntry(string); + s32 Exists(const wchar *, const wchar *); + void LoadStr(const wchar *, const wchar *, wchar *,const wchar*); + string LoadStr(const wchar *, const wchar *, const wchar*); + s32 LoadInt(const wchar *, const wchar *,s32); }; \ No newline at end of file From 509ac93463edd90a39c036c0e9a85dfefde874b8 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sun, 16 Aug 2015 23:35:13 +0200 Subject: [PATCH 7/7] cfg: Move ConfigFile classes to ini.cpp/h --- core/cfg/cfg.cpp | 312 +---------------------------------------------- core/cfg/cfg.h | 39 ------ core/cfg/ini.cpp | 299 +++++++++++++++++++++++++++++++++++++++++++++ core/cfg/ini.h | 53 ++++++++ 4 files changed, 354 insertions(+), 349 deletions(-) create mode 100644 core/cfg/ini.cpp create mode 100644 core/cfg/ini.h diff --git a/core/cfg/cfg.cpp b/core/cfg/cfg.cpp index 69e4d79d1..a162d2eb6 100644 --- a/core/cfg/cfg.cpp +++ b/core/cfg/cfg.cpp @@ -6,21 +6,10 @@ #define _CRT_SECURE_NO_DEPRECATE (1) #include "cfg.h" +#include "ini.h" string cfgPath; -//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 vitem { string s; @@ -29,303 +18,6 @@ struct vitem vitem(string a,string b,string c){s=a;n=b;v=c;} }; vector vlist; -wchar* trim_ws(wchar* str); - -ConfigEntry::ConfigEntry(ConfigEntry* pp) -{ - next=pp; - flags=0; -} - -void ConfigEntry::SaveFile(FILE* file) -{ - if (flags & CEM_SAVE) - fprintf(file,"%s=%s\n",name.c_str(),value.c_str()); -} - -string ConfigEntry::GetValue() -{ - if (flags&CEM_VIRTUAL) - return valueVirtual; - else - return value; -} - -ConfigSection::ConfigSection(ConfigSection* pp) -{ - next=pp; - flags=0; - entrys=0; -} - -ConfigEntry* ConfigSection::FindEntry(string name) -{ - ConfigEntry* c= entrys; - while(c) - { - if (stricmp(name.c_str(),c->name.c_str())==0) - return c; - c=c->next; - } - return 0; -} - -void ConfigSection::SetEntry(string name,string value,u32 eflags) -{ - ConfigEntry* c=FindEntry(name); - if (c) - { - //readonly is read only =) - if (c->flags & CEM_READONLY) - return; - - //virtual : save only if different value - if (c->flags & CEM_VIRTUAL) - { - - if(stricmp(c->valueVirtual.c_str(),value.c_str())==0) - return; - c->flags&=~CEM_VIRTUAL; - } - } - else - { - entrys=c= new ConfigEntry(entrys); - c->name=name; - } - - verify(!(c->flags&(CEM_VIRTUAL|CEM_READONLY))); - //Virtual - //Virtual | ReadOnly - //Save - if (eflags & CEM_VIRTUAL) - { - verify(!(eflags & CEM_SAVE)); - c->flags|=eflags; - c->valueVirtual=value; - } - else if (eflags & CEM_SAVE) - { - verify(!(eflags & (CEM_VIRTUAL|CEM_READONLY))); - flags|=CEM_SAVE; - c->flags|=CEM_SAVE; - - c->value=value; - } - else - { - die("Invalid eflags value"); - } - -} - -ConfigSection::~ConfigSection() -{ - ConfigEntry* n=entrys; - - while(n) - { - ConfigEntry* p=n; - n=n->next; - delete p; - } -} - -void ConfigSection::SaveFile(FILE* file) -{ - if (flags&CEM_SAVE) - { - fprintf(file,"[%s]\n",name.c_str()); - - vector stuff; - - ConfigEntry* n=entrys; - - while(n) - { - stuff.push_back(n); - n=n->next; - } - - for (int i=stuff.size()-1;i>=0;i--) - { - stuff[i]->SaveFile(file); - } - - fprintf(file,"\n"); - } -} - -ConfigSection* ConfigFile::FindSection(string name) -{ - ConfigSection* c= entrys; - while(c) - { - if (stricmp(name.c_str(),c->name.c_str())==0) - return c; - c=c->next; - } - return 0; -} - -ConfigSection* ConfigFile::GetEntry(string name) -{ - ConfigSection* c=FindSection(name); - if (!c) - { - entrys=c= new ConfigSection(entrys); - c->name=name; - } - - return c; -} - -ConfigFile::~ConfigFile() -{ - ConfigSection* n=entrys; - - while(n) - { - ConfigSection* p=n; - n=n->next; - delete p; - } -} - -void ConfigFile::ParseFile(FILE* file) -{ - wchar line[512]; - wchar cur_sect[512]={0}; - int cline=0; - while(file && !feof(file)) - { - fgets(line,512,file); - if (feof(file)) - break; - - cline++; - - if (strlen(line)<3) - continue; - if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') - line[strlen(line)-1]=0; - - wchar* tl=trim_ws(line); - if (tl[0]=='[' && tl[strlen(tl)-1]==']') - { - tl[strlen(tl)-1]=0; - strcpy(cur_sect,tl+1); - trim_ws(cur_sect); - } - else - { - if (cur_sect[0]==0) - continue;//no open section - wchar* str1=strstr(tl,"="); - if (!str1) - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - continue; - } - *str1=0; - str1++; - wchar* v=trim_ws(str1); - wchar* k=trim_ws(tl); - if (v && k) - { - ConfigSection*cs=this->GetEntry(cur_sect); - - //if (!cs->FindEntry(k)) - cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); - } - else - { - printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); - } - } - } -} - -void ConfigFile::SaveFile(FILE* file) -{ - vector stuff; - - ConfigSection* n=entrys; - - while(n) - { - stuff.push_back(n); - n=n->next; - } - - for (int i=stuff.size()-1;i>=0;i--) - { - if (stuff[i]->name!="emu") - stuff[i]->SaveFile(file); - } -} - -s32 ConfigFile::Exists(const wchar * Section, const wchar * Key) -{ - if (Section==0) - return -1; - //return cfgRead(Section,Key,0); - ConfigSection*cs= this->FindSection(Section); - if (cs == 0) - return 0; - - if (Key==0) - return 1; - - ConfigEntry* ce=cs->FindEntry(Key); - if (ce!=0) - return 2; - else - return 0; -} - -void ConfigFile::LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) -{ - verify(Return!=0); - string value = this->LoadStr(Section, Key, Default); - strcpy(Return, value.c_str()); -} - -string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) -{ - verify(Section != 0 && strlen(Section) != 0); - verify(Key != 0 && strlen(Key) != 0); - - if (Default == 0) - Default = ""; - ConfigSection* cs = this->GetEntry(Section); - ConfigEntry* ce = cs->FindEntry(Key); - if (!ce) - { - cs->SetEntry(Key, Default, CEM_SAVE); - return Default; - } - else - { - return ce->GetValue(); - } -} - -s32 ConfigFile::LoadInt(const wchar * Section, const wchar * Key,s32 Default) -{ - wchar temp_d[30]; - wchar temp_o[30]; - sprintf(temp_d,"%d",Default); - this->LoadStr(Section,Key,temp_o,temp_d); - if (strstr(temp_o, "0x") != NULL) - { - return strtol(temp_o, NULL, 16); - } - else - { - return atoi(temp_o); - } -} ConfigFile cfgdb; @@ -455,4 +147,4 @@ void cfgSetVirtual(const wchar * Section, const wchar * Key, const wchar * Strin { vlist.push_back(vitem(Section,Key,String)); //cfgdb.GetEntry(Section,CEM_VIRTUAL)->SetEntry(Key,String,CEM_VIRTUAL); -} \ No newline at end of file +} diff --git a/core/cfg/cfg.h b/core/cfg/cfg.h index 30f06789e..3278ed777 100644 --- a/core/cfg/cfg.h +++ b/core/cfg/cfg.h @@ -19,42 +19,3 @@ s32 cfgExists(const wchar * Section, const wchar * Key); void cfgSetVirtual(const wchar * lpSection, const wchar * lpKey, const wchar * lpString); bool ParseCommandLine(int argc,wchar* argv[]); - -struct ConfigEntry -{ - u32 flags; - string name; - string value; - string valueVirtual; - ConfigEntry* next; - ConfigEntry(ConfigEntry*); - string GetValue(); - void SaveFile(FILE*); -}; - -struct ConfigSection -{ - u32 flags; - string name; - ConfigEntry* entrys; - ConfigSection* next; - ~ConfigSection(); - ConfigSection(ConfigSection*); - ConfigEntry* FindEntry(string); - void SetEntry(string, string, u32); - void SaveFile(FILE*); -}; - -struct ConfigFile -{ - ConfigSection* entrys; - ~ConfigFile(); - void ParseFile(FILE*); - void SaveFile(FILE*); - ConfigSection* FindSection(string); - ConfigSection* GetEntry(string); - s32 Exists(const wchar *, const wchar *); - void LoadStr(const wchar *, const wchar *, wchar *,const wchar*); - string LoadStr(const wchar *, const wchar *, const wchar*); - s32 LoadInt(const wchar *, const wchar *,s32); -}; \ No newline at end of file diff --git a/core/cfg/ini.cpp b/core/cfg/ini.cpp new file mode 100644 index 000000000..03bc4e9ae --- /dev/null +++ b/core/cfg/ini.cpp @@ -0,0 +1,299 @@ +#include "ini.h" + +wchar* trim_ws(wchar* str); + +ConfigEntry::ConfigEntry(ConfigEntry* pp) +{ + next=pp; + flags=0; +} + +void ConfigEntry::SaveFile(FILE* file) +{ + if (flags & CEM_SAVE) + fprintf(file,"%s=%s\n",name.c_str(),value.c_str()); +} + +string ConfigEntry::GetValue() +{ + if (flags&CEM_VIRTUAL) + return valueVirtual; + else + return value; +} + +ConfigSection::ConfigSection(ConfigSection* pp) +{ + next=pp; + flags=0; + entrys=0; +} + +ConfigEntry* ConfigSection::FindEntry(string name) +{ + ConfigEntry* c= entrys; + while(c) + { + if (stricmp(name.c_str(),c->name.c_str())==0) + return c; + c=c->next; + } + return 0; +} + +void ConfigSection::SetEntry(string name,string value,u32 eflags) +{ + ConfigEntry* c=FindEntry(name); + if (c) + { + //readonly is read only =) + if (c->flags & CEM_READONLY) + return; + + //virtual : save only if different value + if (c->flags & CEM_VIRTUAL) + { + + if(stricmp(c->valueVirtual.c_str(),value.c_str())==0) + return; + c->flags&=~CEM_VIRTUAL; + } + } + else + { + entrys=c= new ConfigEntry(entrys); + c->name=name; + } + + verify(!(c->flags&(CEM_VIRTUAL|CEM_READONLY))); + //Virtual + //Virtual | ReadOnly + //Save + if (eflags & CEM_VIRTUAL) + { + verify(!(eflags & CEM_SAVE)); + c->flags|=eflags; + c->valueVirtual=value; + } + else if (eflags & CEM_SAVE) + { + verify(!(eflags & (CEM_VIRTUAL|CEM_READONLY))); + flags|=CEM_SAVE; + c->flags|=CEM_SAVE; + + c->value=value; + } + else + { + die("Invalid eflags value"); + } + +} + +ConfigSection::~ConfigSection() +{ + ConfigEntry* n=entrys; + + while(n) + { + ConfigEntry* p=n; + n=n->next; + delete p; + } +} + +void ConfigSection::SaveFile(FILE* file) +{ + if (flags&CEM_SAVE) + { + fprintf(file,"[%s]\n",name.c_str()); + + vector stuff; + + ConfigEntry* n=entrys; + + while(n) + { + stuff.push_back(n); + n=n->next; + } + + for (int i=stuff.size()-1;i>=0;i--) + { + stuff[i]->SaveFile(file); + } + + fprintf(file,"\n"); + } +} + +ConfigSection* ConfigFile::FindSection(string name) +{ + ConfigSection* c= entrys; + while(c) + { + if (stricmp(name.c_str(),c->name.c_str())==0) + return c; + c=c->next; + } + return 0; +} + +ConfigSection* ConfigFile::GetEntry(string name) +{ + ConfigSection* c=FindSection(name); + if (!c) + { + entrys=c= new ConfigSection(entrys); + c->name=name; + } + + return c; +} + +ConfigFile::~ConfigFile() +{ + ConfigSection* n=entrys; + + while(n) + { + ConfigSection* p=n; + n=n->next; + delete p; + } +} + +void ConfigFile::ParseFile(FILE* file) +{ + wchar line[512]; + wchar cur_sect[512]={0}; + int cline=0; + while(file && !feof(file)) + { + fgets(line,512,file); + if (feof(file)) + break; + + cline++; + + if (strlen(line)<3) + continue; + if (line[strlen(line)-1]=='\r' || line[strlen(line)-1]=='\n') + line[strlen(line)-1]=0; + + wchar* tl=trim_ws(line); + if (tl[0]=='[' && tl[strlen(tl)-1]==']') + { + tl[strlen(tl)-1]=0; + strcpy(cur_sect,tl+1); + trim_ws(cur_sect); + } + else + { + if (cur_sect[0]==0) + continue;//no open section + wchar* str1=strstr(tl,"="); + if (!str1) + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + continue; + } + *str1=0; + str1++; + wchar* v=trim_ws(str1); + wchar* k=trim_ws(tl); + if (v && k) + { + ConfigSection*cs=this->GetEntry(cur_sect); + + //if (!cs->FindEntry(k)) + cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); + } + else + { + printf("Malformed entry on config - ignoring @ %d(%s)\n",cline,tl); + } + } + } +} + +void ConfigFile::SaveFile(FILE* file) +{ + vector stuff; + + ConfigSection* n=entrys; + + while(n) + { + stuff.push_back(n); + n=n->next; + } + + for (int i=stuff.size()-1;i>=0;i--) + { + if (stuff[i]->name!="emu") + stuff[i]->SaveFile(file); + } +} + +s32 ConfigFile::Exists(const wchar * Section, const wchar * Key) +{ + if (Section==0) + return -1; + //return cfgRead(Section,Key,0); + ConfigSection*cs= this->FindSection(Section); + if (cs == 0) + return 0; + + if (Key==0) + return 1; + + ConfigEntry* ce=cs->FindEntry(Key); + if (ce!=0) + return 2; + else + return 0; +} + +void ConfigFile::LoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default) +{ + verify(Return!=0); + string value = this->LoadStr(Section, Key, Default); + strcpy(Return, value.c_str()); +} + +string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default) +{ + verify(Section != 0 && strlen(Section) != 0); + verify(Key != 0 && strlen(Key) != 0); + + if (Default == 0) + Default = ""; + ConfigSection* cs = this->GetEntry(Section); + ConfigEntry* ce = cs->FindEntry(Key); + if (!ce) + { + cs->SetEntry(Key, Default, CEM_SAVE); + return Default; + } + else + { + return ce->GetValue(); + } +} + +s32 ConfigFile::LoadInt(const wchar * Section, const wchar * Key,s32 Default) +{ + wchar temp_d[30]; + wchar temp_o[30]; + sprintf(temp_d,"%d",Default); + this->LoadStr(Section,Key,temp_o,temp_d); + if (strstr(temp_o, "0x") != NULL) + { + return strtol(temp_o, NULL, 16); + } + else + { + return atoi(temp_o); + } +} diff --git a/core/cfg/ini.h b/core/cfg/ini.h new file mode 100644 index 000000000..05ae15fbc --- /dev/null +++ b/core/cfg/ini.h @@ -0,0 +1,53 @@ +#pragma once +#include "types.h" + +//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 +{ + u32 flags; + string name; + string value; + string valueVirtual; + ConfigEntry* next; + ConfigEntry(ConfigEntry*); + string GetValue(); + void SaveFile(FILE*); +}; + +struct ConfigSection +{ + u32 flags; + string name; + ConfigEntry* entrys; + ConfigSection* next; + ~ConfigSection(); + ConfigSection(ConfigSection*); + ConfigEntry* FindEntry(string); + void SetEntry(string, string, u32); + void SaveFile(FILE*); +}; + +struct ConfigFile +{ + ConfigSection* entrys; + ~ConfigFile(); + void ParseFile(FILE*); + void SaveFile(FILE*); + ConfigSection* FindSection(string); + ConfigSection* GetEntry(string); + s32 Exists(const wchar *, const wchar *); + void LoadStr(const wchar *, const wchar *, wchar *,const wchar*); + string LoadStr(const wchar *, const wchar *, const wchar*); + s32 LoadInt(const wchar *, const wchar *,s32); +}; \ No newline at end of file