File.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. ** Command & Conquer Renegade(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. *
  20. * FILE
  21. * $Archive: /Commando/Code/Launcher/Toolkit/Storage/File.h $
  22. *
  23. * DESCRIPTION
  24. * File definitions (Windows)
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Modtime: 9/23/00 6:19p $
  32. * $Revision: 1 $
  33. *
  34. ****************************************************************************/
  35. #ifndef FILE_H
  36. #define FILE_H
  37. #include <Support\UTypes.h>
  38. #include "Stream.h"
  39. #include "Rights.h"
  40. #include <Support\UString.h>
  41. #include <windows.h>
  42. class File : public Stream
  43. {
  44. public:
  45. // File Error conditions
  46. typedef enum
  47. {
  48. FileError_None = 0,
  49. FileError_FNF,
  50. FileError_Access,
  51. FileError_Open,
  52. FileError_Read,
  53. FileError_Write,
  54. FileError_Seek,
  55. FileError_Nomem,
  56. FileError_Fault,
  57. } EFileError;
  58. //! Default constructor - Create an unassociated File
  59. File();
  60. //! Name constructor - Create a File with an associated name
  61. File(const Char* name, ERights rights = Rights_ReadOnly);
  62. File(const UString& name, ERights rights = Rights_ReadOnly);
  63. //! Destructor
  64. virtual ~File();
  65. //! Retrieve name of file
  66. const UString& GetName(void) const;
  67. //! Associate a name to the file
  68. virtual void SetName(const UString& name);
  69. //! Retrieve file access rights
  70. virtual ERights GetRights(void) const;
  71. //! Set file access rights
  72. virtual void SetRights(ERights rights);
  73. //! Check if the file is available
  74. virtual bool IsAvailable(bool force = false);
  75. //! Check if te file is open
  76. virtual bool IsOpen(void) const;
  77. //! Open the file for access.
  78. virtual EFileError Open(ERights rights);
  79. //! Open the file with the associated name for access
  80. virtual EFileError Open(const UString& name, ERights rights);
  81. //! Close the file
  82. virtual void Close(void);
  83. //! Create a new file
  84. virtual EFileError Create(void);
  85. //! Delete an existing file
  86. virtual EFileError Delete(void);
  87. //! Load the file into memory
  88. virtual EFileError Load(void*& outBuffer, UInt32& outSize);
  89. //! Write file data
  90. virtual EFileError Save(const void* buffer, UInt32 size);
  91. //! Error handling hook
  92. virtual bool OnFileError(EFileError error, bool canRetry);
  93. //-----------------------------------------------------------------------
  94. // STREAM INTERFACE
  95. //-----------------------------------------------------------------------
  96. //! Get the length of the file
  97. virtual UInt32 GetLength(void);
  98. //! Set the length of the file
  99. virtual void SetLength(UInt32 length);
  100. //! Get file position marker
  101. virtual UInt32 GetMarker(void);
  102. //! Set file position marker
  103. virtual void SetMarker(Int32 offset, EStreamFrom from);
  104. //! End of file test
  105. virtual bool AtEnd(void);
  106. //! Read bytes from the file
  107. virtual UInt32 GetBytes(void* ptr, UInt32 bytes);
  108. //! Write bytes to the file
  109. virtual UInt32 PutBytes(const void* ptr, UInt32 bytes);
  110. //! Read bytes from the file without marker adjustment
  111. virtual UInt32 PeekBytes(void* ptr, UInt32 bytes);
  112. //! Flush the stream
  113. virtual void Flush(void);
  114. private:
  115. UString mName;
  116. ERights mRights;
  117. HANDLE mHandle;
  118. static const HANDLE INVALID_HANDLE;
  119. };
  120. #endif // FILE_H