WWFILE.H 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/wwfile.h $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 10/31/01 2:00p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef WWFILE_Hx
  39. #define WWFILE_Hx
  40. #ifdef _UNIX
  41. #include "osdep.h"
  42. #endif
  43. #define YEAR(dt) (((dt & 0xFE000000) >> (9 + 16)) + 1980)
  44. #define MONTH(dt) ((dt & 0x01E00000) >> (5 + 16))
  45. #define DAY(dt) ((dt & 0x001F0000) >> (0 + 16))
  46. #define HOUR(dt) ((dt & 0x0000F800) >> 11)
  47. #define MINUTE(dt) ((dt & 0x000007E0) >> 5)
  48. #define SECOND(dt) ((dt & 0x0000001F) << 1)
  49. #ifndef SEEK_SET
  50. #define SEEK_SET 0 // Seek from start of file.
  51. #define SEEK_CUR 1 // Seek relative from current location.
  52. #define SEEK_END 2 // Seek from end of file.
  53. #endif
  54. #ifndef NULL
  55. #define NULL 0
  56. #endif
  57. class FileClass
  58. {
  59. public:
  60. enum
  61. {
  62. READ = 1,
  63. WRITE = 2,
  64. PRINTF_BUFFER_SIZE = 1024
  65. };
  66. virtual ~FileClass(void) {};
  67. virtual char const * File_Name(void) const = 0;
  68. virtual char const * Set_Name(char const *filename) = 0;
  69. virtual int Create(void) = 0;
  70. virtual int Delete(void) = 0;
  71. virtual bool Is_Available(int forced=false) = 0;
  72. virtual bool Is_Open(void) const = 0;
  73. virtual int Open(char const *filename, int rights=READ) = 0;
  74. virtual int Open(int rights=READ) = 0;
  75. virtual int Read(void *buffer, int size) = 0;
  76. virtual int Seek(int pos, int dir=SEEK_CUR) = 0;
  77. virtual int Tell(void) { return Seek(0); }
  78. virtual int Size(void) = 0;
  79. virtual int Write(void const *buffer, int size) = 0;
  80. virtual void Close(void) = 0;
  81. virtual unsigned long Get_Date_Time(void) {return(0);}
  82. virtual bool Set_Date_Time(unsigned long ) {return(false);}
  83. // virtual void Error(int error, int canretry = false, char const * filename=NULL) = 0;
  84. virtual void * Get_File_Handle(void) { return reinterpret_cast<void *>(-1); }
  85. // virtual void Bias(int start, int length=-1) = 0;
  86. operator char const * ()
  87. {
  88. return File_Name();
  89. }
  90. // this form uses a stack buffer of PRINTF_BUFFER_SIZE
  91. int Printf(char *str, ...);
  92. // this form uses the supplied buffer if PRINTF_BUFFER_SIZE is expected to be too small.
  93. int Printf(char *buffer, int bufferSize, char *str, ...);
  94. // this form uses the stack buffer but will prepend any output with the indicated number of tab characters '\t'
  95. int Printf_Indented(unsigned depth, char *str, ...);
  96. };
  97. #endif