Advertisement
Guest User

Por DraKiNs FINI V4.1

a guest
Apr 16th, 2011
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.03 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. //========= [ Variables of Set/Get Ini ] ========================================
  34.  
  35. new
  36. sCacheKeys[MaxLines][MaxKeys],
  37. sCacheValue[MaxLines][MaxKeys],
  38. iLoop           = 0x0,
  39. iFind           = 0x0,
  40. iKeySet         = 0x0,
  41. File:iFile      = File:0,
  42. sTemp[MaxKeys]  = " ";
  43.  
  44. //============ [ Functions ] ================================================
  45.  
  46. //Get ~ Read Functions
  47. stock Fini_GetStr(sKey[])
  48. {
  49.     iLoop = 0x0;
  50.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  51.         if(!strcmp(sCacheKeys[iLoop],sKey,false))
  52.             return sCacheValue[iLoop];
  53.         ++iLoop;
  54.     }
  55.     return sCacheKeys[0];
  56. }
  57.  
  58.  
  59. //Others Funcions
  60. stock   Fini_Create(sFile[])
  61. {
  62.     if(Fini_Exists(sFile)) return false;
  63.     iFile = fopen(sFile,io_write);
  64.     return fclose(iFile);
  65. }
  66.  
  67.  
  68. stock Fini_OpenFile(sFile[])
  69. {
  70.     iFile = fopen(sFile,io_read),
  71.         iFind   = 0x0;
  72.     iLoop = 0x0;
  73.  
  74.     while(fread(iFile,sTemp)) {
  75.         sTemp[strlen(sTemp) - 2] = EOS;
  76.         iFind   = strfind(sTemp,"=");
  77.         format(sCacheValue[iLoop],MaxKeys,sTemp[iFind + 1]);
  78.         sTemp[iFind] = EOS;
  79.         format(sCacheKeys[iLoop],MaxKeys,sTemp);
  80.         ++iLoop;
  81.     }
  82.     return fclose(iFile);
  83. }
  84.  
  85.  
  86. stock Fini_SaveFile(sFile[])
  87. {
  88.     iFile = fopen(sFile,io_write),
  89.         sTemp[0] = EOS;
  90.  
  91.     iLoop = 0x0;
  92.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  93.         format(sTemp,MaxKeys,"%s=%s\r\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
  94.         fwrite(iFile,sTemp);
  95.         ++iLoop;
  96.     }
  97.     return fclose(iFile);
  98. }
  99.  
  100.  
  101. stock Fini_CloseFile()
  102. {
  103.     sCacheKeys[0][0]    =   EOS;
  104.     sCacheValue[0][0]   =   EOS;
  105.     iLoop               =   0x0;
  106.     iFind               =   0x0;
  107.     iKeySet             =   0x0;
  108.     sTemp[0]            =   EOS;
  109.     return true;
  110. }
  111.  
  112.  
  113. stock Fini_IsSet(sTag[])
  114. {
  115.     iLoop = 0x0;
  116.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  117.         if(!strcmp(sCacheKeys[iLoop],sTag,false)) {
  118.             return true;
  119.         }
  120.         iLoop++;
  121.     }
  122.     return false;
  123. }
  124.  
  125.  
  126. //Set ~ Write Functions
  127.  
  128. stock Fini_SetStr(sKey[],sValue[])
  129. {
  130.     iLoop = 0x0;
  131.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
  132.         if(!strcmp(sCacheKeys[iLoop],sKey,false)) {
  133.             sCacheValue[iLoop][0] = EOS;
  134.             strcat(sCacheValue[iLoop],sValue);
  135.             iKeySet = 1;
  136.         }
  137.         ++iLoop;
  138.     }
  139.     if(!iKeySet) {
  140.         while(sCacheKeys[iLoop][0]) iLoop++;
  141.         strcat(sCacheValue[iLoop],sValue);
  142.         strcat(sCacheKeys[iLoop],sKey);
  143.     }
  144.     return EOS;
  145. }
  146.  
  147.  
  148. stock Fini_SetFloat(sTag[],Float:iVal)
  149. {
  150.     format(sTemp,MaxKeys,"%f",iVal);
  151.     return Fini_SetStr(sTag,sTemp);
  152. }
  153.  
  154.  
  155. stock Fini_SetVal(sTag[],iVal)
  156. {
  157.     format(sTemp,MaxKeys,"%d",iVal);
  158.     return Fini_SetStr(sTag,sTemp);
  159. }
  160.  
  161.  
  162. stock Fini_SetBool(sTag[],bool:iVal)
  163. {
  164.     format(sTemp,MaxKeys,"%d",iVal);
  165.     return Fini_SetStr(sTag,sTemp);
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement