[Include] dFile
#1

dFile
The fastest file and directory management.
What is this?

This is a new file management system, which not only the files but the directories can handle!
Anywhere able to save a file.

Warning: The system will save the file next to the server startup!

Why is this?

The system is very simple and straightforward, similar to features in the file manager but it does not contain any other unnecessary things!
There is still a big advantage: It is the fastest file management system! Why? Cause It's based on plugin.

Who made it?

The plugin created JaTochNietDan.

/*
* Dfile 1.0.4
* All rights reserved! © By: Drake
*
* Owner: Drake
* Time: 01/27/2011
*
* This function may be freely distributed.
* And of course, free to use: D
* Thanks to:
* ChuckNorris - Testing, Help
* Fade - Testing, Help
* ****** - boolstr function
* JaTochNietDan - FileManager
*
* Special thanks to:
* Thiadmer - Pawn.
* SA: MP Team Past, Present, Future - SA: MP.
*/


Compare with y_ini:


Features:

dfile_Create - Create a file. Keys:
Код:
 (file [])
File [] parameter is the string name of the file.

dfile_Delete - Delete file.
Код:
 (file [])
File [] to delete the file name.

dfile_Open - Open File.
Код:
 (file [])
File [] file name / location.

dfile_CreateDirectory - Create a directory.
Код:
 (folder [])
Folder [] the name of the directory location.

dfile_DeleteDirectory - Remove a directory.
Код:
 (folder [])
Folder [] the name of the directory location.

dfile_DirectoryExists - Verify that the folder exists
Код:
 Folder []
Folder [] control of the folder.

dfile_WriteString - Write a string to a file.
Код:
 (parameter [], value [])
parameter [] key, which write
val [] something.
Example:
Код:
 key = value
dfile_WriteInt - Write an integer to a file.
Код:
 (parameter [], value [])
parameter [] key, which write
val [] something.
Example:
Код:
 key = value
dfile_WriteBool - Boolean (true = false) Writing a bool value into the file.
Код:
 (parameter [], bool: value)
parameter [] key, which write
bool: You know what. (False / true)
Example:
Код:
 key = true
dfile_WriteFloat - Write a floating point number to a file.
Код:
 (parameter [], value [])
parameter [] key, which write
val [] something.
Example:
Код:
 key = value
dfile_ReadString - Read a string from a file.
Код:
 (parameter[])
parameter [] what the key value.

dfile_ReadInt - Integer read from a file.
Код:
 (parameter [])
parameter [] what the key value.

dfile_ReadFloat - Read a floating point number from a file.
Код:
 (parameter [])
parameter [] what the key value.

dfile_ReadBool - Read a bool value from a file.
Код:
 (parameter [])
parameter [] what the key value.

dfile_MoveFile - Move a file folder. It is important for the extension and that the destination folder exists!
Код:
 (file [], cel [])
File [] file in which to move,
End [] to.

dfile_RenameFile - Rename a file name. The extension is important!
Код:
 (oldname [], newname[])
oldname [] The file you want to rename,
newname [] The file new name.

dfile_SaveFile - Values to save the file.
Код:
 file []
File [] data file, which mentődjenek.

dfile_FileExists - Verify that the file exists
Код:
 file []
File [] control of the file.

dfile_ParseString - Compares the parameters and the input string.
Код:
 (file [] parameter [], value [])
File [] file in which the data is
parameter [] is the key name
val [] value, which compares the key value.

dfile_ParseInt - Compares the input parameter and an integer value.
Код:
 (file [] parameter [], value [])
File [] file in which the data is
parameter [] is the key name
val [] value, which compares the key value.

dfile_ParseFloat - Compares the argument and entered a float value.
Код:
 (file [] parameter [], value [])
File [] file in which the data is
parameter [] is the key name
val [] value, which compares the key value.

dfile_ParseBool - Compares the input parameter and the Boolean value.
Код:
 (file [] parameter [], value [])
File [] file in which the data is
parameter [] is the key name
val [] value, which compares the key value.

dfile_IsSet - Check if the key have value.
Код:
 (parameter[])
parameter [] is the key name

dfile_UnSet - Delete the key value.
Код:
 (parameter [])
parameter [] is the key name

dfile_MultiSet - Tцbb йrtйk нrбsa fбjlba.
Код:
(tipusok[], {Float,_}:...)
tipusok[] - parameter types.
Possible types:
  • "s" - string
  • "d" - integer
  • "b" - boolean
  • "f" - float
dfile_MultiGet - Tцbb йlrtйk lekйrdezйse egy fбjlbуl.
Код:
(tipusok[], {Float,_}:...)
tipusok[] - parameter types.
Possible types:
  • "s" - string
  • "d" - integer
  • "b" - boolean
  • "f" - float
Test script:
Код:
#include <a_samp>
#include <dfile>
#include <YSI\y_ini>

#define FILTERSCRIPT

new gInt, formalas[128];

#define fDFILE "DFILE_Test.txt"
#define fYINI "YINI_Test.txt"

#define WRITES 1000
#define READS 100000

