Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _______
- |:::::::| __ __ ___ ____ __ TM
- |::| \::\ /::/ /::::| |::::| |::|
- |:::::| \::\/::/ /::/ |::| |::|
- |::| /::/\::\ \::\ |::::| |::|
- |:::::::| /::/ \::\ \::::| |::| |::::::|
- |::::|
- [Include] e_admin | New advance admin include | v1
- By Excel
- * Drake1994 - For script help with his dFile include
- Copyright (c) 2013
- All Rights Reserved
- */
- //======================================
- #include <a_samp>
- //======================================
- /*
- ------------> E_Functions Information: <------------
- * efile_create - Create a file.
- * efile_delete - Delete a file.
- * efile_open - Open a file.
- * efile_close - Close a file.
- * efile_WriteString - Write string to the file.
- * efile_writeint - Write integer to the file.
- * efile_writebool - Write a bool integer to the file.
- * efile_writefloat - Write a float integer to the file.
- * efile_multiset - Write multi parameter and value to the file.
- * efile_multiget - Get multi parameter and value from the file.
- * efile_readstring - Read a string from the file.
- * efile_ReadInt - Read an integer from the file.
- * efile_ReadFloat - Read a float integer from the file.
- * efile_movefile - Move a file to the destination.
- * efile_renamefile - Rename a file.
- * efile_savefile - Write the cache to the file.
- * efile_FileExists - Check if the file exists.
- * efile_isset - Check if the parameter has value.
- * efile_unset - Delete the parameter's value.
- * efile_parsestring - Check if the parameter and the string is equal.
- * efile_ParseInt - Check if the parameter and the integer is equal.
- * efile_ParseFloat - Check if the parameter and the float is equal.
- * efile_ParseBool - Check if the parameter and the bool is equal.
- */
- //======================================
- #if defined _e_file_included
- #endinput
- #endif
- #define _e_file_included
- //======================================
- /*
- ------------> E_Natives <------------
- native efile_create(location[]);
- native efile_delete(location[]);
- native efile_open(location[]);
- native efile_close();
- native efile_writestring(parameter[], value[]);
- native efile_writeint(parameter[], value[]);
- native efile_writebool(parameter[], bool:value);
- native efile_writefloat(parameter[], Float.value);
- native efile_multiset(type[],{Float,_}:...);
- native efile_multiget(type[],{Float,_}:...);
- native efile_readstring(parameter[]);
- native efile_ReadInt(parameter[]);
- native efile_ReadFloat(parameter[]);
- native efile_ReadBool(parameter[]);
- native efile_movefile(location[], newlocation[]);
- native efile_renamefile(location[], newname[]);
- native efile_savefile();
- native efile_exists(location[]);
- native efile_isset(parameter[]);
- native efile_unset(parameter[]);
- native efile_parsestring(parameter[], value[]);
- native efile_parseint(parameter[], value);
- native efile_parsefloat(parameter[], Float:value);
- native efile_parsebool(parameter[], bool:value);
- */
- //======================================
- #define \
- efile_writestring(%0,%1) \
- efile_buffer(%0,%1)
- #if !defined \
- strcpy
- #define \
- strcpy(%0,%1,%2) \
- strcat((%0[0] = EOS, %0), %1, %2 + 1)
- #endif
- //======================================
- //======================================
- #define \
- MAX_PARAMETER_SIZE \
- (0x80)
- #define \
- MAX_ERTEK_SIZE \
- (0x100)
- #define \
- FILE_NAME \
- (0x40)
- #define \
- MAX_LINES \
- (0x3E8)
- //======================================
- //======================================
- static stock
- fajlnev[FILE_NAME], paramtar[MAX_PARAMETER_SIZE],
- formazas[512+3], olvasas[512],
- File:fajlmegnyitas, File:celfajl,
- eredmeny[256], sorokszama = 0;
- static stock
- parameternek[MAX_LINES],
- param[MAX_LINES][MAX_PARAMETER_SIZE],
- ert[MAX_LINES][MAX_ERTEK_SIZE];
- //======================================
- //======================================
- stock bool:boolstr2(string[]){
- if (!string[0] || string[0] == '0' || !strcmp(string, "false", true)) return false;
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_create(location[]);
- Usage: Creates a new directory in scriptfiles.
- */
- stock efile_create(location[])
- {
- if(fexist(location)) return false;
- fclose(fopen(location, io_write));
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_exists(location[]);
- Usage: Checks if the location given exists.
- */
- stock efile_exists(location[])
- { return fexist(location); }
- //======================================
- //======================================
- /*
- Function: efile_delete(location[]);
- Usage: Deletes the existing file defined.
- */
- stock efile_delete(location[])
- {
- if(!fexist(location)) return false;
- fremove(location);
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_readstring(parameter[]);
- Usage: Reads the string from the file.
- */
- stock efile_readstring(parameter[])
- {
- new
- i = 0x0;
- for(; i < sorokszama; ++i)
- {
- if(strcmp(param[i], parameter, false)) continue;
- return ert[i];
- }
- eredmeny[0] = EOS;
- return eredmeny;
- }
- //======================================
- //======================================
- /*
- Function: efile_open(location[]);
- Usage: Opens the existing file from scriptfiles.
- */
- stock efile_open(location[])
- {
- new
- sorokszama2 = 0x-1,
- talalat;
- olvasas[0] = EOS;
- fajlmegnyitas = fopen(location,io_read);
- while(fread(fajlmegnyitas, olvasas))
- {
- talalat = strfind(olvasas, "=", false);
- strmid(param[++sorokszama2], olvasas, 0, talalat);
- strmid(ert[sorokszama2], olvasas, talalat+1, strfind(olvasas, "\r\n", false));
- parameternek[sorokszama2] = efile_hashstring(param[sorokszama2]);
- }
- sorokszama = (sorokszama2 + 1);
- fclose(fajlmegnyitas);
- format(fajlnev,FILE_NAME,"%s",location);
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_hashstring(parameter[]);
- Usage: Hashes the string given in parameters.
- */
- stock efile_hashstring(parameter[])
- {
- new
- totalContado = 0, i = strlen(parameter);
- while(i-- != 0) totalContado += parameter[i];
- return totalContado;
- }
- //======================================
- //======================================
- /*
- Function: efile_writeint(parameter[], value);
- Usage: Write value to a new parameter.
- */
- stock efile_writeint(parameter[], value)
- {
- new
- intvalue[MAX_ERTEK_SIZE];
- format(intvalue, sizeof(intvalue), "%d", value);
- return efile_buffer(parameter, intvalue);
- }
- //======================================
- //======================================
- /*
- Function: efile_writebool(parameter[], bool:value);
- Usage: Write booling value to a new parameter.
- */
- stock efile_writebool(parameter[], bool:value)
- {
- if(value) efile_buffer(parameter, "true");
- else efile_buffer(parameter, "false");
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_writefloat(parameter[], Float:value);
- Usage: Write booling value to a new parameter.
- */
- stock efile_writefloat(parameter[], Float:value)
- {
- new
- floatvalue[MAX_ERTEK_SIZE];
- format(floatvalue, sizeof(floatvalue), "%f", value);
- return efile_buffer(parameter, floatvalue);
- }
- //======================================
- //======================================
- /*
- Function: efile_multiset(type[],{Float,_}:...);
- Usage: This is an advance way to set file data wheather its a bool, int, string or float.
- */
- stock efile_multiset(type[],{Float,_}:...)
- {
- new
- i = 0x-1;
- while(++i<strlen(type))
- {
- new
- l = 0x-1,
- iLoop = -1,
- string2[512];
- while(++l<MAX_PARAMETER_SIZE) paramtar[l] = getarg(1 + (i * 2), l);
- switch(type[i])
- {
- case 'b': efile_writebool(paramtar, bool:getarg(2 + (i * 2)));
- case 'd', 'i': efile_writeint(paramtar, getarg(2 + (i * 2)));
- case 'f': efile_writefloat(paramtar, Float:(getarg(2 + (i * 2))));
- case 's':
- {
- while((++iLoop != MAX_ERTEK_SIZE)) string2[iLoop] = getarg(2 + (i * 2), iLoop);
- efile_writestring(paramtar, string2);
- }
- }
- }
- return false;
- }
- //======================================
- //======================================
- /*
- Function: efile_multiget(tipusok[],{Float,_}:...);
- Usage: This is an advance way to get file data wheather its a bool, int, string or float.
- */
- stock efile_multiget(type[],{Float,_}:...)
- {
- new
- i = 0x-1;
- while(++i<strlen(type))
- {
- new
- l = 0x-1,
- iLoop = 0x-1;
- while(++l<MAX_PARAMETER_SIZE) paramtar[l] = getarg(1 + (i * 2), l);
- switch(type[i])
- {
- case 'b': setarg(2+(i*2), 0, boolstr2(efile_readstring(paramtar)));
- case 'd', 'i': setarg(2+(i*2), 0, strval(efile_readstring(paramtar)));
- case 'f': setarg(2+(i*2), 0, _:floatstr(efile_readstring(paramtar)));
- case 's':
- {
- format(formazas,sizeof(formazas),"%s",efile_readstring(paramtar));
- while((strlen(efile_readstring(paramtar)) != iLoop++)) setarg(2+(i*2),iLoop,formazas[iLoop]);
- }
- default: return print("e_file (ERROR): Unknown type defination."), 0;
- }
- }
- return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_close();
- Usage: This closes a file which is opened before this native.
- */
- stock efile_close()
- {
- new
- i = -1;
- for(; ++i != sorokszama ;)
- {
- param[i][0] = EOS;
- ert[i][0] = EOS;
- parameternek[i] = 0;
- }
- return sorokszama = 0;
- }
- //======================================
- //======================================
- /*
- Function: efile_savefile();
- Usage: Saves the data writen on file.
- */
- stock efile_savefile()
- {
- new
- iLoop = -1;
- fajlmegnyitas = fopen(fajlnev, io_write);
- while(++iLoop != sorokszama)
- {
- if(strlen(param[iLoop]) > 0)
- {
- format(formazas, sizeof(formazas), "%s=%s\r\n", param[iLoop], ert[iLoop]);
- fwrite(fajlmegnyitas, formazas);
- }else break;
- }
- return fclose(fajlmegnyitas);
- }
- //======================================
- //======================================
- /*
- Function: efile_renamefile(location[], newname[]);
- Usage: Rename the file.
- */
- stock efile_renamefile(location[], newname[])
- { return efile_movefile(location, newname); }
- //======================================
- //======================================
- /*
- Function: efile_movefile(location[], newlocation[]);
- Usage: Moves a existing file to a new location.
- */
- stock efile_movefile(location[], newlocation[])
- {
- if(!fexist(location)) return false;
- efile_create(newlocation);
- fajlmegnyitas = fopen(location, io_read);
- celfajl = fopen(newlocation, io_write);
- while(fread(fajlmegnyitas, olvasas)) fwrite(celfajl, olvasas);
- fclose(fajlmegnyitas);
- fclose(celfajl);
- fremove(location);
- return true;
- }
- //======================================
- //======================================
- stock efile_parsestring(parameter[], value[])
- {
- format(formazas, sizeof(formazas), "%s", efile_readstring(parameter));
- if(strval(efile_readstring(parameter)) == strval(value)) return true;
- else return false;
- }
- //======================================
- //======================================
- stock efile_parseint(parameter[], value)
- {
- new intvalue[MAX_PARAMETER_SIZE];
- format(intvalue, sizeof(intvalue), "%d", value);
- return efile_parsestring(parameter, intvalue);
- }
- //======================================
- //======================================
- stock efile_ParseFloat(parameter[], Float:value)
- {
- new floatvalue[MAX_PARAMETER_SIZE];
- format(floatvalue, sizeof(floatvalue), "%f", value);
- return efile_parsestring(parameter, floatvalue);
- }
- //======================================
- //======================================
- stock efile_ParseBool(parameter[], bool:value)
- {
- new boolean;
- if(value) boolean = efile_parsestring(parameter, "true");
- else boolean = efile_parsestring(parameter, "false");
- return boolean;
- }
- //======================================
- //======================================
- /*
- Function: efile_isset(parameter[]);
- Usage: Checks wheather the paramater has a value or not.
- */
- stock efile_isset(parameter[])
- {
- if(!strlen(efile_readstring(parameter))) return false;
- else return true;
- }
- //======================================
- //======================================
- /*
- Function: efile_unset(parameter[]);
- Usage: Reset the parameter value Or you can say it deletes it.
- */
- stock efile_unset(parameter[])
- {
- new
- i = 0x-1;
- for( ; ++i != sorokszama ; )
- {
- if(!strcmp(param[i], parameter, false))
- {
- return ert[i][0] = EOS;
- }
- }
- return true;
- }
- //======================================
- //======================================
- /*
- - Not Used -
- Function: efile_buffer(parameter[], str[]);
- Usage: Not in use for you.
- */
- stock efile_buffer(parameter[], str[])
- {
- new i, valami = efile_hashstring(parameter);
- for( ; i != sorokszama ; ++i) if(valami == parameternek[i])
- {
- if(strcmp(param[i], parameter, false)) continue;
- return strcpy(ert[i], str, MAX_ERTEK_SIZE);
- }
- parameternek[i]=valami;
- return strcpy(param[i], parameter, MAX_PARAMETER_SIZE), strcpy(ert[i], str, MAX_ERTEK_SIZE), sorokszama++, true;
- }
- //======================================
Advertisement
Add Comment
Please, Sign In to add comment