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.

101 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A collection of utility classes to simplify file I/O, and
  4. // as much as possible contain portability problems. Here avoiding
  5. // including windows.h.
  6. //
  7. //=============================================================================
  8. #ifndef FILEIO_H
  9. #define FILEIO_H
  10. #if defined (_WIN32)
  11. #else
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #if !defined( _PS3 )
  15. #include <signal.h>
  16. #endif // _PS3
  17. #endif
  18. #include "tier0/platform.h"
  19. #include "tier1/utlstring.h"
  20. #include "tier1/utllinkedlist.h"
  21. const int64 k_nMillion = 1000000;
  22. const int64 k_nThousand = 1000;
  23. const int64 k_nKiloByte = 1024;
  24. const int64 k_nMegabyte = k_nKiloByte * k_nKiloByte;
  25. const int64 k_nGigabyte = k_nMegabyte * k_nKiloByte;
  26. class CPathString
  27. {
  28. public:
  29. // Constructors: Automatically fixes slashes and removes double slashes when the object is
  30. // constructed, and then knows how to append magic \\?\ on Windows for unicode paths
  31. CPathString( const char *pchUTF8Path );
  32. ~CPathString();
  33. // Gets the path in UTF8
  34. const char *GetUTF8Path();
  35. // Gets wchar_t based path, with \\?\ pre-pended (allowing long paths on Win32, should only be used with unicode aware filesystem calls)
  36. const wchar_t *GetWCharPathPrePended();
  37. private:
  38. void PopulateWCharPath();
  39. char *m_pchUTF8Path;
  40. wchar_t *m_pwchWideCharPathPrepended;
  41. };
  42. #if !defined(_PS3)
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Encapsulates watching a directory for file changes
  45. //-----------------------------------------------------------------------------
  46. class CDirWatcher
  47. {
  48. public:
  49. CDirWatcher();
  50. ~CDirWatcher();
  51. // only one directory can be watched at a time
  52. void SetDirToWatch( const char *pchDir );
  53. // retrieve any changes
  54. bool GetChangedFile( CUtlString *psFile );
  55. #ifdef DBGFLAG_VALIDATE
  56. void Validate( CValidator &validator, const char *pchName );
  57. #endif
  58. private:
  59. CUtlLinkedList<CUtlString> m_listChangedFiles;
  60. void *m_hFile;
  61. void *m_pOverlapped;
  62. void *m_pFileInfo;
  63. #ifdef OSX
  64. public:
  65. struct timespec m_modTime;
  66. void AddFileToChangeList( const char *pchFile );
  67. CUtlString m_BaseDir;
  68. private:
  69. void *m_WatcherStream;
  70. #endif
  71. friend class CDirWatcherFriend;
  72. #ifdef LINUX
  73. void AddFileToChangeList( const char *pchFile );
  74. #endif
  75. #ifdef WIN32
  76. // used by callback functions to push a file onto the list
  77. void AddFileToChangeList( const char *pchFile );
  78. void PostDirWatch();
  79. #endif
  80. };
  81. #endif // _PS3
  82. #endif // FILEIO_H