Advertisement
Guest User

Fini Cache File System

a guest
Jul 11th, 2011
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.21 KB | None | 0 0
  1. /*////////////////////////////////////////////////////////////////////////////////
  2.  
  3.                      _ ____        _____          __  __
  4.                     (_)  _ \ ___  |_   _|__  __ _|  \/  |
  5.                     | | |_) / __|   | |/ _ \/ _` | |\/| |
  6.                     | |  __/\__ \   | |  __/ (_| | |  | |
  7.                     |_|_|   |___/   |_|\___|\__,_|_|  |_|
  8.  
  9.                         Intelligent Programming Style ®
  10.  
  11.                          ____________________________
  12. [url]www.ips-team.blogspot.com[/url]
  13. [url]www.ips-team.forumeiros.com[/url]
  14. ____________________________
  15.  
  16. Created By DraKiNs & SlashPT
  17. Thanks to [iPs]TeaM and Jhony
  18.  
  19. */
  20. ////////////////////////////////////////////////////////////////////////////////
  21.  
  22. //========= [ Configs of Read/Write Files ] ====================================
  23.  
  24. #define MaxLines    (999)
  25. #define MaxKeys     (064)
  26.  
  27. #define Fini_GetBool(%0)    (bool:strval(Fini_GetStr(%0)))
  28. #define Fini_GetValue(%0)   (strval(Fini_GetStr(%0)))
  29. #define Fini_Exists(%0)     (fexist(%0))
  30. #define Fini_GetFloat(%0)   floatstr(Fini_GetStr(%0))
  31. #define Fini_Remove(%0)     (fremove(%0))
  32.  
  33. #define WINDOWS //delete if use linux
  34. //========= [ Variables of Set/Get Ini ] ========================================
  35.  
  36. new
  37. sCacheKeys[MaxLines][MaxKeys],
  38. sCacheValue[MaxLines][MaxKeys],
  39. iLoop           = 0x0,
  40. iFind           = 0x0,
  41. iKeySet         = 0x0,
  42. File:iFile      = File:0,
  43. sTemp[MaxKeys]  = " ";
  44.  
  45. //============ [ Functions ] ================================================
  46.  
  47. //Get ~ Read Functions
  48. stock Fini_GetStr(sKey[])
  49. {
  50.     iLoop = 0x0;
  51.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  52.         if(!strcmp(sCacheKeys[iLoop],sKey,false))
  53.             return sCacheValue[iLoop];
  54.         ++iLoop;
  55.     }
  56.     return sCacheKeys[0];
  57. }
  58.  
  59.  
  60. //Others Funcions
  61. stock   Fini_Create(sFile[])
  62. {
  63.     if(Fini_Exists(sFile)) return false;
  64.     iFile = fopen(sFile,io_write);
  65.     return fclose(iFile);
  66. }
  67.  
  68.  
  69. stock Fini_OpenFile(sFile[])
  70. {
  71.     iFile = fopen(sFile,io_read),
  72.         iFind   = 0x0;
  73.     iLoop = 0x0;
  74.  
  75.     while(fread(iFile,sTemp)) {
  76.         sTemp[strlen(sTemp) - 2] = EOS;
  77.         iFind   = strfind(sTemp,"=");
  78.         format(sCacheValue[iLoop],MaxKeys,sTemp[iFind + 1]);
  79.         sTemp[iFind] = EOS;
  80.         format(sCacheKeys[iLoop],MaxKeys,sTemp);
  81.         ++iLoop;
  82.     }
  83.     return fclose(iFile);
  84. }
  85.  
  86.  
  87. stock Fini_SaveFile(sFile[])
  88. {
  89.     iFile = fopen(sFile,io_write),
  90.         sTemp[0] = EOS;
  91.  
  92.     iLoop = 0x0;
  93.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  94.  
  95.         #if defined WINDOWS
  96.         format(sTemp,MaxKeys,"%s=%s\r\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
  97.         #else
  98.         format(sTemp,MaxKeys,"%s=%s\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
  99.         #endif
  100.         fwrite(iFile,sTemp);
  101.         ++iLoop;
  102.     }
  103.     return fclose(iFile);
  104. }
  105.  
  106. stock Fini_CloseFile()
  107. {
  108.     sCacheKeys[0][0]    =   EOS;
  109.     sCacheValue[0][0]   =   EOS;
  110.     iLoop               =   0x0;
  111.     iFind               =   0x0;
  112.     iKeySet             =   0x0;
  113.     sTemp[0]            =   EOS;
  114.     return true;
  115. }
  116.  
  117.  
  118. stock Fini_IsSet(sTag[])
  119. {
  120.     iLoop = 0x0;
  121.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  122.         if(!strcmp(sCacheKeys[iLoop],sTag,false)) {
  123.             return true;
  124.         }
  125.         iLoop++;
  126.     }
  127.     return false;
  128. }
  129.  
  130.  
  131. //Set ~ Write Functions
  132.  
  133. stock Fini_SetStr(sKey[],sValue[])
  134. {
  135.     iLoop = 0x0;
  136.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  137.         if(!strcmp(sCacheKeys[iLoop],sKey,false)) {
  138.             sCacheValue[iLoop][0] = EOS;
  139.             strcat(sCacheValue[iLoop],sValue);
  140.             iKeySet = 1;
  141.         }
  142.         ++iLoop;
  143.     }
  144.     if(!iKeySet) {
  145.         while(sCacheKeys[iLoop][0]) iLoop++;
  146.         strcat(sCacheValue[iLoop],sValue);
  147.         strcat(sCacheKeys[iLoop],sKey);
  148.     }
  149.     return EOS;
  150. }
  151.  
  152.  
  153. stock Fini_SetFloat(sTag[],Float:iVal)
  154. {
  155.     format(sTemp,MaxKeys,"%f",iVal);
  156.     return Fini_SetStr(sTag,sTemp);
  157. }
  158.  
  159.  
  160. stock Fini_SetVal(sTag[],iVal)
  161. {
  162.     format(sTemp,MaxKeys,"%d",iVal);
  163.     return Fini_SetStr(sTag,sTemp);
  164. }
  165.  
  166.  
  167. stock Fini_SetBool(sTag[],bool:iVal)
  168. {
  169.     format(sTemp,MaxKeys,"%d",iVal);
  170.     return Fini_SetStr(sTag,sTemp);
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement