Wnd_File.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ** Command & Conquer Generals(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: Blade Runner CD-ROM Windows 95
  23. //
  24. // File name: WND_FILE.H
  25. //
  26. // Source code: WND_FILE.CPP
  27. //
  28. // Compatibility: Microsoft Visual C++ 4.0
  29. // Borland C++ 5.0
  30. // Watcom C++ 10.6
  31. //
  32. // Start Date: See comments in version control log
  33. // Last Update: See comments in version control log
  34. //
  35. // Programmer(s): Michael Legg
  36. // Mike Grayford
  37. // James McNeill
  38. //
  39. //****************************************************************************
  40. #pragma once
  41. #ifndef WND_FILE_H
  42. #define WND_FILE_H
  43. //------------------------------------------------------------------------------
  44. // include files...
  45. //------------------------------------------------------------------------------
  46. #include <stdio.h>
  47. #include <sys/stat.h>
  48. #include <sys/types.h>
  49. #include <ctype.h>
  50. #include <stdlib.h>
  51. #include <assert.h>
  52. #define BOOL int
  53. #define ASSERT(x) assert(x)
  54. #define VERIFY(X) assert(X)
  55. //------------------------------------------------------------------------------
  56. // defines...
  57. //------------------------------------------------------------------------------
  58. //
  59. // it's one or the other!
  60. //
  61. #define SUPPORT_STREAMS TRUE // Normally this!
  62. #define SUPPORT_HANDLES FALSE // This is a test!
  63. #define MODE_READ_ONLY 0
  64. #define MODE_WRITE_ONLY 1
  65. #define MODE_READ_AND_WRITE 2
  66. #define MODE_WRITE_TRUNCATE MODE_WRITE_ONLY
  67. #define MODE_WRITE_APPEND 3
  68. #define MODE_WRITE_UPDATE 4
  69. #define SEEK_SET 0
  70. #define SEEK_CUR 1
  71. #define SEEK_END 2
  72. // #define INVALID_FILE_HANDLE -1
  73. #define INVALID_FILE_HANDLE INVALID_HANDLE_VALUE
  74. #define MAX_PATH_SIZE _MAX_PATH
  75. #define STRING_IT(a) #a
  76. #define TOKEN_IT(a) STRING_IT(,##a)
  77. #define MESSAGE(a) message (__FILE__ "(" TOKEN_IT(__LINE__) ") : " a)
  78. //#pragma MESSAGE("What does it do?")
  79. #ifdef _DEBUG
  80. void __cdecl Msg( int line, char *file, char *fmt, ... );
  81. void __cdecl Msg( int line, char *filename, wchar_t *fmt, unsigned int codepage=1252, ... );
  82. void Delete_Msg_File( void );
  83. #else
  84. #define Msg
  85. #define Delete_Msg_File()
  86. #endif
  87. //------------------------------------------------------------------------------
  88. // file class definition
  89. //------------------------------------------------------------------------------
  90. class StandardFileClass
  91. {
  92. public:
  93. //
  94. // public class functions...
  95. //
  96. StandardFileClass();
  97. ~StandardFileClass();
  98. bool Open ( const char *file_name, int open_mode );
  99. bool Close ( void );
  100. int Read ( void *buffer, unsigned long int bytes_to_read );
  101. int Write ( void *buffer, unsigned long int bytes_to_write );
  102. bool Seek ( int distance, int seek_file_position );
  103. int Tell ( void );
  104. int Query_Size ( void );
  105. bool Query_Open ( void );
  106. char * Query_Name_String ( void );
  107. int End_Of_File ( void );
  108. int Flush ( void );
  109. #if( SUPPORT_STREAMS )
  110. FILE *Query_File_Stream_Pointer( void );
  111. #endif
  112. private:
  113. //
  114. // private class functions...
  115. //
  116. void Reset( void );
  117. //
  118. // private class data...
  119. //
  120. #if( SUPPORT_HANDLES )
  121. HANDLE File_Handle;
  122. #endif
  123. #if( SUPPORT_STREAMS )
  124. //--------------------------------------------------------------------
  125. // The _stat structure, defined in SYS\STAT.H, includes these fields.
  126. // st_atime Time of last access of file ( time_t ).
  127. // st_ctime Time of creation of file ( time_t ).
  128. // st_dev Drive number of the disk containing the file (same as st_rdev).
  129. // st_rdev Drive number of the disk containing the file (same as st_dev).
  130. // st_mode Bit mask for file-mode information.
  131. // _S_IFDIR bit is set if path specifies a directory;
  132. // _S_IFREG bit is set if path specifies an ordinary file or a device.
  133. // User read/write bits are set according to the file's permission
  134. // mode; user execute bits are set according to the filename extension.
  135. // st_mtime Time of last modification of file.
  136. // st_nlink Always 1 on non-NTFS file systems.
  137. // st_size Size of the file in bytes; a 64-bit integer for _stati64 and _wstati64
  138. //--------------------------------------------------------------------
  139. FILE *File_Stream_Ptr;
  140. struct stat File_Statistics;
  141. #endif
  142. char File_Name[ MAX_PATH_SIZE ];
  143. bool Currently_Open;
  144. };
  145. //------------------------------------------------------------------------------
  146. // non-class public functions...
  147. //------------------------------------------------------------------------------
  148. #if( SUPPORT_HANDLES )
  149. HANDLE Open_File( char const *file_name, int mode );
  150. bool Close_File( HANDLE handle );
  151. int Read_File( HANDLE handle,
  152. void *buffer,
  153. unsigned long int bytes_to_read );
  154. int Write_File( HANDLE handle,
  155. void const *buffer,
  156. unsigned long int bytes_to_write );
  157. bool Seek_File( HANDLE handle,
  158. int distance,
  159. int seek_file_location );
  160. int Tell_File( HANDLE handle );
  161. int File_Size( HANDLE handle );
  162. //
  163. // include path in name
  164. //
  165. bool Full_Path_File_Exists( char const *file_name );
  166. //
  167. // don't include path in name
  168. //
  169. bool HD_File_Exists( char const *file_name );
  170. bool CD_File_Exists( char const *file_name );
  171. // bool Find_File( char const *file_name );
  172. #endif
  173. #if( SUPPORT_STREAMS )
  174. //
  175. // include path in name
  176. //
  177. bool Full_Path_File_Exists( char const *file_name );
  178. //
  179. // don't include path in name
  180. //
  181. bool HD_File_Exists( char const *file_name );
  182. bool CD_File_Exists( char const *file_name );
  183. // bool Find_File( char const *file_name );
  184. #endif
  185. #endif // WND_FILE_H