RAMFileFactory.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Installer *
  23. * *
  24. * $Archive:: /Commando/Code/Installer/RAMFileFactory.cpp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 10/31/01 2:57p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "RAMFileFactory.h"
  37. #include "BuffFile.h"
  38. #include "RamFile.h"
  39. /***********************************************************************************************
  40. * RAMFileFactoryClass::RAMFileFactoryClass -- *
  41. * *
  42. * INPUT: *
  43. * *
  44. * OUTPUT: *
  45. * *
  46. * WARNINGS: *
  47. * *
  48. * HISTORY: *
  49. * 08/22/01 IML : Created. *
  50. *=============================================================================================*/
  51. RAMFileFactoryClass::RAMFileFactoryClass()
  52. : FileFactoryClass(),
  53. FileBuffer (NULL)
  54. {
  55. }
  56. /***********************************************************************************************
  57. * RAMFileFactoryClass::RAMFileFactoryClass -- *
  58. * *
  59. * INPUT: *
  60. * *
  61. * OUTPUT: *
  62. * *
  63. * WARNINGS: *
  64. * *
  65. * HISTORY: *
  66. * 08/22/01 IML : Created. *
  67. *=============================================================================================*/
  68. RAMFileFactoryClass::~RAMFileFactoryClass()
  69. {
  70. if (FileBuffer != NULL) delete [] FileBuffer;
  71. }
  72. /***********************************************************************************************
  73. * RAMFileFactoryClass::Get_File -- *
  74. * *
  75. * INPUT: *
  76. * *
  77. * OUTPUT: *
  78. * *
  79. * WARNINGS: *
  80. * *
  81. * HISTORY: *
  82. * 08/22/01 IML : Created. *
  83. *=============================================================================================*/
  84. FileClass *RAMFileFactoryClass::Get_File (const char *filename)
  85. {
  86. RAMFileClass *ramfile;
  87. // If file buffer has not been read then do it now.
  88. if ((FileBuffer == NULL) || (stricmp (filename, FileName) != 0)) {
  89. BufferedFileClass *bufferfile;
  90. if (FileBuffer != NULL) delete [] FileBuffer;
  91. bufferfile = new BufferedFileClass (filename);
  92. if ((bufferfile != NULL) && bufferfile->Is_Available()) {
  93. FileBuffer = new unsigned char [bufferfile->Size()];
  94. bufferfile->Open();
  95. bufferfile->Read (FileBuffer, bufferfile->Size());
  96. }
  97. FileBufferSize = bufferfile->Size();
  98. FileName = filename;
  99. // Clean-up.
  100. delete bufferfile;
  101. }
  102. ramfile = new RAMFileClass (FileBuffer, FileBufferSize);
  103. return (ramfile);
  104. }
  105. /***********************************************************************************************
  106. * RAMFileFactoryClass::Return_File -- *
  107. * *
  108. * INPUT: *
  109. * *
  110. * OUTPUT: *
  111. * *
  112. * WARNINGS: *
  113. * *
  114. * HISTORY: *
  115. * 08/22/01 IML : Created. *
  116. *=============================================================================================*/
  117. void RAMFileFactoryClass::Return_File (FileClass *file)
  118. {
  119. delete file;
  120. }