F1N4L_

F_INI By F1N4L 1.5

May 5th, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.43 KB | None | 0 0
  1. /*
  2. [|||||||] [|||||||] [||||||] [||] [||||||] [||||||] [|||] [||||||]
  3. [||] [||] [||] [||] [||] [||] [||][||] [||]
  4. [|||||] [|||||] [||] [||] [|||||] [||||||] [||] [||] [||] [||||||]
  5. [||] [||] [||] [||] [||] [||] [||][||] [||] |||]
  6. [||] [||] [||] [||||||] [||||||] [||||||] [||||||] [||] [||] [||] [||||||]
  7.  
  8. Escreve somente inteiros em uma determinada palavra-chave.
  9. Macro: F_WIn
  10. F_WriteInt(file[], key[], value);
  11.  
  12. Escreve somente textos em uma determinada palavra-chave.
  13. Macro: F_WSt
  14. F_WriteStr(file[], key[], value[]);
  15.  
  16. Escreve somente float em uma determinada palavra-chave.
  17. Macro: F_WFl
  18. F_WriteFloat(file[], key[], Float:value);
  19.  
  20. Escreve somente valores booleanos em uma determinada palavra-chave.
  21. Macro: F_WBo
  22. F_WriteBool(file[], key[], bool:value);
  23.  
  24. Faz a leitura de inteiros em uma determinada palavra-chave.
  25. Macro: F_RIn
  26. F_ReadInt(file[], key[]);
  27.  
  28. Faz a leitura de textos em uma determinada palavra-chave.
  29. Macro: F_RSt
  30. F_ReadStr(file[], key[]);
  31.  
  32. Faz a leitura de float em uma determinada palavra-chave.
  33. Macro: F_RFl
  34. F_ReadFloat(file[], key[]);
  35.  
  36. Faz a leitura de valores booleanos em uma determinada palavra-chave.
  37. Macro: F_RBo
  38. F_ReadBool(file[], key[]);
  39.  
  40. Verifica se o arquivo existe.
  41. Macro: F_Ex
  42. F_Exists(file[])
  43.  
  44. Cria determinado arquivo.
  45. Macro: F_Cr
  46. F_Create(file[]);
  47.  
  48. Salva todos os dados de determinado arquivo.
  49. Macro: F_Sa
  50. F_Save(file[]);
  51.  
  52. Faz um backup de determinado arquivo, renomeando-o para 'FileName_RandomNumber.fback'.
  53. Macro: F_Ba
  54. F_Backup(file[]);
  55.  
  56. Faz uma busca para verificar se existe determinada palavra-chave com/sem case sensitive.
  57. Macro: F_FKe
  58. F_FindKey(file[], key[], true/false);
  59.  
  60. Adiciona uma linha de texto em determinado arquivo. Pode ser utilizado como salvamento de logs.
  61. Macro: F_ASt
  62. F_AddStr(file[], str[]);
  63. */
  64.  
  65. //________________________Configuration:________________________
  66. #define MAX_FILE_LINES 25
  67. #define MAX_LINE_CHARS 128
  68. #define DIVISION "="
  69.  
  70. //________________________Shorter:________________________
  71. #define F_Exists F_Ex
  72. #define F_WriteInt F_WIn
  73. #define F_WriteStr F_WSt
  74. #define F_WriteFloat F_WFl
  75. #define F_WriteBool F_WBo
  76. #define F_ReadInt F_RIn
  77. #define F_ReadStr F_RSt
  78. #define F_ReadFloat F_RFl
  79. #define F_ReadBool F_RBo
  80. #define F_Create F_Cr
  81. #define F_Backup F_Ba
  82. #define F_FindKey F_FKe
  83. #define F_AddStr F_ASt
  84.  
  85. //________________________Defines:________________________
  86. #define F_RFl(%0,%1) floatstr(F_ReadStr(%0,%1))
  87.  
  88. //________________________Stocks:________________________
  89. stock F_Exists(file[])
  90. {
  91. print("DEBUG / F_Exists");
  92.  
  93. return fexist(file);
  94. }
  95.  
  96. stock F_Backup(file[])
  97. {
  98. print("DEBUG / F_Backup");
  99.  
  100. if(!fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser salvo!\nMotivo: Arquivo não existe.\n\n");
  101.  
  102. new File:Arquivo, String[MAX_FILE_LINES], Strcat[MAX_LINE_CHARS * MAX_FILE_LINES];
  103.  
  104. Arquivo = fopen(file, io_read);
  105.  
  106. for(new i = 0; i < MAX_FILE_LINES; i ++)
  107. {
  108. fread(Arquivo, String);
  109.  
  110. strcat(Strcat, String);
  111. }
  112. fclose(Arquivo);
  113.  
  114. format(String, sizeof String, "%s_%i.fback", file, random(99999));
  115.  
  116. Arquivo = fopen(String, io_write);
  117.  
  118. fwrite(Arquivo, Strcat);
  119.  
  120. return fclose(Arquivo);
  121. }
  122.  
  123. stock F_Create(file[])
  124. {
  125. print("DEBUG / F_Create");
  126.  
  127. new File:Arquivo;
  128.  
  129. if(fexist(file)) return printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser criado!\nMotivo: Arquivo já existe.\n\n", file);
  130.  
  131. Arquivo = fopen(file, io_write);
  132.  
  133. return fclose(Arquivo);
  134. }
  135.  
  136. stock F_AddStr(file[], str[])
  137. {
  138. print("DEBUG / F_AddStr");
  139.  
  140. 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);
  141. else
  142. {
  143. new File:Arquivo, String[MAX_LINE_CHARS];
  144.  
  145. Arquivo = fopen(file, io_append);
  146.  
  147. format(String, sizeof String, "%s\r\n", str);
  148. fwrite(Arquivo, String);
  149. }
  150. return fclose(Arquivo);
  151. }
  152.  
  153. stock F_ReadStr(file[], key[])
  154. {
  155. print("DEBUG / F_ReadStr");
  156.  
  157. new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS];
  158.  
  159. if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
  160. else
  161. {
  162. Arquivo = fopen(file, io_read);
  163.  
  164. for(new i = 0; i < MAX_FILE_LINES; i ++)
  165. {
  166. fread(Arquivo, String);
  167.  
  168. if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
  169. }
  170. fclose(Arquivo);
  171. }
  172.  
  173. return Value;
  174. }
  175.  
  176. stock F_ReadInt(file[], key[])
  177. {
  178. print("DEBUG / F_ReadInt");
  179.  
  180. 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);
  181.  
  182. new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS];
  183.  
  184. Arquivo = fopen(file, io_read);
  185.  
  186. for(new i = 0; i < MAX_FILE_LINES; i ++)
  187. {
  188. fread(Arquivo, String);
  189.  
  190. if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
  191. }
  192. fclose(Arquivo);
  193.  
  194. return strval(Value);
  195. }
  196.  
  197. stock bool:F_ReadBool(file[], key[])
  198. {
  199. print("DEBUG / F_ReadBool");
  200.  
  201. new File:Arquivo, String[MAX_FILE_LINES], Value[MAX_LINE_CHARS], bool:Var;
  202.  
  203. if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser lido!\nMotivo: Arquivo não existe.\n\n", file);
  204. else
  205. {
  206. Arquivo = fopen(file, io_read);
  207.  
  208. for(new i = 0; i < MAX_FILE_LINES; i ++)
  209. {
  210. fread(Arquivo, String);
  211.  
  212. if(strfind(String, key, false) == 0) strmid(Value, String, strlen(key) + strlen(DIVISION), strlen(String));
  213. }
  214. fclose(Arquivo);
  215.  
  216. if(strval(Value) == 1) Var = true;
  217. else Var = false;
  218. }
  219. return Var;
  220. }
  221.  
  222. stock F_FindKey(file[], key[], bool:sensitive)
  223. {
  224. print("DEBUG / F_FindKey");
  225.  
  226. 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);
  227.  
  228. new File:Arquivo, Lines[MAX_FILE_LINES], String[128], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Finds, CountFinds;
  229.  
  230. Arquivo = fopen(file, io_read);
  231.  
  232. for(new i = 0; i < MAX_FILE_LINES; i ++)
  233. {
  234. fread(Arquivo, Lines);
  235.  
  236. if(strfind(Lines, key, sensitive) == 0)
  237. {
  238. format(String, sizeof String, "Chave encontrada - Chave: %s | Linha: %i", key, i+1);
  239. strcat(Strcat, String);
  240. Finds = true;
  241. CountFinds ++;
  242. }
  243. }
  244. fclose(Arquivo);
  245.  
  246. if(Finds == false) strcat(Strcat, "Sem resultados");
  247.  
  248. return Strcat;
  249. }
  250.  
  251. stock F_WriteStr(file[], key[], str[])
  252. {
  253. print("DEBUG / F_WriteStr");
  254.  
  255. 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);
  256.  
  257. new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
  258.  
  259. Arquivo = fopen(file, io_read);
  260.  
  261. for(new i = 0; i < MAX_FILE_LINES; i ++)
  262. {
  263. fread(Arquivo, Lines);
  264.  
  265. if(strfind(Lines, key, false) == 0 && Writed == false)
  266. {
  267. format(Lines, sizeof Lines, "%s%s%s\r\n", key, DIVISION, str);
  268. Writed = true;
  269. }
  270.  
  271. strcat(Strcat, Lines);
  272. }
  273.  
  274. if(Writed == false)
  275. {
  276. format(Lines, sizeof Lines, "%s%s%s\r\n", key, DIVISION, str);
  277.  
  278. Arquivo = fopen(file, io_append);
  279. fwrite(Arquivo, Lines);
  280. }
  281. else
  282. {
  283. Arquivo = fopen(file, io_write);
  284. fwrite(Arquivo, Strcat);
  285. }
  286.  
  287. return fclose(Arquivo);
  288. }
  289.  
  290. stock F_WriteInt(file[], key[], int)
  291. {
  292. print("DEBUG / F_WriteStr");
  293.  
  294. 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);
  295.  
  296. new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
  297.  
  298. Arquivo = fopen(file, io_read);
  299.  
  300. for(new i = 0; i < MAX_FILE_LINES; i ++)
  301. {
  302. fread(Arquivo, Lines);
  303.  
  304. if(strfind(Lines, key, false) == 0)
  305. {
  306. format(Lines, sizeof Lines, "%s%s%i\r\n", key, DIVISION, int);
  307. Writed = true;
  308. }
  309.  
  310. strcat(Strcat, Lines);
  311. }
  312.  
  313. if(Writed == false)
  314. {
  315. format(Lines, sizeof Lines, "%s%s%i\r\n", key, DIVISION, int);
  316.  
  317. Arquivo = fopen(file, io_append);
  318. fwrite(Arquivo, Lines);
  319. }
  320. else
  321. {
  322. Arquivo = fopen(file, io_write);
  323. fwrite(Arquivo, Strcat);
  324. }
  325.  
  326. return fclose(Arquivo);
  327. }
  328.  
  329. stock F_WriteFloat(file[], key[], Float:flt)
  330. {
  331. print("DEBUG / F_WriteFloat");
  332.  
  333. 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);
  334.  
  335. new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
  336.  
  337. Arquivo = fopen(file, io_read);
  338.  
  339. for(new i = 0; i < MAX_FILE_LINES; i ++)
  340. {
  341. fread(Arquivo, Lines);
  342.  
  343. if(strfind(Lines, key, false) == 0)
  344. {
  345. format(Lines, sizeof Lines, "%s%s%f\r\n", key, DIVISION, flt);
  346. Writed = true;
  347. }
  348.  
  349. strcat(Strcat, Lines);
  350. }
  351.  
  352. if(Writed == false)
  353. {
  354. format(Lines, sizeof Lines, "%s%s%f\r\n", key, DIVISION, flt);
  355.  
  356. Arquivo = fopen(file, io_append);
  357. fwrite(Arquivo, Lines);
  358. }
  359. else
  360. {
  361. Arquivo = fopen(file, io_write);
  362. fwrite(Arquivo, Strcat);
  363. }
  364.  
  365. return fclose(Arquivo);
  366. }
  367.  
  368. stock bool:F_WriteBool(file[], key[], bool:bl)
  369. {
  370. print("DEBUG / F_WriteBool");
  371.  
  372. new File:Arquivo, Lines[MAX_FILE_LINES], Strcat[MAX_FILE_LINES * MAX_LINE_CHARS], bool:Writed;
  373.  
  374. if(!fexist(file)) printf("\n\n________F_Files_Warning:________\nArquivo '%s' não pode ser escrito!\nMotivo: Arquivo não existe.\n\n", file);
  375. else
  376. {
  377. Arquivo = fopen(file, io_read);
  378.  
  379. for(new i = 0; i < MAX_FILE_LINES; i ++)
  380. {
  381. fread(Arquivo, Lines);
  382.  
  383. if(strfind(Lines, key, false) == 0)
  384. {
  385. if(bl == true) format(Lines, sizeof Lines, "%s%s1\r\n", key, DIVISION);
  386. else format(Lines, sizeof Lines, "%s%s0\r\n", key, DIVISION);
  387. Writed = true;
  388. }
  389.  
  390. strcat(Strcat, Lines);
  391. }
  392.  
  393. if(Writed == false)
  394. {
  395. if(bl == true) format(Lines, sizeof Lines, "%s%s1\r\n", key, DIVISION);
  396. else format(Lines, sizeof Lines, "%s%s0\r\n", key, DIVISION);
  397.  
  398. Arquivo = fopen(file, io_append);
  399. fwrite(Arquivo, Lines);
  400. }
  401. else
  402. {
  403. Arquivo = fopen(file, io_write);
  404. fwrite(Arquivo, Strcat);
  405. }
  406. }
  407.  
  408. return fclose(Arquivo);
  409. }
Advertisement
Add Comment
Please, Sign In to add comment