[Include] INI File Manager + Convertor Include
#1

INI - File Manager
IncludЙ by Neufox
#2 Release
Version: 3 | Last Update: 04/12/2014

Hello friends! I made my mind releasing this old include of mine today, I know its late and nower days people recommend SQLITE or MYSQL. But still i want to release this. Its an edited version of SII. This is quiet simple and easy and CLEAN. So i hope you like it! I also want to aware you all that this don't support multiple file opening, yea it does close previous one and open up the new file in the case of dini conversion, but that can't be called multiple file opening. I have also performed some speed tests and the result is quiet good. You can checkout that down the thread.

Well I want to thank [DRuG]Slick for base SII code and SAMP Team. And Neufox(indirectly, me) for this include and creating it.

NOTE: Script distributed under no agreement or conditions. Free for all, People have no permission to remove credits, re-release script until permission is granted from the real owner(s).

* You can also download Basic Login & Register system, test: initest.pwn

Version 3 (04/12/2014)
  • Fixed closing issue in "INI_Rename & INI_Copy".
  • Fixed conversion system (mainly UDB)
Download: n_ini.inc {Version 3 | Recommended}

Version 2 (30/11/2014)
  • Removed "INI_WriteFloat" limit
  • Fixed minor bug in "INI_Rename" & "INI_Copy"
  • Fixed minor issue in "INI_WriteBool"
  • Updated UDB system
Download: n_ini.inc {Version 2}

Version 1 (29/11/2014)
The basic demonstration of the script.
  • Fast, faster than dini, dudb, and some other file/ini managers.
  • Easy, as [DRUG]Slick said, "Even your mother can use it!".
  • Many new features, like "Renaming, Copying..." files.
  • Multi write and read from a file.
  • Accepts comments in the file. (Use ";" to start a comment)
  • A dynamic convertor which helps you to convert other ini manager functions.
    • DINI
    • DUDB
    • SFM(Southclaw's File Manager)
    • FINI
    • SII
    • SF(Simple File)
    • dFile
  • Cache based file saving system.
  • The script is crash free, so no worry.
  • Inbuilt UDB system, allows you to create USER-DATABASE easily.
  • New multiple writing and reading function, Write all your stuff in one GO!
  • AUTO_SAVE feature, if set to "true", you don't need to use "INI_Save" before closing, just "INI_Close". Its integrated in INI_Close itself.
Download: n_ini.inc {Version 1}

Stocks
Here are some stock functions or natives, these are also available in the script. Here, just to display the functions.
pawn Код:
//Creates an ini file(only if not existing).
//"bool:open" when true automatically opens the file after creating it.
native INI_Create(const filename[], bool:open = false);

//Removing an already existing file
native INI_Remove(const filename[]);

//Advance function in some cases. Actually opens the file specified so that we can start experiments.
//NOTE: If the file does not кxists, this auto creates and open it.
native INI_Open(const filename[]);

//Close the opened file.
//NOTE: If enabled "INI_AUTO_SAVE", this automatically writes the data from cache.
native INI_Close();

//Write cache data to file.
native INI_Save();

//Rename the opened file. The data remains the same and saved.
native INI_Rename(const newname[]);

//Duplicate the whole file with the data saved.
native INI_Copy(const copyname[]);

//Writing stuff to a file. Includes "strings, float, boolean, & integer".
native INI_WriteString(const key[], const value[]);
native INI_WriteInt(const key[], value);
native INI_WriteFloat(const key[], Float: value);
native INI_WriteBool(const key[], bool:value);

//Reading stuff froam a file.
native INI_ReadString(const key[]);
native INI_ReadInt(const key[]);
native Float:INI_ReadFloat(const key[]);
native bool:INI_ReadBool(const key[]);

//Advance feature, write stuff of all type in one go.
//TIP:
//'s' - string
//'b' - bool
//'f' - float
//'i' or 'd' - integer
//EXAMPLE: INI_MultiWrite("db", "kills", 0, "killed", true);
native INI_MultiWrite(format[], {Float,_}:...);

//Advance feature, read all stuff in one go.
//EXAMPLE:
/*
new kills, bool:killed;
INI_MultiRead("db", "kills", kills, "killed", killed);
*/

native INI_MultiRead(format[],{Float,_}:...);

//Remove an existing key froam a file.
native INI_RemoveKey(const key[]);

//Check if the key exists.
native INI_KeyExist(const key[]);

//Return "true" if any file is opened.
native INI_ReturnFile();

//Returns the file name which is opened(if any).
native INI_ReturnFilename();
Speed tests
Also given the code, so that users can make out their own tests.

Writing to a file!
  • Writing String 50 times: 14ms
  • Writing Integer 50 times: 6ms
  • Writing Float 50 times: 10ms
  • Writing Bool 50 times: 12ms
Reading from a file!
  • Reading String 50 times: 20ms
  • Reading Integer 50 times: 8ms
  • Reading Float 50 times: 13ms
  • Reading Bool 50 times: 15ms
Speed test code:
pawn Код:
/*
    n_ini.inc include by Neufox
    n_ini (INI-File) test by Neufox, reading and writing speed tests!
*/


#include <a_samp>
#include <n_ini>

#define INI_TESTS 50//the number of times to write and read each category or type

#if(!INI_AUTO_SAVE)
    #undef INI_AUTO_SAVE
    #define INI_AUTO_SAVE true
#endif

public OnFilterScriptInit()
{
        print("READING & WRITTING INI FILE SPEED Tests loaded with (n_ini.inc)");
        print("Credits: Neufox, ENJOY!");
   
        new tick, string[17];
        tick=GetTickCount();
       
        INI_Open("test.ini");//opening the file

        //writing
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_String_%d", i);
            INI_WriteString(string, "blah blah blah blah blah blah blah blah blah blah blah blah");
        }
        printf("Takes %d ms to Write Strings "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_int_%d", i);
            INI_WriteInt(string, 1234567890);
        }

        printf("Takes %d ms to Write Integers "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_float_%d", i);
            INI_WriteFloat(string, 1234567890.0000);
        }
        printf("Takes %d ms to Write Floats "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_bool_%d", i);
            INI_WriteBool(string, true);
        }
        printf("Takes %d ms to Write Bools "#INI_TESTS" times\n", GetTickCount()-tick);

        //reading
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_String_%d", i);
            INI_ReadString(string);
        }
        printf("Takes %d ms to Read Strings "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_int_%d", i);
            INI_ReadInt(string);
        }
        printf("Takes %d ms to Read Integers "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_float_%d", i);
            INI_ReadFloat(string);
        }
        printf("Takes %d ms to Read Floats "#INI_TESTS" times\n", GetTickCount()-tick);

        tick=GetTickCount();
        for(new i;i<INI_TESTS;i++)
        {
            format(string, sizeof(string), "Test_bool_%d", i);
            INI_ReadBool(string);
        }
        printf("Takes %d ms to Read Bools "#INI_TESTS" times\n", GetTickCount()-tick);
       
        INI_Close();//closeing the file
        return 1;
}

public OnFilterScriptExit()
{
        return 1;
}
NOTE: If any bugs or suggestions, please report. Otherwise, enjoy!
Reply
#2

Nice work, do a 1000 times loop functions and do comparision to benchmarks of anothers includes...

@Edit: what is the difference between this version and original SII include? What have you changed?
Reply
#3

Quote:
Originally Posted by n0minal
Посмотреть сообщение
Nice work, do a 1000 times loop functions and do comparision to benchmarks of anothers includes...
Thanks.
I will surely do that but my PC is consuming more time to instal windows 7. Just got crashed after a while i released this.
Well, if you don't want to wait, you may use the speed test code provided in the main thread to perform some tests. I am sure its quiet easy.

@EDIT:
- Saving bools
- Multiple writing and reading
- Ini conversion system(One of the main featurE)
- Fixed some minor issues
- Easy inbuilt UDB system
- Renaming and copying

Just read the thread for everything about this.
Reply
#4

Quote:
Originally Posted by Neufox
Посмотреть сообщение
Thanks.
I will surely do that but my PC is consuming more time to instal windows 7. Just got crashed after a while i released this.
Well, if you don't want to wait, you may use the speed test code provided in the main thread to perform some tests. I am sure its quiet easy.

@EDIT:
- Saving bools
- Multiple writing and reading
- Ini conversion system(One of the main featurE)
- Fixed some minor issues
- Easy inbuilt UDB system
- Renaming and copying

Just read the thread for everything about this.
Im on mobile now, i'll take a look again on the source when get on PC later, good job mate, keep it up
Reply
#5

good job! i will tried it!
Reply
#6

Good job you done here, now take a rep.
Reply
#7

Very nice. Love the conversion part.
Reply
#8

The speed is puiet good.
Very nice work, INI_Multi(Write/Read)!
Reply
#9

I don't understand why you would need to use format in the bool write function why not just do this.
pawn Код:
stock INI_WriteBool(const key[], bool:value)
{
        if(value) return INI_WriteString(key, "1");
        return INI_WriteString(key, "0");
}
Don't limit precision of floats!
pawn Код:
format(dest, sizeof(dest), "%0.4f", value);
INI_Copy has a critical bug.
pawn Код:
h = fopen(gFile[E_FILENAME], io_read);
        g = fopen(copyname, io_write);
 
        if (!h) return false;
        if (!g) return false;
If you try to copy a file that does not exist the write file is not closed! Same issue with INI_Rename()

Another thing is make sure you do all tests on a RamDisk so access times are completely minimized.

There is probably other stuff as well, but those are what I noticed before hitting the sack.
Reply
#10

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I don't understand why you would need to use format in the bool write function why not just do this.
pawn Код:
stock INI_WriteBool(const key[], bool:value)
{
        if(value) return INI_WriteString(key, "1");
        return INI_WriteString(key, "0");
}
Ohh, I was just copying and pasting stuff! Didn't notice that could have been much easier!

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Don't limit precision of floats!
pawn Код:
format(dest, sizeof(dest), "%0.4f", value);
Done! (limit removed)

Quote:
Originally Posted by Pottus
Посмотреть сообщение
INI_Copy has a critical bug.
pawn Код:
h = fopen(gFile[E_FILENAME], io_read);
        g = fopen(copyname, io_write);
 
        if (!h) return false;
        if (!g) return false;
If you try to copy a file that does not exist the write file is not closed! Same issue with INI_Rename()
I didn't understand what you actually mean from that ^^?
(Umm, You mean I didn't closed the copied file...)

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Another thing is make sure you do all tests on a RamDisk so access times are completely minimized.
I'll do that later ^^

Quote:
Originally Posted by Pottus
Посмотреть сообщение
There is probably other stuff as well, but those are what I noticed before hitting the sack.
I am really keen to know those other stuff(s)!
Reply
#11

You need to do something like this....

pawn Код:
h = fopen(gFile[E_FILENAME], io_read);
if (!h) return false;
g = fopen(copyname, io_write);
if (!g)
{
    fclose(h);
    return false;
}
Reply
#12

Quote:
Originally Posted by Pottus
Посмотреть сообщение
You need to do something like this....

pawn Код:
h = fopen(gFile[E_FILENAME], io_read);
if (!h) return false;
g = fopen(copyname, io_write);
if (!g)
{
    fclose(h);
    return false;
}
Well lately, but thanks for your opinions.

[ANNOUNCE] Download Version 3(Fixed all issues), checkout the main thread for downloading.
Reply
#13

Very well done. Pretty fast according to the speed tests.
REP+
Reply
#14

Thanks for version 3.

Well, i am a bit confused while using INI_MultiWrite, it would be very helpful if you explain that to me.
Thanks in advance!!
Reply
#15

Quote:
Originally Posted by $$inSane
Посмотреть сообщение
Thanks for version 3.

Well, i am a bit confused while using INI_MultiWrite, it would be very helpful if you explain that to me.
Thanks in advance!!
I think its used like this:
INI_MultiWrite("ds", "integer", 1, "string", "blah");
You can extend that function to add more, Just like using sscanf. Similar case is with MultiRead, the only difference is that you have to use variables in which you want to place the data after reading the specific key.

Also some few tips:
"s" - string
"i" or "d" - integer
"b" - bool
"f" - float


And, thanks Neufox for this include.
Reply
#16

I interested to see some speed tests in comparision of yini and DOF2.

@ Good job though
Reply
#17

Quote:
Originally Posted by Excips
Посмотреть сообщение
I interested to see some speed tests in comparision of yini and DOF2.

@ Good job though
Well, no point in making a speed test with those libraries. They support multi file opening but n_ini don't.

@Nice job Neufox, very useful in converting DINI & DUDB, I am currently using this in LuxAdmin.
+1

BTW: Nower days I recommend SQLITE.
Reply
#18

Quote:
Originally Posted by Qu3esL
Посмотреть сообщение
I think its used like this:
INI_MultiWrite("ds", "integer", 1, "string", "blah");
You can extend that function to add more, Just like using sscanf. Similar case is with MultiRead, the only difference is that you have to use variables in which you want to place the data after reading the specific key.

Also some few tips:
"s" - string
"i" or "d" - integer
"b" - bool
"f" - float


And, thanks Neufox for this include.
THANKS. That helped me alot.
REP4U !!
Reply
#19

Good job.
I m getin error using this to convert Ladmin, please help.
Reply
#20

Quote:
Originally Posted by Cassy_
Посмотреть сообщение
Good job.
I m getin error using this to convert Ladmin, please help.
Please post down the errors and necessary part of your script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)