1
0

a_files.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Cali-Files: Simple file system.
  3. Create, delete, write and read.
  4. Steal this and I'll kill you. =D
  5. */
  6. #if defined _a_files_included
  7. #endinput
  8. #endif
  9. #define _a_files_included
  10. #pragma library a_files
  11. #include <file>
  12. #include <string>
  13. stock CreateFile(filename[])
  14. {
  15. if (!fexist(filename)) {
  16. new File: file = fopen(filename, io_write);
  17. if (file) {
  18. fclose(file);
  19. return 1;
  20. }
  21. }
  22. return 1;
  23. }
  24. stock DeleteFile(filename[])
  25. {
  26. if (fexist(filename)) {
  27. fremove(filename);
  28. return 1;
  29. }
  30. return 1;
  31. }
  32. stock Write(filename[], key[])
  33. {
  34. new File: file = fopen(filename, io_append);
  35. if (file) {
  36. fwrite(file, key);
  37. fclose(file);
  38. return 1;
  39. }
  40. return 1;
  41. }
  42. stock NewLine(filename[])
  43. {
  44. new File: file = fopen(filename, io_append);
  45. if (file) {
  46. fwrite(file, "\r\n");
  47. fclose(file);
  48. return 1;
  49. }
  50. return 1;
  51. }
  52. stock Read(filename[], key[])
  53. {
  54. new tmp[255], key_length = strlen(key);
  55. new File: file = fopen(filename, io_read);
  56. if (file) {
  57. while (fread(file, key, sizeof(key))) {
  58. if (tmp[key_length] == '=' && !strcmp(tmp, key, true, key_length)) {
  59. strmid(tmp, tmp, key_length+1, strlen(tmp), 255);
  60. fclose(file);
  61. }
  62. }
  63. }
  64. return tmp;
  65. }