StreamingArchiveFile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------=
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright(C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: RTS 3
  33. //
  34. // Module: IO
  35. //
  36. // File name: Common/StreamingArchiveFile.h
  37. //
  38. // Created: 11/08/01
  39. //
  40. //----------------------------------------------------------------------------
  41. #pragma once
  42. #ifndef __STREAMINGARCHIVEFILE_H
  43. #define __STREAMINGARCHIVEFILE_H
  44. //----------------------------------------------------------------------------
  45. // Includes
  46. //----------------------------------------------------------------------------
  47. #include "Common/RAMFile.h"
  48. //----------------------------------------------------------------------------
  49. // Forward References
  50. //----------------------------------------------------------------------------
  51. //----------------------------------------------------------------------------
  52. // Type Defines
  53. //----------------------------------------------------------------------------
  54. //===============================
  55. // StreamingArchiveFile
  56. //===============================
  57. /**
  58. * File abstraction for standard C file operators: open, close, lseek, read, write
  59. */
  60. //===============================
  61. class StreamingArchiveFile : public RAMFile
  62. {
  63. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(StreamingArchiveFile, "StreamingArchiveFile")
  64. protected:
  65. File *m_file; ///< The archive file that I came from
  66. Int m_startingPos; ///< My starting position in the archive
  67. Int m_size; ///< My length
  68. Int m_curPos; ///< My current position.
  69. public:
  70. StreamingArchiveFile();
  71. //virtual ~StreamingArchiveFile();
  72. virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access
  73. virtual void close( void ); ///< Close the file
  74. virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read
  75. virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write
  76. virtual Int seek( Int new_pos, seekMode mode = CURRENT ); ///< Set file position: See File::seek
  77. // Ini's should not be parsed with streaming files, that's just dumb.
  78. virtual void nextLine(Char *buf = NULL, Int bufSize = 0) { DEBUG_CRASH(("Should not call nextLine on a streaming file.\n")); }
  79. virtual Bool scanInt(Int &newInt) { DEBUG_CRASH(("Should not call scanInt on a streaming file.\n")); return FALSE; }
  80. virtual Bool scanReal(Real &newReal) { DEBUG_CRASH(("Should not call scanReal on a streaming file.\n")); return FALSE; }
  81. virtual Bool scanString(AsciiString &newString) { DEBUG_CRASH(("Should not call scanString on a streaming file.\n")); return FALSE; }
  82. virtual Bool open( File *file ); ///< Open file for fast RAM access
  83. virtual Bool openFromArchive(File *archiveFile, const AsciiString& filename, Int offset, Int size); ///< copy file data from the given file at the given offset for the given size.
  84. virtual Bool copyDataToFile(File *localFile) { DEBUG_CRASH(("Are you sure you meant to copyDataToFile on a streaming file?")); return FALSE; }
  85. virtual char* readEntireAndClose() { DEBUG_CRASH(("Are you sure you meant to readEntireAndClose on a streaming file?")); return NULL; }
  86. virtual File* convertToRAMFile() { DEBUG_CRASH(("Are you sure you meant to readEntireAndClose on a streaming file?")); return this; }
  87. };
  88. //----------------------------------------------------------------------------
  89. // Inlining
  90. //----------------------------------------------------------------------------
  91. #endif // __STREAMINGARCHIVEFILE_H