|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis class ( Using the codeThe only class is the The first part handles all the structure: All data is saved in one I hope you did understand this, it would have been easier to explain in French or German. You can of course list all categories, and all keys in a specified category. When you want to modify or read a value, you need to specify the categoryname and the keyname only. This code is all you need to write an ini: IniStructure Ini = new IniStructure();
Ini.AddCategory("NewSection");
Ini.AddValue("NewSection","NewKey","value");
Ini.ModifyValue("NewSection","NewKey","Newvalue");
IniStructure.WriteIni(Ini,"c:\filename.ini","Optional \n multiline \n comment");
The ini c:\filename.ini would then contain: # Optional
# multiline
# comment
[NewSection]
NewKey=NewValue
Each time you write, the file is cleared and rewritten from scratch. To read an ini, it's very similar: IniStructure Ini = IniStructure.ReadIni("C:\filename.ini");
string[] allCategories = Ini.GetCategories();
// if Global would be a category, this lists all keys:
string[] keysInGlobal = Ini.GetKeys("Global");
// and if testkey would be a key in Global:
string testKeyValue = Ini.GetValue("Global","testkey");
There are also methods to list the categories and the key-value pairs by index, but they are only used to iterate through all categories and keys during saving. Points of InterestIt's the first time I use SortedLists, and first tried to write this without them, but I'm happy that I found them because it makes the code a lot simpler. There are some things to do, like error handling: because most methods only return bool, you can only know if an error occurred, but no more. Things like incorrect names (no '=', '[', ']' ... in category names etc..) are handled, but that's all. There's sure room for improvement, but, that's always the case, isn't it? History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||