Win32BIGFile.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. ////// Win32BIGFile.cpp /////////////////////////
  24. // Bryan Cleveland, August 2002
  25. /////////////////////////////////////////////////////
  26. #include "Common/LocalFile.h"
  27. #include "Common/LocalFileSystem.h"
  28. #include "Common/RAMFile.h"
  29. #include "Common/StreamingArchiveFile.h"
  30. #include "Common/GameMemory.h"
  31. #include "Common/PerfTimer.h"
  32. #include "Win32Device/Common/Win32BIGFile.h"
  33. //============================================================================
  34. // Win32BIGFile::Win32BIGFile
  35. //============================================================================
  36. Win32BIGFile::Win32BIGFile()
  37. {
  38. }
  39. //============================================================================
  40. // Win32BIGFile::~Win32BIGFile
  41. //============================================================================
  42. Win32BIGFile::~Win32BIGFile()
  43. {
  44. }
  45. //============================================================================
  46. // Win32BIGFile::openFile
  47. //============================================================================
  48. File* Win32BIGFile::openFile( const Char *filename, Int access )
  49. {
  50. const ArchivedFileInfo *fileInfo = getArchivedFileInfo(AsciiString(filename));
  51. if (fileInfo == NULL) {
  52. return NULL;
  53. }
  54. RAMFile *ramFile = NULL;
  55. if (BitTest(access, File::STREAMING))
  56. ramFile = newInstance( StreamingArchiveFile );
  57. else
  58. ramFile = newInstance( RAMFile );
  59. ramFile->deleteOnClose();
  60. if (ramFile->openFromArchive(m_file, fileInfo->m_filename, fileInfo->m_offset, fileInfo->m_size) == FALSE) {
  61. ramFile->close();
  62. ramFile = NULL;
  63. return NULL;
  64. }
  65. if ((access & File::WRITE) == 0) {
  66. // requesting read only access. Just return the RAM file.
  67. return ramFile;
  68. }
  69. // whoever is opening this file wants write access, so copy the file to the local disk
  70. // and return that file pointer.
  71. File *localFile = TheLocalFileSystem->openFile(filename, access);
  72. if (localFile != NULL) {
  73. ramFile->copyDataToFile(localFile);
  74. }
  75. ramFile->close();
  76. ramFile = NULL;
  77. return localFile;
  78. }
  79. //============================================================================
  80. // Win32BIGFile::closeAllFiles
  81. //============================================================================
  82. void Win32BIGFile::closeAllFiles( void )
  83. {
  84. }
  85. //============================================================================
  86. // Win32BIGFile::getName
  87. //============================================================================
  88. AsciiString Win32BIGFile::getName( void )
  89. {
  90. return m_name;
  91. }
  92. //============================================================================
  93. // Win32BIGFile::getPath
  94. //============================================================================
  95. AsciiString Win32BIGFile::getPath( void )
  96. {
  97. return m_path;
  98. }
  99. //============================================================================
  100. // Win32BIGFile::setSearchPriority
  101. //============================================================================
  102. void Win32BIGFile::setSearchPriority( Int new_priority )
  103. {
  104. }
  105. //============================================================================
  106. // Win32BIGFile::close
  107. //============================================================================
  108. void Win32BIGFile::close( void )
  109. {
  110. }
  111. //============================================================================
  112. // Win32BIGFile::getFileInfo
  113. //============================================================================
  114. Bool Win32BIGFile::getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const
  115. {
  116. const ArchivedFileInfo *tempFileInfo = getArchivedFileInfo(filename);
  117. if (tempFileInfo == NULL) {
  118. return FALSE;
  119. }
  120. TheLocalFileSystem->getFileInfo(AsciiString(m_file->getName()), fileInfo);
  121. // fill in the size info. Since the size can't be bigger than a JUNK file, the high Int will always be 0.
  122. fileInfo->sizeHigh = 0;
  123. fileInfo->sizeLow = tempFileInfo->m_size;
  124. return TRUE;
  125. }