26.01.2011, 04:35
I should note that in a test on Cache Files OPEN / SAVE / CLOSE should stay out of the loop because it will run only in general 1x
I'm not have sii, tomorrow I results
pawn Код:
#include <a_samp>
#include <dini>
#define FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n-----------------------------");
print(" ini file system speed tests");
print("-----------------------------\n");
cini_Create("cini.ini");
dini_Create("dini.ini");
Fini_Create("Fini.ini");
new super[20];
format(super,sizeof(super),"super dooper string");
print("write times:");
new ticks = GetTickCount();
for(new i=0;i<1000;i++)
{
cini_FSave("cini.ini","sdf",
"cessil",super,
"digit",200,
"float",1.1
);
}
printf("cini write time %d",GetTickCount() - ticks);
ticks = GetTickCount();
for(new i=0;i<1000;i++)
{
dini_Set("dini.ini","cessil",super);
dini_IntSet("dini.ini","digit",200);
dini_FloatSet("dini.ini","float",1.1);
}
printf("dini write time %d",GetTickCount() - ticks);
ticks = GetTickCount();
Fini_OpenFile("Fini.ini");
for(new i=0;i<1000;i++)
{
Fini_SetStr("cessil","super");
Fini_SetVal("digit",200);
Fini_SetFloat("float",1.1);
}
Fini_SaveFile();
Fini_CloseFile();
printf("fini write time %d",GetTickCount() - ticks);
print("read times:");
#define Fini_GetFloat(%0) floatstr(Fini_GetStr(%0))
ticks = GetTickCount();
Fini_OpenFile("Fini.ini");
for(new i=0;i<1000;i++)
{
Fini_GetStr("cessil");
Fini_GetValue("digit");
Fini_GetFloat("float");
}
Fini_CloseFile();
printf("fini read time %d",GetTickCount() - ticks);
ticks = GetTickCount();
for(new i=0;i<1000;i++)
{
dini_Get("dini.ini","cessil");
dini_Int("dini.ini","digit");
dini_Float("dini.ini","float");
}
printf("dini read time %d",GetTickCount() - ticks);
new string[128], digit, Float:fl;
ticks = GetTickCount();
for(new i=0;i<1000;i++)
{
cini_FLoad("cini.ini","sdf",
"cessil",string,
"digit",digit,
"float",fl
);
}
printf("cini 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;
}
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;
}
Код:
[03:37:23] cini write time 222 [03:37:26] dini write time 2426 [03:37:26] fini write time 39 [03:37:26] read times: [03:37:26] fini read time 60 [03:37:26] dini read time 105 [03:37:26] cini read time 141