RAWFILE.H (12755B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\rawfile.h_v 2.15 06 Sep 1995 16:29:30 JOE_BOSTIC $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Westwood Library * 22 * * 23 * File Name : RAWFILE.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : August 8, 1994 * 28 * * 29 * Last Update : October 18, 1994 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * RawFileClass::File_Name -- Returns with the filename associate with the file object. * 34 * RawFileClass::RawFileClass -- Default constructor for a file object. * 35 * RawFileClass::Is_Open -- Checks to see if the file is open or not. * 36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 37 38 #ifndef RAWFILE_H 39 #define RAWFILE_H 40 41 #ifndef WIN32 42 #define WIN32 1 43 #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check 44 #define _WIN32 45 #endif // _WIN32 46 #endif 47 #include <windows.h> 48 49 //#include <wwlib32.h> 50 #include <limits.h> 51 #include <errno.h> 52 #include <windows.h> 53 //#include <algo.h> 54 #include "wwfile.h" 55 56 #ifdef NEVER 57 /* 58 ** This is a duplicate of the error numbers. The error handler for the RawFileClass handles 59 ** these errors. If the error routine is overridden and additional errors are defined, then 60 ** use numbers starting with 100. Note that these errors here are listed in numerical order. 61 ** These errors are defined in the standard header file "ERRNO.H". 62 */ 63 EZERO, // Non-error. 64 EINVFNC, // Invalid function number. 65 ENOFILE, // File not found. 66 ENOENT=ENOFILE, // No such file or directory. 67 ENOPATH, // Path not found. 68 EMFILE, // Too many open files. 69 EACCES, // Permission denied. 70 EBADF, // Bad file number. 71 ECONTR, // Memory blocks destroyed. 72 ENOMEM, // Not enough core memory. 73 EINVMEM, // Invalid memory block address. 74 EINVENV, // Invalid environment. 75 EINVFMT, // Invalid format. 76 EINVACC, // Invalid access code. 77 EINVDAT, // Invalid data. 78 EFAULT, // Unknown error. 79 EINVDRV, // Invalid drive specified. 80 ENODEV=EINVDRV, // No such device. 81 ECURDIR, // Attempt to remove CurDir. 82 ENOTSAM, // Not same device. 83 ENMFILE, // No more files. 84 EINVAL, // Invalid argument. 85 E2BIG, // Argument list too long. 86 ENOEXEC, // exec format error. 87 EXDEV, // Cross-device link. 88 ENFILE, // Too many open files. 89 ECHILD, // No child process. 90 ENOTTY, // not used 91 ETXTBSY, // not used 92 EFBIG, // not used 93 ENOSPC, // No space left on device. 94 ESPIPE, // Illegal seek. 95 EROFS, // Read-only file system. 96 EMLINK, // not used 97 EPIPE, // Broken pipe. 98 EDOM, // Math argument. 99 ERANGE, // Result too large. 100 EEXIST, // File already exists. 101 EDEADLOCK, // Locking violation. 102 EPERM, // Operation not permitted. 103 ESRCH, // not used 104 EINTR, // Interrupted function call. 105 EIO, // Input/output error. 106 ENXIO, // No such device or address. 107 EAGAIN, // Resource temporarily unavailable. 108 ENOTBLK, // not used 109 EBUSY, // Resource busy. 110 ENOTDIR, // not used 111 EISDIR, // not used 112 EUCLEAN, // not used 113 #endif 114 115 /* 116 ** This is the definition of the raw file class. It is derived from the abstract base FileClass 117 ** and handles the interface to the low level DOS routines. This is the first class in the 118 ** chain of derived file classes that actually performs a useful function. With this class, 119 ** I/O is possible. More sophisticated features, such as packed files, CD-ROM support, 120 ** file caching, and XMS/EMS memory support, are handled by derived classes. 121 ** 122 ** Of particular importance is the need to override the error routine if more sophisticated 123 ** error handling is required. This is more than likely if greater functionality is derived 124 ** from this base class. 125 */ 126 class RawFileClass : public FileClass 127 { 128 public: 129 130 /* 131 ** This is a record of the access rights used to open the file. These rights are 132 ** used if the file object is duplicated. 133 */ 134 int Rights; 135 136 RawFileClass(char const *filename); 137 RawFileClass(void); 138 RawFileClass (RawFileClass const & f); 139 RawFileClass & operator = (RawFileClass const & f); 140 virtual ~RawFileClass(void) {if (Allocated && Filename) free((char *)Filename);}; 141 142 virtual char const * File_Name(void) const; 143 virtual char const * Set_Name(char const *filename); 144 virtual int Create(void); 145 virtual int Delete(void); 146 virtual int Is_Available(int forced=false); 147 virtual int Is_Open(void) const; 148 virtual int Open(char const *filename, int rights=READ); 149 virtual int Open(int rights=READ); 150 virtual long Read(void *buffer, long size); 151 virtual long Seek(long pos, int dir=SEEK_CUR); 152 virtual long Size(void); 153 virtual long Write(void const *buffer, long size); 154 virtual void Close(void); 155 virtual void Error(int error, int canretry = false, char const * filename=NULL); 156 virtual void Set_Buffer_Size(int size); 157 158 159 protected: 160 161 /* 162 ** This function returns the largest size a low level DOS read or write may 163 ** perform. Larger file transfers are performed in chunks of this size or less. 164 */ 165 long Transfer_Block_Size(void) {return (long)((unsigned)UINT_MAX)-16L;}; 166 167 private: 168 169 /* 170 ** This is the low level DOS handle. A -1 indicates an empty condition. 171 */ 172 int Handle; 173 174 /* 175 ** This points to the filename as a NULL terminated string. It may point to either a 176 ** constant or an allocated string as indicated by the "Allocated" flag. 177 */ 178 char const * const Filename; 179 180 /* 181 ** Filenames that were assigned as part of the construction process 182 ** are not allocated. It is assumed that the filename string is a 183 ** constant in that case and thus making duplication unnecessary. 184 ** This value will be non-zero if the filename has be allocated 185 ** (using strdup()). 186 */ 187 unsigned Allocated:1; 188 }; 189 190 191 /*********************************************************************************************** 192 * RawFileClass::File_Name -- Returns with the filename associate with the file object. * 193 * * 194 * Use this routine to determine what filename is associated with this file object. If no * 195 * filename has yet been assigned, then this routing will return NULL. * 196 * * 197 * INPUT: none * 198 * * 199 * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL * 200 * if one doesn't exist. * 201 * * 202 * WARNINGS: none * 203 * * 204 * HISTORY: * 205 ;* 10/18/1994 JLB : Created. * 206 *=============================================================================================*/ 207 inline char const * RawFileClass::File_Name(void) const 208 { 209 return Filename; 210 } 211 212 /*********************************************************************************************** 213 * RawFileClass::RawFileClass -- Default constructor for a file object. * 214 * * 215 * This constructs a null file object. A null file object has no file handle or filename * 216 * associated with it. In order to use a file object created in this fashion it must be * 217 * assigned a name and then opened. * 218 * * 219 * INPUT: none * 220 * * 221 * OUTPUT: none * 222 * * 223 * WARNINGS: none * 224 * * 225 * HISTORY: * 226 ;* 10/18/1994 JLB : Created. * 227 *=============================================================================================*/ 228 inline RawFileClass::RawFileClass(void) : Filename(0) 229 { 230 Handle = -1; 231 Allocated = false; 232 } 233 234 /*********************************************************************************************** 235 * RawFileClass::Is_Open -- Checks to see if the file is open or not. * 236 * * 237 * Use this routine to determine if the file is open. It returns true if it is. * 238 * * 239 * INPUT: none * 240 * * 241 * OUTPUT: bool; Is the file open? * 242 * * 243 * * 244 * WARNINGS: none * 245 * * 246 * HISTORY: * 247 ;* 10/18/1994 JLB : Created. * 248 *=============================================================================================*/ 249 inline int RawFileClass::Is_Open(void) const 250 { 251 return (Handle != -1); 252 } 253 254 #endif