FileSystem.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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: GameEngine
  33. //
  34. // Module: IO
  35. //
  36. // File name: FileSystem.h
  37. //
  38. // Created:
  39. //
  40. //----------------------------------------------------------------------------
  41. #pragma once
  42. #ifndef __FILESYSTEM_H
  43. #define __FILESYSTEM_H
  44. //----------------------------------------------------------------------------
  45. // Includes
  46. //----------------------------------------------------------------------------
  47. //#include "Common/File.h"
  48. #include "Common/STLTypedefs.h"
  49. #include "Common/SubsystemInterface.h"
  50. //----------------------------------------------------------------------------
  51. // Forward References
  52. //----------------------------------------------------------------------------
  53. class File;
  54. //----------------------------------------------------------------------------
  55. // Type Defines
  56. //----------------------------------------------------------------------------
  57. typedef std::set<AsciiString, rts::less_than_nocase<AsciiString> > FilenameList;
  58. typedef FilenameList::iterator FilenameListIter;
  59. //----------------------------------------------------------------------------
  60. // Type Defines
  61. //----------------------------------------------------------------------------
  62. //#define W3D_DIR_PATH "../FinalArt/W3D/" ///< .w3d files live here
  63. //#define TGA_DIR_PATH "../FinalArt/Textures/" ///< .tga texture files live here
  64. //#define TERRAIN_TGA_DIR_PATH "../FinalArt/Terrain/" ///< terrain .tga texture files live here
  65. #define W3D_DIR_PATH "Art/W3D/" ///< .w3d files live here
  66. #define TGA_DIR_PATH "Art/Textures/" ///< .tga texture files live here
  67. #define TERRAIN_TGA_DIR_PATH "Art/Terrain/" ///< terrain .tga texture files live here
  68. #define MAP_PREVIEW_DIR_PATH "%sMapPreviews/" ///< We need a common place we can copy the map previews to at runtime.
  69. #define USER_W3D_DIR_PATH "%sW3D/" ///< .w3d files live here
  70. #define USER_TGA_DIR_PATH "%sTextures/" ///< User .tga texture files live here
  71. // the following defines are only to be used while maintaining legacy compatability
  72. // with old files until they are completely gone and in the regular art set
  73. #ifdef MAINTAIN_LEGACY_FILES
  74. #define LEGACY_W3D_DIR_PATH "../LegacyArt/W3D/" ///< .w3d files live here
  75. #define LEGACY_TGA_DIR_PATH "../LegacyArt/Textures/" ///< .tga texture files live here
  76. #endif // MAINTAIN_LEGACY_FILES
  77. // LOAD_TEST_ASSETS automatically loads w3d assets from the TEST_W3D_DIR_PATH
  78. // without having to add an INI entry.
  79. ///@todo this allows us to use the test art directory, it should be removed for FINAL release
  80. #define LOAD_TEST_ASSETS 1
  81. #ifdef LOAD_TEST_ASSETS
  82. #define ROAD_DIRECTORY "../TestArt/TestRoad/"
  83. #define TEST_STRING "***TESTING"
  84. // the following directories will be used to look for test art
  85. #define LOOK_FOR_TEST_ART
  86. #define TEST_W3D_DIR_PATH "../TestArt/" ///< .w3d files live here
  87. #define TEST_TGA_DIR_PATH "../TestArt/" ///< .tga texture files live here
  88. #endif
  89. struct FileInfo {
  90. Int sizeHigh;
  91. Int sizeLow;
  92. Int timestampHigh;
  93. Int timestampLow;
  94. };
  95. //===============================
  96. // FileSystem
  97. //===============================
  98. /**
  99. * FileSystem is an interface class for creating specific FileSystem objects.
  100. *
  101. * A FileSystem object's implemenation decides what derivative of File object needs to be
  102. * created when FileSystem::Open() gets called.
  103. */
  104. //===============================
  105. #include <map>
  106. class FileSystem : public SubsystemInterface
  107. {
  108. FileSystem(const FileSystem&);
  109. FileSystem& operator=(const FileSystem&);
  110. public:
  111. FileSystem();
  112. virtual ~FileSystem();
  113. void init();
  114. void reset();
  115. void update();
  116. File* openFile( const Char *filename, Int access = 0 ); ///< opens a File interface to the specified file
  117. Bool doesFileExist(const Char *filename) const; ///< returns TRUE if the file exists. filename should have no directory.
  118. void getFileListInDirectory(const AsciiString& directory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories.
  119. Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const; ///< fills in the FileInfo struct for the file given. returns TRUE if successful.
  120. Bool createDirectory(AsciiString directory); ///< create a directory of the given name.
  121. Bool areMusicFilesOnCD();
  122. void loadMusicFilesFromCD();
  123. void unloadMusicFilesFromCD();
  124. protected:
  125. mutable std::map<unsigned,bool> m_fileExist;
  126. };
  127. extern FileSystem* TheFileSystem;
  128. //----------------------------------------------------------------------------
  129. // Inlining
  130. //----------------------------------------------------------------------------
  131. #endif // __WSYS_FILESYSTEM_H