Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [|||||||] [|||||||] [||||||] [||] [||||||] [||||||] [|||] [||||||]
- [||] [||] [||] [||] [||] [||] [||][||] [||]
- [|||||] [|||||] [||] [||] [|||||] [||||||] [||] [||] [||] [||||||]
- [||] [||] [||] [||] [||] [||] [||][||] [||] |||]
- [||] [||] [||] [||||||] [||||||] [||||||] [||||||] [||] [||] [||] [||||||]
- Escreve somente inteiros em uma determinada palavra-chave.
- Macro: F_WIn
- F_WriteInt(file[], key[], value);
- Escreve somente textos em uma determinada palavra-chave.
- Macro: F_WSt
- F_WriteStr(file[], key[], value[]);
- Escreve somente float em uma determinada palavra-chave.
- Macro: F_WFl
- F_WriteFloat(file[], key[], Float:value);
- Escreve somente valores booleanos em uma determinada palavra-chave.
- Macro: F_WBo
- F_WriteBool(file[], key[], bool:value);
- Faz a leitura de inteiros em uma determinada palavra-chave.
- Macro: F_RIn
- F_ReadInt(file[], key[]);
- Faz a leitura de textos em uma determinada palavra-chave.
- Macro: F_RSt
- F_ReadStr(file[], key[]);
- Faz a leitura de float em uma determinada palavra-chave.
- Macro: F_RFl
- F_ReadFloat(file[], key[]);
- Faz a leitura de valores booleanos em uma determinada palavra-chave.
- Macro: F_RBo
- F_ReadBool(file[], key[]);
- Verifica se o arquivo existe.
- Macro: F_Ex
- F_Exists(file[])
- Cria determinado arquivo.
- Macro: F_Cr
- F_Create(file[]);
- Salva todos os dados de determinado arquivo.
- Macro: F_Sa
- F_Save(file[]);
- Faz um backup de determinado arquivo, renomeando-o para 'FileName_RandomNumber.fback'.
- Macro: F_Ba
- F_Backup(file[]);
- Faz uma busca para verificar se existe determinada palavra-chave com/sem case sensitive.
- Macro: F_FKe
- F_FindKey(file[], key[], true/false);
- Adiciona uma linha de texto em determinado arquivo. Pode ser utilizado como salvamento de logs.
- Macro: F_ASt
- F_AddStr(file[], str[]);
- */
- //________________________Configuration:________________________
- #define MAX_FILE_LINES 25
- #define MAX_LINE_CHARS 128
- #define DIVISION "="
- //________________________Shorter:________________________
- #define F_Exists F_Ex
- #define F_WriteInt F_WIn
- #define F_WriteStr F_WSt
- #define F_WriteFloat F_WFl
- #define F_WriteBool F_WBo
- #define F_ReadInt F_RIn
- #define F_ReadStr F_RSt
- #define F_ReadFloat F_RFl
- #define F_ReadBool F_RBo
- #define F_Create F_Cr
- #define F_Backup F_Ba
- #define F_FindKey F_FKe
- #define F_AddStr F_ASt
- //________________________Defines:________________________
- #define F_RFl(%0,%1) floatstr(F_ReadStr(%0,%1))
- //________________________Stocks:________________________
- stock F_Exists(file[])
- {
- print("DEBUG / F_Exists");
- return fexist(file);
- }
- stock F_Backup(file[])
- {
- print("DEBUG / F_Backup");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser salvo!\nMotivo: Arquivo não existe.\n\n");
- new File:Arquivo, String[MAX_FILE_LINES], Strcat[MAX_LINE_CHARS * MAX_FILE_LINES];
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, String);
- strcat(Strcat, String);
- }
- fclose(Arquivo);
- format(String, sizeof String, "%s_%i.fback", file, random(99999));
- Arquivo = fopen(String, io_write);
- fwrite(Arquivo, Strcat);
- return fclose(Arquivo);
- }
- stock F_Create(file[])
- {
- print("DEBUG / F_Create");
- new File:Arquivo;
- if(fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser criado!\nMotivo: Arquivo já existe.\n\n", file);
- Arquivo = fopen(file, io_write);
- return fclose(Arquivo);
- }
- stock F_AddStr(file[], str[])
- {
- print("DEBUG / F_AddStr");
- if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido / escrito!\nMotivo: Arquivo não existe.\n\n", file);
- else
- {
- new File:Arquivo, String[MAX_LINE_CHARS];
- Arquivo = fopen(file, io_append);
- format(String, sizeof String, "%s\r\n", str);
- fwrite(Arquivo, String);
- }
- return fclose(Arquivo);
- }
- stock F_ReadStr(file[], key[])
- {
- print("DEBUG / F_ReadStr");
- new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS];
- if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
- else
- {
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, String);
- if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
- }
- fclose(Arquivo);
- }
- return Value;
- }
- stock F_ReadInt(file[], key[])
- {
- print("DEBUG / F_ReadInt");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
- new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS];
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, String);
- if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
- }
- fclose(Arquivo);
- return strval(Value);
- }
- stock bool:F_ReadBool(file[], key[])
- {
- print("DEBUG / F_ReadBool");
- new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS], bool:Var;
- if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
- else
- {
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, String);
- if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
- }
- fclose(Arquivo);
- if(strval(Value) == 1) Var = true;
- else Var = false;
- }
- return Var;
- }
- stock F_FindKey(file[], key[], bool:sensitive)
- {
- print("DEBUG / F_FindKey");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
- new File:Arquivo, Lines[MAX_FILE_LINES], String[128], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Finds, CountFinds;
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, Lines);
- if(strfind(Lines, key, sensitive) == 0)
- {
- format(String, sizeof String, "Chave encontrada - Chave: %s | Linha: %i", key, i+1);
- strcat(Strcat, String);
- Finds = true;
- CountFinds ++;
- }
- }
- fclose(Arquivo);
- if(Finds == false) strcat(Strcat, "Sem resultados");
- return Strcat;
- }
- stock F_WriteStr(file[], key[], str[])
- {
- print("DEBUG / F_WriteStr");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser escrito!\nMotivo: Arquivo não existe.\n\n", file);
- new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, Lines);
- if(strfind(Lines, key, false) == 0 && Writed == false)
- {
- format(Lines, sizeof Lines, "%s%s%s\r\n", key, DIVISION, str);
- Writed = true;
- }
- strcat(Strcat, Lines);
- }
- if(Writed == false)
- {
- format(Lines, sizeof Lines, "%s%s%s\r\n", key, DIVISION, str);
- Arquivo = fopen(file, io_append);
- fwrite(Arquivo, Lines);
- }
- else
- {
- Arquivo = fopen(file, io_write);
- fwrite(Arquivo, Strcat);
- }
- return fclose(Arquivo);
- }
- stock F_WriteInt(file[], key[], int)
- {
- print("DEBUG / F_WriteStr");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser escrito!\nMotivo: Arquivo não existe.\n\n", file);
- new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, Lines);
- if(strfind(Lines, key, false) == 0)
- {
- format(Lines, sizeof Lines, "%s%s%i\r\n", key, DIVISION, int);
- Writed = true;
- }
- strcat(Strcat, Lines);
- }
- if(Writed == false)
- {
- format(Lines, sizeof Lines, "%s%s%i\r\n", key, DIVISION, int);
- Arquivo = fopen(file, io_append);
- fwrite(Arquivo, Lines);
- }
- else
- {
- Arquivo = fopen(file, io_write);
- fwrite(Arquivo, Strcat);
- }
- return fclose(Arquivo);
- }
- stock F_WriteFloat(file[], key[], Float:flt)
- {
- print("DEBUG / F_WriteFloat");
- if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser escrito!\nMotivo: Arquivo não existe.\n\n", file);
- new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, Lines);
- if(strfind(Lines, key, false) == 0)
- {
- format(Lines, sizeof Lines, "%s%s%f\r\n", key, DIVISION, flt);
- Writed = true;
- }
- strcat(Strcat, Lines);
- }
- if(Writed == false)
- {
- format(Lines, sizeof Lines, "%s%s%f\r\n", key, DIVISION, flt);
- Arquivo = fopen(file, io_append);
- fwrite(Arquivo, Lines);
- }
- else
- {
- Arquivo = fopen(file, io_write);
- fwrite(Arquivo, Strcat);
- }
- return fclose(Arquivo);
- }
- stock bool:F_WriteBool(file[], key[], bool:bl)
- {
- print("DEBUG / F_WriteBool");
- new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
- if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser escrito!\nMotivo: Arquivo não existe.\n\n", file);
- else
- {
- Arquivo = fopen(file, io_read);
- for(new i = 0; i < MAX_FILE_LINES; i ++)
- {
- fread(Arquivo, Lines);
- if(strfind(Lines, key, false) == 0)
- {
- if(bl == true) format(Lines, sizeof Lines, "%s%s1\r\n", key, DIVISION);
- else format(Lines, sizeof Lines, "%s%s0\r\n", key, DIVISION);
- Writed = true;
- }
- strcat(Strcat, Lines);
- }
- if(Writed == false)
- {
- if(bl == true) format(Lines, sizeof Lines, "%s%s1\r\n", key, DIVISION);
- else format(Lines, sizeof Lines, "%s%s0\r\n", key, DIVISION);
- Arquivo = fopen(file, io_append);
- fwrite(Arquivo, Lines);
- }
- else
- {
- Arquivo = fopen(file, io_write);
- fwrite(Arquivo, Strcat);
- }
- }
- return fclose(Arquivo);
- }
Advertisement
Add Comment
Please, Sign In to add comment