View Single Post
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-18-2019 , 20:46   Re: INI File Reader/Writer AMXX 1.9
Reply With Quote #5

The INI Parser of AMXX only allows you to read the data and it's entirely event based (you must hook events), technically:

Code:
ParseFromINI() {     new INIParser:Parser = INI_CreateParser();     INI_SetReaders(Parser, "OnKeyValue", "OnNewSection");     INI_ParseFile(Parser, "path/to/file.ini");     INI_DestroyParser(Parser); } public bool:OnNewSection(INIParser:handle, const section[], bool:invalid_tokens, bool:close_bracket, bool:extra_tokens, curtok, any:data) {     if (!equali(section, "SectionName"))         return true;     return true; } public bool:OnKeyValue(INIParser:handle, const key[], const value[], bool:invalid_tokens, bool:equal_token, bool:quotes, curtok, any:data) {     if (!equali(key, "KeyName"))         return true;     server_print("%s=%s", key, value);     return true; }

To work with INI Parser of amxx you need to create handlers and a number of checks/code. In a way there is nothing wrong with this but it may be a hard and extensive work if you are working with multiple plugins to perform the parse and not just one. On the other hand, in Settings API or INI File Reader/Writer all you have to do is specify the file, section and key that you are looking for

Code:
new buffer[64]; ini_read_string("path/to/file.ini", "SectionName", "KeyName", buffer, charsmax(buffer));

and you can not only read as you can also adds data to the file as you already cited.

Code:
new buffer[64]; copy(buffer, charsmax(buffer), "KeyValue"); ini_write_string("path/to/file.ini", "SectionName", "KeyName", buffer); /* [SectionName] KeyName = KeyValue */

So in short, if you are looking for a simple and flexible way to work with INI files I believe both Settings API and this include are the best choices, but you are free to choose the best method for you.

Actually there is nothing wrong with MeRcyLeZZ's API, just a little bug when there is double brackets in section name (e.g. [[SectionName]]). I did the include for flexibility reason so you do not need to enable any "extra" plugin just like fvault, nfvault, dhudmessage, ROG, CromChat and whatever more; and I coded it the way I believe it is improved.
__________________









Last edited by CrazY.; 03-18-2019 at 20:52.
CrazY. is offline