Advertisement
losnato

[Include] Losgs

Oct 29th, 2011
2,776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.89 KB | None | 0 0
  1. /*
  2. native CreateLog(const file[]);
  3. native WriteLog(const file[], string[]);
  4. native RemoveLog(const file[]);
  5. native LogExists(const file[]);
  6. */
  7.  
  8. #define LogExists fexist
  9.  
  10. stock CreateLog(const file[])
  11. {
  12.     if(LogExists(file ) )
  13.     {
  14.         print("--------------------------------------------------------------------");
  15.         printf("Losgs: Você está tentando criar um log já existente (%s)", file);
  16.         print("Losgs: Consulte o tópico oficial para mais informações.");
  17.         print("Losgs: http://forum.sa-mp.com/showthread.php?t=293534");
  18.         print("--------------------------------------------------------------------");
  19.         return 0;
  20.     }
  21.  
  22.     new
  23.         File: logFile = fopen(file, io_write);
  24.  
  25.     fclose(logFile);
  26.  
  27.     return 1;
  28. }
  29.  
  30. stock WriteLog(const file[], string[], maxlength = sizeof(string))
  31. {
  32.     if(!LogExists(file))
  33.         CreateLog(file);
  34.  
  35.     new
  36.         year,
  37.         month,
  38.         day,
  39.         hour,
  40.         minute,
  41.         second,
  42.         stringLog[600];
  43.  
  44.     getdate(year, month, day);
  45.     gettime(hour, minute, second);
  46.  
  47.     format(stringLog, maxlength + 27, "(%02d/%02d/%d)[%02d:%02d:%02d] %s\r\n", day, month, year, hour, minute, second, string);
  48.  
  49.     new
  50.         File: logFile = fopen(file, io_append);
  51.  
  52.     fwrite(logFile, stringLog);
  53.     fclose(logFile);
  54.  
  55.     return 1;
  56. }
  57.  
  58. stock RemoveLog(const file[])
  59. {
  60.     if(!LogExists(file))
  61.     {
  62.         print("--------------------------------------------------------------------");
  63.         printf("Losgs: Você está tentando deletar um log que não existe (%s)", file);
  64.         print("Losgs: Consulte o tópico oficial para mais informações.");
  65.         print("Losgs: http://forum.sa-mp.com/showthread.php?t=293534");
  66.         print("--------------------------------------------------------------------");
  67.         return 0;
  68.     }
  69.  
  70.     fremove(file);
  71.  
  72.     return 1;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement