forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.h
More file actions
185 lines (154 loc) · 7.52 KB
/
FileSystem.h
File metadata and controls
185 lines (154 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------=
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright(C) 2001 - All Rights Reserved
//
//----------------------------------------------------------------------------
//
// Project: GameEngine
//
// Module: IO
//
// File name: FileSystem.h
//
// Created:
//
//----------------------------------------------------------------------------
#pragma once
//----------------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------------
#include "Common/file.h"
#include "Common/STLTypedefs.h"
#include "Common/SubsystemInterface.h"
#include <Utility/hash_map_adapter.h>
#include "mutex.h"
//----------------------------------------------------------------------------
// Forward References
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Type Defines
//----------------------------------------------------------------------------
typedef std::set<AsciiString, rts::less_than_nocase<AsciiString> > FilenameList;
typedef FilenameList::iterator FilenameListIter;
typedef UnsignedByte FileInstance;
//----------------------------------------------------------------------------
// Type Defines
//----------------------------------------------------------------------------
//#define W3D_DIR_PATH "../FinalArt/W3D/" ///< .w3d files live here
//#define TGA_DIR_PATH "../FinalArt/Textures/" ///< .tga texture files live here
//#define TERRAIN_TGA_DIR_PATH "../FinalArt/Terrain/" ///< terrain .tga texture files live here
#define W3D_DIR_PATH "Art/W3D/" ///< .w3d files live here
#define TGA_DIR_PATH "Art/Textures/" ///< .tga texture files live here
#define TERRAIN_TGA_DIR_PATH "Art/Terrain/" ///< terrain .tga texture files live here
#define MAP_PREVIEW_DIR_PATH "%sMapPreviews/" ///< We need a common place we can copy the map previews to at runtime.
#define USER_W3D_DIR_PATH "%sW3D/" ///< .w3d files live here
#define USER_TGA_DIR_PATH "%sTextures/" ///< User .tga texture files live here
// the following defines are only to be used while maintaining legacy compatibility
// with old files until they are completely gone and in the regular art set
#ifdef MAINTAIN_LEGACY_FILES
#define LEGACY_W3D_DIR_PATH "../LegacyArt/W3D/" ///< .w3d files live here
#define LEGACY_TGA_DIR_PATH "../LegacyArt/Textures/" ///< .tga texture files live here
#endif // MAINTAIN_LEGACY_FILES
// LOAD_TEST_ASSETS automatically loads w3d assets from the TEST_W3D_DIR_PATH
// without having to add an INI entry.
#if defined(RTS_DEBUG)
#define LOAD_TEST_ASSETS 1
#endif
#ifdef LOAD_TEST_ASSETS
#define ROAD_DIRECTORY "../TestArt/TestRoad/"
#define TEST_STRING "***TESTING"
// the following directories will be used to look for test art
#define LOOK_FOR_TEST_ART
#define TEST_W3D_DIR_PATH "../TestArt/" ///< .w3d files live here
#define TEST_TGA_DIR_PATH "../TestArt/" ///< .tga texture files live here
#endif
#ifndef ENABLE_FILESYSTEM_LOGGING
#define ENABLE_FILESYSTEM_LOGGING (0)
#endif
struct FileInfo {
Int64 size() const { return (Int64)sizeHigh << 32 | sizeLow; }
Int64 timestamp() const { return (Int64)timestampHigh << 32 | timestampLow; }
Int sizeHigh;
Int sizeLow;
Int timestampHigh;
Int timestampLow;
};
//===============================
// FileSystem
//===============================
/**
* FileSystem is an interface class for creating specific FileSystem objects.
*
* A FileSystem object's implementation decides what derivative of File object needs to be
* created when FileSystem::Open() gets called.
*/
// TheSuperHackers @feature xezon 23/08/2025 Implements file instance access.
// Can be used to access different versions of files in different archives under the same name.
// Instance 0 refers to the top file that shadows all other files under the same name.
//
// TheSuperHackers @bugfix xezon 26/10/2025 Adds a mutex to the file exist map to try prevent
// application hangs during level load after the file exist map was corrupted because of writes
// from multiple threads.
//===============================
class FileSystem : public SubsystemInterface
{
FileSystem(const FileSystem&);
FileSystem& operator=(const FileSystem&);
public:
FileSystem();
virtual ~FileSystem() override;
virtual void init() override;
virtual void reset() override;
virtual void update() override;
File* openFile( const Char *filename, Int access = File::NONE, size_t bufferSize = File::BUFFERSIZE, FileInstance instance = 0 ); ///< opens a File interface to the specified file
Bool doesFileExist(const Char *filename, FileInstance instance = 0) const; ///< returns TRUE if the file exists. filename should have no directory.
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.
Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo, FileInstance instance = 0) const; ///< fills in the FileInfo struct for the file given. returns TRUE if successful.
Bool createDirectory(AsciiString directory); ///< create a directory of the given name.
static AsciiString normalizePath(const AsciiString& path); ///< normalizes a file path. The path can refer to a directory. File path must be absolute, but does not need to exist. Returns an empty string on failure.
static Bool isPathInDirectory(const AsciiString& testPath, const AsciiString& basePath); ///< determines if a file path is within a base path. Both paths must be absolute, but do not need to exist.
protected:
#if ENABLE_FILESYSTEM_EXISTENCE_CACHE
struct FileExistData
{
FileExistData() : instanceExists(0), instanceDoesNotExist(~FileInstance(0)) {}
FileInstance instanceExists;
FileInstance instanceDoesNotExist;
};
typedef std::hash_map<
rts::string_key<AsciiString>, FileExistData,
rts::string_key_hash<AsciiString>,
rts::string_key_equal<AsciiString> > FileExistMap;
mutable FileExistMap m_fileExist;
mutable FastCriticalSectionClass m_fileExistMutex;
#endif
};
extern FileSystem* TheFileSystem;
//----------------------------------------------------------------------------
// Inlining
//----------------------------------------------------------------------------