Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Interfaces to the OS Interface classes.
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef TFSTATSOSINTERFACE_H
  14. #define TFSTATSOSINTERFACE_H
  15. #ifdef WIN32
  16. #pragma warning (disable:4786)
  17. #pragma once
  18. #endif
  19. #include "util.h"
  20. #include <string>
  21. using std::string;
  22. //----------------------------------------------------------------------------------------------------
  23. // Purpose: The OS Interface classes contain OS / Compiler specific code in
  24. // them, so that it is abstracted away from TFStats. This removes compatibility
  25. //issues from TFStats and isolates them to this class.
  26. // Subclasses of this abstract class implement each platform.
  27. //------------------------------------------------------------------------------------------------------
  28. class CTFStatsOSInterface
  29. {
  30. public:
  31. virtual char pathSeperator()=0;
  32. virtual int mkdir(const char* ccs)=0;
  33. virtual int chdir(const char* ccs)=0;
  34. virtual char* getcwd(char* buf,int maxlen)=0;
  35. virtual int chdrive(int drive)=0;
  36. virtual int getdrive()=0;
  37. virtual char** gettzname()=0;
  38. virtual bool makeHier(string dir);
  39. virtual char*getNextDirectory(char* path);//helper for above function
  40. virtual string& addDirSlash(string& s);
  41. virtual string& removeDirSlash(string& s);
  42. //change the normal _find function interface somewhat to make it simpler
  43. //and to make it a little more compatible with the linux interface (scandir())
  44. virtual bool findfirstfile(char* filemask,string& filename)=0;
  45. virtual bool findnextfile(string& filename)=0;
  46. virtual bool findfileclose()=0;
  47. virtual char* ultoa(unsigned long theNum, char* buf,int radix)=0;
  48. };
  49. #ifdef WIN32
  50. class CTFStatsWin32Interface : public CTFStatsOSInterface
  51. {
  52. public:
  53. char pathSeperator(){return '\\';}
  54. int mkdir(const char* ccs){return ::_mkdir(ccs);}
  55. int chdir(const char* ccs){return ::_chdir(ccs);}
  56. char* getcwd(char* buf,int maxlen){return ::_getcwd(buf,maxlen);}
  57. int chdrive(int drive){return ::_chdrive(drive);}
  58. int getdrive(){return ::_getdrive();}
  59. char** gettzname(){return _tzname;}
  60. long hFindFile;
  61. bool findfirstfile(char* filemask,string& filename);
  62. bool findnextfile(string& filename);
  63. bool findfileclose();
  64. CTFStatsWin32Interface():hFindFile(-1){}
  65. char* ultoa(unsigned long theNum, char* buf,int radix){return _ultoa(theNum,buf,radix);}
  66. };
  67. #else
  68. #include <dirent.h>
  69. #include <errno.h>
  70. class CTFStatsLinuxInterface : public CTFStatsOSInterface
  71. {
  72. public:
  73. char pathSeperator(){return '/';}
  74. int mkdir(const char* ccs)
  75. {
  76. int result=::mkdir(ccs,PERMIT);
  77. chmod(ccs,PERMIT);
  78. return result;
  79. }
  80. int chdir(const char* ccs){return ::chdir(ccs);}
  81. char* getcwd(char* buf,int maxlen){return ::getcwd(buf,maxlen);}
  82. int chdrive(int drive){return -1;}
  83. int getdrive(){return -1;}
  84. char** gettzname(){return tzname;}
  85. int foundFileIterator;
  86. int numFiles;
  87. dirent** foundFiles;
  88. static string filemask;
  89. static void filemask2RegExp(char* buf);
  90. static int filenameCompare(dirent* file);
  91. bool findfirstfile(char* filemask,string& filename);
  92. bool findnextfile(string& filename);
  93. bool findfileclose();
  94. CTFStatsLinuxInterface():foundFileIterator(-1),numFiles(0),foundFiles(0){}
  95. char* ultoa(unsigned long theNum, char* buf,int radix);
  96. };
  97. #endif
  98. #endif // TFSTATSOSINTERFACE_H