public OnFilterScriptInit()
{
    print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    print("---------------------");
    print("Writing Tests Started");
    new
        initialTick,
        DFILE_tick,
        YINI_tick;

    print("-Testing dFile");
    //dFile Write
    {
        dfile_Create(fDFILE);
        dfile_Open(fDFILE);
        initialTick=GetTickCount();
        for(new i;i<WRITES;i++)format(formalas, sizeof(formalas), "%d", i), dfile_WriteInt(formalas, i);
        dfile_SaveFile();
        dfile_CloseFile();
        DFILE_tick=GetTickCount()-initialTick;
    }

    print("-Testing Yini\n");
    //Yini Write
    {
        new
            INI:file = INI_Open(fYINI);
        initialTick=GetTickCount();
        for(new i;i<WRITES;i++)format(formalas, sizeof(formalas), "%d", i), INI_WriteInt(file, formalas, i);
        INI_Close(file);
        YINI_tick=GetTickCount()-initialTick;
    }
    printf("\n-nTest Results %d Writes\n", WRITES);
    printf(" - dFile:\t%d", DFILE_tick);
    printf(" - Yini:\t%d", YINI_tick);
	print("---------------------\n\n");
	print("---------------------");
    print("Reading Tests Started");
    print("-Testing dFile");
    {
        dfile_Create(fDFILE);
        dfile_Open(fDFILE);
        initialTick=GetTickCount();
        for(new i;i<READS;i++)dfile_ReadInt("0");
        DFILE_tick=GetTickCount()-initialTick;
    }

    print("-Testing Yini\n");
    {
        new
            INI:file = INI_Open(fYINI);
        initialTick=GetTickCount();
        for(new i;i<READS;i++)
        {
            INI_Load(fYINI);
        }
        INI_Close(file);
        YINI_tick=GetTickCount()-initialTick;
    }
    printf("\n- Test Results %d Reads\n", READS);
    printf(" - dFile:\t%d", DFILE_tick);
    printf(" - Yini:\t%d\n\n", YINI_tick);
    print("---------------------");
}

INI:filename[](name[], value[])
{
    INI_Int("TEST_TAG", gInt);
    return 0;
}
Usage:
Код:
#include <a_samp>
#include <dfile>

main()
{
	new variable1[3][128], variable2[2], float:variable3, bool:variable4;
	dfile_Create("test.ini");
	dfile_Open("test.ini");
	dfile_WriteString("parameter0", "test1234234");
	dfile_WriteInt("parameter1", 999999999);
	dfile_WriteFloat("parameter2", 0.97398457987);
	dfile_WriteBool("parameter3", true);
	dfile_MultiSet("ssddfbs",
		"test", "something",
		"test2", "testhere",
		"test3", 30,
		"test4", 50,
		"test5", 36.23425,
		"test6", true,
		"test7", "anothersomething"
	);
	dfile_MultiGet("ssddfbs",
		"test", variable1[0],
		"test2", variable1[1],
		"test3", variable2[0],
		"test4", variable2[1],
		"test5", variable3,
		"test6", variable4,
		"test7", variable1[2]
	);
	dfile_SaveFile();
	printf("%s|%s|%d|%d|%f|%b|%s", variable1[0], variable1[1], variable2[0], variable2[1], variable3, variable4, variable1[2]);
	dfile_Open("test.ini");
	printf("%s", dfile_ReadString("parameter0"));
	printf("%d", dfile_ReadInt("parameter1"));
	printf("%f", dfile_ReadFloat("parameter2"));
	printf("%d s", dfile_ReadBool("parameter3"));
	printf("%d", dfile_ParseString("parameter0", "test1234234"));
	printf("%d", dfile_ParseInt("parameter1", 345));
	printf("%d", dfile_ParseFloat("parameter2", 0.973984));
	printf("%d", dfile_ParseBool("parameter3", true));
	printf("%d a", dfile_IsSet("parameter3"));
	dfile_CloseFile();
}
Download:
v1.0.5: Download
v1.0.9: Download
v1.1.0: Download
v1.1.1: Download

Updates:
Updated function:
  • dfile_WriteString - The function don't rewrite the key value if that exist
New functions have been added:
  • dfile_FileExists
  • dfile_DirectoryExists
  • dfile_RenameFile
  • dfile_IsSet
  • dfile_UnSet
Some functions are changed!
  • dfile_Open - Now read the file contents
  • dfile_ReadString - Now only the key needed
Description by ChuckNorris.
Reply
#2

Can you make some test's against SII??


anyways keep the good work
Reply
#3

Epic woooh thats fast
Reply
#4

You guys try so hard to beat y_ini, but one thing it's clear, y_ini has much more features than all of the file writing/reading system around here.
Reply
#5

Yeah we try to beat it and we beated it. the yini example has INI_WriteHex but where u can use the HEX code. or another example: Bin. Where can u use it man? And yini is hard to use and this simple file system easy, fast.
UPDATE: compare with SII and it's faster :P
Reply
#6

Quote:
Originally Posted by Drake1994
Посмотреть сообщение
Yeah we try to beat it and we beated it. the yini example has INI_WriteHex but where u can use the HEX code. or another example: Bin. Where can u use it man? And yini is hard to use and this simple file system easy, fast.
UPDATE: compare with SII and it's faster :P
You can never know.

****** will pass by here and will do a full analysis.
Reply
#7

Holy mother of all geeks! Another file writing system!



I have to test this!
Reply
#8

yep it beated SII but i known that SII would give some fight too let's wait for ****** make one analysis if it's all okay ill just use it :3 thanks for share
Reply
#9

You didn't test reading though.
Reply
#10

Good Work man,it nice.

Test with Fini?
Reply
#11

This is plugin, I couldn't test it properly because it gives me error Debug Assertion Failed!
If you have any solution to this, let me know, k?
Reply
#12

Compared with Fini, see the result above the main post.
And sorry i don't know anything about that error.
Reply
#13

Ok,Thanks

Execute test using the 10 or 20 keys,and not 100000 keys...
And need for download
http://www.dll-files.com/dllindex/dl...shtml?msvcp100
for execute plugin,LOL
Hugs!
Reply
#14

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
You didn't test reading though.
^

And please make another writing test including:
  • Writing several ints
  • Writing several floats
  • Writing several strings
  • Writing to two different files
All in the same itteration of course. ^^
Reply
#15

Lol.

It is a Good Script But look my speed tests (READ/WRITE):



TOTAL

Код:
Cini = 3115
Dini = 9595
Fini = 194
dFile = 283
TESTS
pawn Код:
#include <a_samp>
#include <dini>

#define FILTERSCRIPT



public OnFilterScriptInit()
{
    print("\n-----------------------------");
    print(" ini file system speed tests write");
    print("-----------------------------\n");

    #define maxtests 10000
   
    cini_Create("cini.ini");
    dini_Create("dini.ini");
    Fini_Create("Fini.ini");
    Fini_Create("Dfile.ini");

    //write
    new super[20];
    format(super,sizeof(super),"super dooper string");

    print("write times:");
    new ticks = GetTickCount();
    for(new i=0;i<maxtests;i++)
    {
        cini_FSave("cini.ini","s",
        "cessil",super
        );
    }
    printf("cini write time     %d",GetTickCount() - ticks);
    ticks = GetTickCount();
    for(new i=0;i<maxtests;i++)
    {
        dini_Set("dini.ini","cessil",super);
    }
    printf("dini write time     %d",GetTickCount() - ticks);

    ticks = GetTickCount();
    Fini_OpenFile("Fini.ini");
    for(new i=0;i<maxtests;i++)
    {
        Fini_SetStr("cessil",super);
    }
    Fini_SaveFile();
    Fini_CloseFile();
    printf("fini write time     %d",GetTickCount() - ticks);


    ticks = GetTickCount();
    dfile_Open("Dfile.ini");
    for(new i=0;i<maxtests;i++)
    {
        dfile_WriteString ("cessil",super);
    }
    dfile_SaveFile();
    printf("dfile write time     %d",GetTickCount() - ticks);
   
    //read
    print("\n-----------------------------");
    print(" ini file system speed tests read");
    print("-----------------------------\n");

    print("read times:");
    ticks = GetTickCount();
    for(new i=0;i<maxtests;i++)
    {
        new string[64];
        cini_FLoad("cini.ini","s","cessil",string);
    }
    printf("cini read  time     %d",GetTickCount() - ticks);
    ticks = GetTickCount();
    for(new i=0;i<maxtests;i++)
    {
        dini_Get("dini.ini","cessil");
    }
    printf("dini read time     %d",GetTickCount() - ticks);

    ticks = GetTickCount();
    Fini_OpenFile("Fini.ini");
    for(new i=0;i<maxtests;i++)
    {
        Fini_GetStr("cessil");
    }
    Fini_SaveFile();
    Fini_CloseFile();
    printf("fini read time     %d",GetTickCount() - ticks);


    ticks = GetTickCount();
    dfile_Open("Dfile.ini");
    for(new i=0;i<maxtests;i++)
    {
        new string[64];
        dfile_ReadString ("cessil",string);
    }
    dfile_SaveFile();
    printf("dfile read time     %d",GetTickCount() - ticks);
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#define maxtag   (00244)
#define maxfile    (99999)
#define maxname (00064)

#define Fini_Exists             fexist
#define Fini_GetFloat(%0)       floatstr(Fini_GetStr(%0))

static
    zNormal1,
    zNormal2,
    fStr[maxtag],
    fTag[maxtag],
    fFile[maxfile],
    File:zFopenFile,
    fName[maxname],
    iSource
;

stock
    Fini_OpenFile(fname[])
{
    zFopenFile = fopen(fname,io_read);

    while(fread(zFopenFile,fStr))
        strins(fFile,fStr,strlen(fFile),maxfile);

    fclose(zFopenFile);
    format(fName,maxname,"%s",fname);
    return true;
}

stock
    Fini_SaveFile()
{
    fremove(fName);
    zFopenFile = fopen(fName,io_write);

    fwrite(zFopenFile,fFile);
    fclose(zFopenFile);
    return true;
}

stock
    Fini_CloseFile()
{
    fFile[0] = '\0';
    fName[0] = '\0';
    return true;
}

stock
    Fini_GetStr(ftag[])
{
    zNormal1 = strfind(fFile,ftag,true);
    zNormal2 = (zNormal1 + (strlen(ftag)));
    strmid(fTag,fFile,zNormal2,(zNormal2  + maxtag),maxtag);
    zNormal2 = strfind(fTag,"\n",true);
    strmid(fStr,fTag,1,zNormal2 ,maxtag);
    return fStr;
}


stock
    Fini_SetStr(ftag[],fstr[])
{
   
    zNormal1 = strfind(fFile,ftag,true);
    if(zNormal1 != -1)
    {
        format(fTag,maxtag,"%s=%s",ftag,Fini_GetStr(ftag));
        iSource = strlen( fTag ) + zNormal1;
        format(fStr,maxtag,"%s=%s\r",ftag,fstr);
        strdel(fFile,zNormal1  ,iSource);
        format(fStr,128,"%s",fStr);
        strins(fFile,fStr,zNormal1 ,128);
    }
    else
    {
        format(fStr,maxtag,"%s=%s\r\n",ftag,fstr);
        strins(fFile,fStr,strlen(fFile));
    }
    return true;
}

stock
    Fini_Create(nFile[])
{
    if (Fini_Exists(nFile)) return false;
    new File:cFile = fopen(nFile,io_write);
    return fclose(cFile);
}

stock
    Fini_SetVal(ftag[],fval)
{
    static Seting[24];
    format(Seting,maxtag,"%d",fval);
    Fini_SetStr(ftag,Seting);
    return true;
}

stock
    Fini_SetFloat(ftag[],Float:fval)
{
    static Seting[24];
    format(Seting,maxtag,"%f",fval);
    Fini_SetStr(ftag,Seting);
    return true;
}

stock
    Fini_SetBool(ftag[],bool:fval)
{
    static Seting[24];
    format(Seting,maxtag,"%d",fval);
    Fini_SetStr(ftag,Seting);
    return true;
}

stock
    Fini_IsSet(ftag[])
{
    format(fTag,maxtag,"%s=%s",ftag,Fini_GetStr(ftag));
    zNormal1 = strfind(fFile,ftag,true);
    if(zNormal1 != -1)
        return true;
    return false;
}

stock Fini_GetBool(ftag[])
{
    new Seting = strval(Fini_GetStr(ftag));
    return Seting;
}

native file_move(file[],destination[]);
native file_delete(file[]);
native file_create(file[]);
native file_write(file[],text[],mode[] = "a");
native file_read(file[],storage[], size = sizeof(storage));
native file_log();
native file_exists(file[]);
native dir_create(directory[]);
native dir_delete(directory[]);
native dir_exists(directory[]);

stock Fini_GetValue(ftag[])
{
    new Seting = strval(Fini_GetStr(ftag));
    return Seting;
}
/*
| cessil's ini system (cini)
| version: 1.0
| date: 26/1/2010
| stocks:
| cini_Register(playerid,pass[]);                   creates a user file with a password
| cini_CheckAccount(playerid,pass[]);               checks if an account exists
| cini_Save(playerid,typedefs[],{Float,_}:...);     clears an account file and writes specified stats
| cini_Add(playerid,typedefs[],{Float,_}:...);      similar to cini_Save but it adds to an existing file and doesn't clear it
| cini_Load(playerid,typedefs[],{Float,_}:...);     returns data from a user file
| cini_Update(playerid,typedefs[],{Float,_}:...);   replaces key values with new ones
| cini_DelKey(playerid,typedefs[],{Float,_}:...);   deletes a key from a user file
| cini_Delete(playerid)                             deletes a user file
| cini_EscapeString(text[]);                        cancels out \n and \r, it's not needed if you don't save then load after registration
| cini_Create(filen[],typedefs[],{Float,_}:...);    creates an empty file
| cini_FSave(filen[],typedefs[],{Float,_}:...);     similar to cini_Save but first arg requires a filename not playerid and does not check if file exists first
| cini_FLoad(filen[],typedefs[],{Float,_}:...);     similar to cini_Load but first arg requires a filename not playerid
| cini_FUpdate(filen[],typedefs[],{Float,_}:...);   similar to cini_Update but first arg requires a filename not playerid
| cini_FDelKey(filen[],typedefs[],{Float,_}:...);   similar to cini_DelKey but first arg requires a filename not playerid
*/


#include <a_samp>

#define cini_max_filename           40              //max size of /folder/name.ini
#define cini_max_string             256             //max string for saving total data
#define cini_max_password_length    20              //maximum password length, use longer if you're encrypting especially whirlpool
#define cini_string                 48              //this is like "Password=security" strings
#define cini_file_location          "/accounts/"    //folder to save accounts to

  /*==================/
 / for user accounts /
/==================*/

stock cini_Register(playerid, pass[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new filename[cini_max_filename];
    new string[cini_max_string];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(fexist(filename)) return false;
    new File:file = fopen(filename,io_write);
    format(string,sizeof(string),"Password=%s\n",pass);
    fwrite(file,string);
    fclose(file);
    if(fexist(filename)) return true;
    return false;
}

stock cini_CheckAccount(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename)) return false;
    return true;
}

stock cini_CheckLogin(playerid,pass[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new filename[cini_max_filename];
    new string[cini_max_string];
    new password[cini_max_password_length];
    format(password,sizeof(password),"%s",pass);
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename)) return false;
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        if(strfind(string,"Password=",false,0) == 0)
        {
            strdel(string,0,strfind(string,"=",true)+1);
            strdel(string,strlen(string)-1,strlen(string));
            if(!strcmp(password,string,false))
            {
                fclose(file);
                return true;
            }
        }
    }
    fclose(file);
    return false;
}

stock cini_Save(playerid,typedefs[],{Float,_}:...)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new types[64];
    new string[cini_max_string];
    new filename[cini_max_filename];
    format(types,sizeof(types),"%s",typedefs);
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_Save account %s does not exist",filename);
        return false;
    }
    if(strlen(types) != (numargs() - 2) / 2)
    {
        printf("cini error: cini_Save type definitions expected: %d got: %d",strlen(types),(numargs() - 2) / 2);
        return false;
    }
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        if(strfind(string,"Password=",false) != -1) break;
    }
    if(!strlen(string)) //checks the account has a password
    {
        fclose(file);
        printf("cini error: cini_Save, Password not found for %s",filename);
        return false;
    }
    fclose(file);
    file = fopen(filename,io_write);
    for(new i=0;i<strlen(types);i++)
    {
        new tstr[cini_string];
        for(new l=0;l<cini_string;l++)
        {
            tstr[l] = getarg(2 + (i * 2), l);
        }
        format(string,sizeof(string),"%s%s=",string,tstr);
        switch(types[i])
        {
            case 'd', 'i':
            {
                format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
            }
            case 'f':
            {
                format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
            }
            case 's':
            {
                new tsrt[cini_string];
                for(new l=0;l<cini_string;l++)
                {
                    tsrt[l] = getarg(3 + (i * 2), l);
                }
                format(string,sizeof(string),"%s%s\n",string,tsrt);
            }
            default:
            {
                fclose(file);
                print("cini error: cini_Save unknown type passed in type definitions");
                return false;
            }
        }
    }
    fwrite(file,string);
    fclose(file);
    return true;
}

stock cini_Add(playerid,typedefs[],{Float,_}:...)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new types[64];
    new string[cini_max_string];
    new filename[cini_max_filename];
    format(types,sizeof(types),"%s",typedefs);
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_Add account %s does not exist",filename);
        return false;
    }
    if(strlen(types) != (numargs() - 2) / 2)
    {
        printf("cini error: cini_Add type definitions expected: %d got: %d",strlen(types),(numargs() - 2) / 2);
        return false;
    }
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        if(strfind(string,"Password=",false) != -1) break;
    }
    if(!strlen(string)) //checks the account has a password
    {
        fclose(file);
        printf("cini error: cini_Add, Password not found for %s",filename);
        return false;
    }
    fclose(file);
    string = "";
    file = fopen(filename,io_append);
    for(new i=0;i<strlen(types);i++)
    {
        new tstr[cini_string+2];
        for(new l=0;l<cini_string;l++)
        {
            tstr[l] = getarg(2 + (i * 2), l);
        }
        format(string,sizeof(string),"%s%s=",string,tstr);
        switch(types[i])
        {
            case 'd', 'i':
            {
                format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
            }
            case 'f':
            {
                format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
            }
            case 's':
            {
                tstr = "";
                for(new l=0;l<cini_string;l++)
                {
                    tstr[l] = getarg(3 + (i * 2), l);
                }
                format(string,sizeof(string),"%s%s\n",string,tstr);
            }
            default:
            {
                fclose(file);
                print("cini error: cini_Add unknown type passed in type definitions");
                return false;
            }
        }
    }
    fwrite(file,string);
    fclose(file);
    return true;
}

stock cini_Load(playerid,typedefs[],{Float,_}:...)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new types[64];
    new args = numargs() - 2;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_Load account %s does not exist",filename);
        return false;
    }
    format(types,sizeof(types),"%s",typedefs);
    if(!strlen(types) || args <= 0)
    {
        print("cini error: cini_Load missing parameters");
        return false;
    }
    if(strlen(types) != args / 2)
    {
        printf("cini error: cini_Load type definitions expected: %d got: %d",strlen(types),args / 2);
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<strlen(types);i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(2 + (i * 2), l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(strcmp(tstr,key,false) || !strlen(tstr)) continue;
            strdel(string,0,strfind(string,"=",true)+1);
            strdel(string,strlen(string)-1,strlen(string));
            switch(types[i])
            {
                case 'd', 'i':
                {
                    setarg(3 + (i * 2), 0, strval(string));
                }
                case 'f':
                {
                    setarg(3 + (i * 2),0,_:floatstr(string));
                }
                case 's':
                {
                    new strin[cini_string];
                    format(strin,sizeof(strin),"%s",string);
                    for(new l=0;l<cini_string;l++)
                    {
                        setarg(3 + (i * 2),l,strin[l]);
                    }
                }
                default:
                {
                    fclose(file);
                    print("cini error: cini_Load unknown type passed in type definitions");
                    return false;
                }
            }
        }
    }
    fclose(file);
    return true;
}

stock cini_Update(playerid,typedefs[],{Float,_}:...)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new types[64];
    new args = numargs() - 2, updated = 0;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_Update account %s does not exist",filename);
        return false;
    }
    format(types,sizeof(types),"%s",typedefs);
    if(!strlen(types) || args <= 0)
    {
        print("cini error: cini_Update missing parameters");
        return false;
    }
    if(strlen(types) != args / 2)
    {
        printf("cini error: cini_Update type definitions expected: %d got: %d",strlen(types),args / 2);
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new store[cini_max_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<strlen(types);i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(2 + (i * 2), l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(strcmp(tstr,key,false) || !strlen(tstr)) continue;
            updated++;
            strdel(string,strfind(string,"=",true)+1,strlen(string));
            switch(types[i])
            {
                case 'd', 'i':
                {
                    format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
                }
                case 'f':
                {
                    format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
                }
                case 's':
                {
                    new tsrt[cini_string];
                    for(new l=0;l<cini_string;l++)
                    {
                        tsrt[l] = getarg(3 + (i * 2), l);
                    }
                    format(string,sizeof(string),"%s%s\n",string,tsrt);
                }
                default:
                {
                    fclose(file);
                    print("cini error: cini_Update unknown type passed in type definitions");
                    return false;
                }
            }
        }
        strcat(store,string,sizeof(store));
    }
    if(strlen(types) != updated) printf("cini warning: cini_Update attempted to update %d keys, updated %d",strlen(types),updated);
    fclose(file);
    file = fopen(filename,io_write);
    fwrite(file,store);
    fclose(file);
    return true;
}

stock cini_DelKey(playerid,{Float,_}:...)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new args = numargs() - 1, deleted = 0;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_DelKey account %s does not exist",filename);
        return false;
    }
    if(args <= 0)
    {
        print("cini error: cini_DelKey missing parameters");
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new store[cini_max_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<args;i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(1 + i , l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(!strcmp(tstr,key,false) || !strlen(tstr))
            {
                deleted++;
                continue;
            }
            strcat(store,string,sizeof(store));
        }
    }
    if(args != deleted) printf("cini warning: cini_DelKey attempted to delete %d keys, deleted %d",args,deleted);
    fclose(file);
    file = fopen(filename,io_write);
    fwrite(file,store);
    fclose(file);
    return true;
}

stock cini_Delete(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s%s.ini",cini_file_location,name);
    print(filename);
    if(fremove(filename)) return true;
    return false;
}

stock cini_EscapeString(text[])
{
    new string[cini_string];
    format(string,sizeof(string),"%s",text);
    for(new i=0;i<strlen(string);i++)
    {
        if(string[i] == '\n') strdel(string,i,i+1);
        if(string[i] == '\r') strdel(string,i,i+1);
    }
    return string;
}

  /*==================/
 /  for other files  /
/==================*/

stock cini_Create(filen[])
{
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s",filen);
    if(fexist(filename)) return false;
    new File:file = fopen(filename,io_write);
    fclose(file);
    if(!fexist(filename)) return false;
    return true;
}

stock cini_FSave(filen[],typedefs[],{Float,_}:...)
{
    new types[64];
    new string[cini_max_string];
    new filename[cini_max_filename];
    format(types,sizeof(types),"%s",typedefs);
    format(filename,sizeof(filename),"%s",filen);
    if(strlen(types) != (numargs() - 2) / 2)
    {
        printf("cini error: cini_FSave type definitions expected: %d got: %d",strlen(types),(numargs() - 2) / 2);
        return false;
    }
    new File:file = fopen(filename,io_write);
    for(new i=0;i<strlen(types);i++)
    {
        new tstr[cini_string];
        for(new l=0;l<cini_string;l++)
        {
            tstr[l] = getarg(2 + (i * 2), l);
        }
        format(string,sizeof(string),"%s%s=",string,tstr);
        switch(types[i])
        {
            case 'd', 'i':
            {
                format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
            }
            case 'f':
            {
                format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
            }
            case 's':
            {
                new tsrt[cini_string];
                for(new l=0;l<cini_string;l++)
                {
                    tsrt[l] = getarg(3 + (i * 2), l);
                }
                format(string,sizeof(string),"%s%s\n",string,tsrt);
            }
            default:
            {
                fclose(file);
                print("cini error: cini_FSave unknown type passed in type definitions");
                return false;
            }
        }
    }
    fwrite(file,string);
    fclose(file);
    return true;
}

stock cini_FAdd(filen[],typedefs[],{Float,_}:...)
{
    new types[64];
    new string[cini_max_string];
    new filename[cini_max_filename];
    format(types,sizeof(types),"%s",typedefs);
    format(filename,sizeof(filename),"%s",filen);
    if(!fexist(filename))
    {
        printf("cini error: cini_FAdd file %s does not exist",filename);
        return false;
    }
    if(strlen(types) != (numargs() - 2) / 2)
    {
        printf("cini error: cini_FAdd type definitions expected: %d got: %d",strlen(types),(numargs() - 2) / 2);
        return false;
    }
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        if(strfind(string,"Password=",false) != -1) break;
    }
    if(!strlen(string)) //checks the account has a password
    {
        fclose(file);
        printf("cini error: cini_FAdd, Password not found for %s",filename);
        return false;
    }
    fclose(file);
    string = "";
    file = fopen(filename,io_append);
    for(new i=0;i<strlen(types);i++)
    {
        new tstr[cini_string+2];
        for(new l=0;l<cini_string;l++)
        {
            tstr[l] = getarg(2 + (i * 2), l);
        }
        format(string,sizeof(string),"%s%s=",string,tstr);
        switch(types[i])
        {
            case 'd', 'i':
            {
                format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
            }
            case 'f':
            {
                format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
            }
            case 's':
            {
                tstr = "";
                for(new l=0;l<cini_string;l++)
                {
                    tstr[l] = getarg(3 + (i * 2), l);
                }
                format(string,sizeof(string),"%s%s\n",string,tstr);
            }
            default:
            {
                fclose(file);
                print("cini error: cini_FAdd unknown type passed in type definitions");
                return false;
            }
        }
    }
    fwrite(file,string);
    fclose(file);
    return true;
}

stock cini_FLoad(filen[],typedefs[],{Float,_}:...)
{
    new types[64];
    new args = numargs() - 2;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s",filen);
    if(!fexist(filename))
    {
        printf("cini error: cini_FLoad file %s does not exist",filename);
        return false;
    }
    format(types,sizeof(types),"%s",typedefs);
    if(!strlen(types) || args <= 0)
    {
        print("cini error: cini_FLoad missing parameters");
        return false;
    }
    if(strlen(types) != args / 2)
    {
        printf("cini error: cini_FLoad type definitions expected: %d got: %d",strlen(types),args / 2);
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<strlen(types);i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(2 + (i * 2), l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(strcmp(tstr,key,false) || !strlen(tstr)) continue;
            strdel(string,0,strfind(string,"=",true)+1);
            strdel(string,strlen(string)-1,strlen(string));
            switch(types[i])
            {
                case 'd', 'i':
                {
                    setarg(3 + (i * 2), 0, strval(string));
                }
                case 'f':
                {
                    setarg(3 + (i * 2),0,_:floatstr(string));
                }
                case 's':
                {
                    new strin[cini_string];
                    format(strin,sizeof(strin),"%s",string);
                    for(new l=0;l<cini_string;l++)
                    {
                        setarg(3 + (i * 2),l,strin[l]);
                    }
                }
                default:
                {
                    fclose(file);
                    print("cini error: cini_FLoad unknown type passed in type definitions");
                    return false;
                }
            }
        }
    }
    fclose(file);
    return true;
}

stock cini_FUpdate(filen[],typedefs[],{Float,_}:...)
{
    new types[64];
    new args = numargs() - 2, updated = 0;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s",cini_file_location,name);
    if(!fexist(filename))
    {
        printf("cini error: cini_FUpdate file %s does not exist",filename);
        return false;
    }
    format(types,sizeof(types),"%s",typedefs);
    if(!strlen(types) || args <= 0)
    {
        print("cini error: cini_FUpdate missing parameters");
        return false;
    }
    if(strlen(types) != args / 2)
    {
        printf("cini error: cini_FUpdate type definitions expected: %d got: %d",strlen(types),args / 2);
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new store[cini_max_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<strlen(types);i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(2 + (i * 2), l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(strcmp(tstr,key,false) || !strlen(tstr)) continue;
            updated++;
            strdel(string,strfind(string,"=",true)+1,strlen(string));
            switch(types[i])
            {
                case 'd', 'i':
                {
                    format(string,sizeof(string),"%s%d\n",string,getarg(3 + (i * 2)));
                }
                case 'f':
                {
                    format(string,sizeof(string), "%s%f\n",string,Float:getarg(3 + (i * 2)));
                }
                case 's':
                {
                    new tsrt[cini_string];
                    for(new l=0;l<cini_string;l++)
                    {
                        tsrt[l] = getarg(3 + (i * 2), l);
                    }
                    format(string,sizeof(string),"%s%s\n",string,tsrt);
                }
                default:
                {
                    fclose(file);
                    print("cini error: cini_FUpdate unknown type passed in type definitions");
                    return false;
                }
            }
        }
        strcat(store,string,sizeof(store));
    }
    if(strlen(types) != updated) printf("cini warning: cini_FUpdate attempted to update %d keys, updated %d",strlen(types),updated);
    fclose(file);
    file = fopen(filename,io_write);
    fwrite(file,store);
    fclose(file);
    return true;
}

stock cini_FDelKey(filen[],{Float,_}:...)
{
    new args = numargs() - 1, deleted = 0;
    new filename[cini_max_filename];
    format(filename,sizeof(filename),"%s",cini_file_location,filen);
    if(!fexist(filename))
    {
        printf("cini error: cini_FDelKey file %s does not exist",filename);
        return false;
    }
    if(args <= 0)
    {
        print("cini error: cini_FDelKey missing parameters");
        return false;
    }
    new key[cini_string];
    new string[cini_string];
    new store[cini_max_string];
    new File:file = fopen(filename,io_read);
    while(fread(file,string))
    {
        for(new i=0;i<args;i++)
        {
            new tstr[cini_string];
            for(new l=0;l<cini_string;l++)
            {
                tstr[l] = getarg(1 + i , l);
            }
            format(key,cini_string,"%s",string);
            strdel(key,strfind(key,"=",true),strlen(key));
            if(!strcmp(tstr,key,false) || !strlen(tstr))
            {
                deleted++;
                continue;
            }
            strcat(store,string,sizeof(store));
        }
    }
    if(args != deleted) printf("cini warning: cini_FDelKey attempted to delete %d keys, deleted %d",args,deleted);
    fclose(file);
    file = fopen(filename,io_write);
    fwrite(file,store);
    fclose(file);
    return true;
}


#define dfile_ReadFloat(%1,%2) floatstr(dfile_ReadString(%1,%2))
#define dfile_ReadInt(%1,%2) strval(dfile_ReadString(%1,%2))
#define dfile_ReadBool(%1,%2) boolstr2(dfile_ReadString(%1,%2))
#define dfile_FileExists(%1) file_exists(%1)
#define dfile_DirectoryExists(%1) dir_exists(%1)

#define MAX_STRING 256
#define FILE_SIZE (99999)
#define FILE_NAME (00064)

static  tarolo[FILE_SIZE],
        fajlnev[FILE_NAME],
        olvasas[FILE_SIZE];


stock dfile_Delete(fajl[]){
    if(!file_exists(fajl)) return false;
    file_delete(fajl);
    return true;
}

stock dfile_ReadString(fajl[],parameter[]){
    new ertek[MAX_STRING],
        eredmeny[MAX_STRING],
        talalat;
    eredmeny[0]=EOS;
    olvasas[0]=EOS;
    if(!file_exists(fajl)) return eredmeny;
    file_read(fajl, olvasas);
    format(ertek, sizeof(ertek), "%s=", parameter);
    talalat = strfind(olvasas, ertek, false);
    if(talalat != -1){strmid(eredmeny, olvasas, talalat+strlen(ertek), strfind(olvasas, "\n", false, talalat+1)); return eredmeny;}
    else return eredmeny;
}

stock dfile_Open(fajl[]){
    if(!fexist(fajl)) return false;
    format(fajlnev, FILE_NAME, "%s", fajl);
    return true;
}

stock dfile_WriteString(parameter[], ertek[])
{
    new string[128];
    if(fajlnev[0] == 0) return false;
    format(string,sizeof(string), "%s=", parameter);
    new talalat = strfind(tarolo, string, false, 0);
    if(talalat == -1)
    {
        format(string, sizeof(string), "%s=%s\n", parameter, ertek);
        strins(tarolo, string, strlen(tarolo));
    }else{
        strdel(tarolo, talalat-1, strfind(tarolo, "\n", false, talalat));
        format(string, sizeof(string), "%s=%s\n", parameter, ertek);
        strins(tarolo, string, strlen(tarolo));
    }
    return true;
}

stock dfile_SaveFile()
{
    if(strlen(tarolo) == 0) return false;
    file_delete(fajlnev);
    file_create(fajlnev);
    file_write(fajlnev, tarolo);
    tarolo[0] = EOS;
    fajlnev[0] = EOS;
    return true;
}

stock dfile_WriteInt(parameter[], ertek){
    new intvalue[MAX_STRING];
    format(intvalue, sizeof(intvalue), "%d", ertek);
    return dfile_WriteString(parameter, intvalue);
}

stock dfile_WriteBool(parameter[], bool:ertek){
    if(ertek) dfile_WriteString(parameter, "true");
    else dfile_WriteString(parameter, "false");
    return true;
}

stock dfile_WriteFloat(parameter[], Float:ertek){
    new floatvalue[MAX_STRING];
    format(floatvalue, sizeof(floatvalue), "%f", ertek);
    return dfile_WriteString(parameter, floatvalue);
}

stock bool:boolstr2(string[]){
    if (!string[0] || string[0] == '0' || !strcmp(string, "false", true)) return false;
    return true;
}

stock dfile_CreateDirectory(mappa[]){
    if(dir_exists(string)) return false;
    dir_create(mappa);
    return true;
}

stock dfile_DeleteDirectory(mappa[]){
    if(!dir_exists(mappa)) return false;
    dir_delete(mappa);
    return true;
}

stock dfile_MoveFile(fajl[], cel[]){
    if(!file_exists(fajl)) return false;
    file_move(fajl, cel);
    return true;
}

stock dfile_ParseString(fajl[], parameter[], ertek[])
{
    new string[128], string2[128];
    format(string, sizeof(string), "%s", dfile_ReadString(fajl, parameter));
    format(string2, sizeof(string), "%s", ertek);
    if(!strcmp(string, string2, false)) return true;
    return false;
}

stock dfile_ParseInt(fajl[], parameter[], ertek)
{
    new intvalue[MAX_STRING];
    format(intvalue, sizeof(intvalue), "%d", ertek);
    return dfile_ParseString(fajl, parameter, intvalue);
}

stock dfile_ParseFloat(fajl[], parameter[], Float:ertek)
{
    new floatvalue[MAX_STRING];
    format(floatvalue, sizeof(floatvalue), "%f", ertek);
    return dfile_ParseString(fajl, parameter, floatvalue);
}

stock dfile_ParseBool(fajl[], parameter[], bool:ertek)
{
    new string[128], string2[128];
    format(string, sizeof(string), "%s", boolstr2(dfile_ReadString(fajl, parameter)));
    format(string2, sizeof(string), "%s", ertek);
    if(strcmp(string, string2, false)) return true;
    return false;
}
Fini is Slow in a Multiple Keys,but is much faster in keys normals (example: 15 keys in max)




EDIT
I Include SII

Код:
-----------------------------
[13:02:10]  ini file system speed tests write
[13:02:10] -----------------------------

[13:02:10] write times:
[13:02:12] cini write time     2100
[13:02:21] dini write time     9087
[13:02:21] sii write time     46
[13:02:21] fini write time     98
[13:02:21] dfile write time     27
[13:02:21] 
-----------------------------
[13:02:21]  ini file system speed tests read
[13:02:21] -----------------------------

[13:02:21] read times:
[13:02:22] cini read  time     696
[13:02:22] dini read time     3760
[13:02:22] sii write time     420
[13:02:22] fini read time     69
[13:02:22] dfile read time     172
Reply
#16

If you go above 5k line (in test) the fini don't write anything to the file. check it (For me) And if u see my file create next to samp-server.exe not to scriptfiles folder.
Reply
#17

Please add
Код:
dfile_RenameDirectory(oldname [], newname []);
Thanks
Reply
#18

Drake1994
Yeah,No one uses more than 1 kb in a file.

So 383 kbps is too much! (is limit of Fini)
So forget that argument.

Hugs

EDIT
I made test of write using YINI

Код:
[13:27:48] cini write time     2105
[13:27:57] dini write time     8388
[13:27:57] sii write time     46
[13:27:57] fini write time     95
[13:27:57] dfile write time     25
[13:27:57] yini write time     21
Reply
#19

Obviously there is something wrong with all of your tests (goes to most of you). You either:
a) Do some trick with your system to make it look faster (in the test).
b) The time it took to execute blablabla is fake.
c) You don't really know what you're doing.
d) You only test the stuff you know your system is fast at.

Looking forward to ******'s tests, as atleast he know what he's doing.
Reply
#20

My result:


Test script:
Код:
#include <a_samp>
#include <dfile>
#include <Fini>

#define TESZT 500

public OnFilterScriptInit()
{
	new string[128];
    dfile_Create("Dfile.txt");
    dfile_Create("scriptfiles/Fini.txt");

    new Dfile = GetTickCount();

  	dfile_Open("Dfile.txt");
  	print("\n\n\n");
  	print("Writing data:");
  	print("----------------------------");
    for(new i; i < TESZT; i++)
    {
        format(string, sizeof(string), "teszt%d", i);
        dfile_WriteString(string, "test");
    }
    dfile_SaveFile();
    printf("[DFILE] writing time: %d", GetTickCount() - Dfile);

    new Fini = GetTickCount();

    Fini_OpenFile("Fini.txt");
    for(new i; i < TESZT; i++)
    {
       format(string, sizeof(string), "test%d", i);
       Fini_SetStr(string, "test");
    }
	Fini_SaveFile();
    Fini_CloseFile();
    printf("[FINI] writing time: %d", GetTickCount() - Fini);
    printf("\n\n\n");
    print("Reading data:");
    print("----------------------------");
    Dfile = GetTickCount();
    dfile_Open("Dfile.txt");
    new dfilevalue, finivalue;
    while(GetTickCount() - Dfile < 1000)
    {
        dfile_ReadString("teszt1");
        dfilevalue++;
    }
    dfile_CloseFile();
    printf("[DFILE] reading time: %d", dfilevalue);
    Fini = GetTickCount();
    Fini_OpenFile("Fini.txt");
    while(GetTickCount() - Fini < 1000)
    {
        Fini_GetStr("test1");
        finivalue++;
    }
    Fini_CloseFile();
    printf("[FINI] readingtime: %d", finivalue);
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)