Skip to content

Commit f17504c

Browse files
committed
[GEN][ZH] Unify File System code (#1279)
1 parent 4e1aa51 commit f17504c

File tree

7 files changed

+63
-8
lines changed

7 files changed

+63
-8
lines changed

Generals/Code/GameEngine/Include/Common/FileSystem.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ struct FileInfo {
115115
* created when FileSystem::Open() gets called.
116116
*/
117117
//===============================
118+
#include <map>
118119

119120
class FileSystem : public SubsystemInterface
120121
{
122+
FileSystem(const FileSystem&);
123+
FileSystem& operator=(const FileSystem&);
124+
121125
public:
122126
FileSystem();
123127
virtual ~FileSystem();
@@ -139,8 +143,7 @@ class FileSystem : public SubsystemInterface
139143
AsciiString normalizePath(const AsciiString& path) const; ///< 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.
140144
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.
141145
protected:
142-
143-
146+
mutable std::map<unsigned,bool> m_fileExist;
144147
};
145148

146149
extern FileSystem* TheFileSystem;

Generals/Code/GameEngine/Source/Common/System/FileSystem.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ File* FileSystem::openFile( const Char *filename, Int access )
179179
if ( TheLocalFileSystem != NULL )
180180
{
181181
file = TheLocalFileSystem->openFile( filename, access );
182+
if (file != NULL && (file->getAccess() & File::CREATE))
183+
{
184+
unsigned key = TheNameKeyGenerator->nameToLowercaseKey(filename);
185+
m_fileExist[key] = true;
186+
}
182187
}
183188

184189
if ( (TheArchiveFileSystem != NULL) && (file == NULL) )
@@ -196,12 +201,24 @@ File* FileSystem::openFile( const Char *filename, Int access )
196201
Bool FileSystem::doesFileExist(const Char *filename) const
197202
{
198203
USE_PERF_TIMER(FileSystem)
199-
if (TheLocalFileSystem->doesFileExist(filename)) {
204+
205+
unsigned key=TheNameKeyGenerator->nameToLowercaseKey(filename);
206+
std::map<unsigned,bool>::iterator i=m_fileExist.find(key);
207+
if (i!=m_fileExist.end())
208+
return i->second;
209+
210+
if (TheLocalFileSystem->doesFileExist(filename))
211+
{
212+
m_fileExist[key]=true;
200213
return TRUE;
201214
}
202-
if (TheArchiveFileSystem->doesFileExist(filename)) {
215+
if (TheArchiveFileSystem->doesFileExist(filename))
216+
{
217+
m_fileExist[key]=true;
203218
return TRUE;
204219
}
220+
221+
m_fileExist[key]=false;
205222
return FALSE;
206223
}
207224

@@ -274,7 +291,11 @@ Bool FileSystem::areMusicFilesOnCD()
274291
cdRoot = cdi->getPath();
275292
if (!cdRoot.endsWith("\\"))
276293
cdRoot.concat("\\");
294+
#if RTS_GENERALS
277295
cdRoot.concat("gensec.big");
296+
#elif RTS_ZEROHOUR
297+
cdRoot.concat("genseczh.big");
298+
#endif
278299
DEBUG_LOG(("FileSystem::areMusicFilesOnCD() - checking for %s", cdRoot.str()));
279300
File *musicBig = TheLocalFileSystem->openFile(cdRoot.str());
280301
if (musicBig)

Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
#include "Common/GameAudio.h"
3434
#include "Common/GameMemory.h"
3535
#include "Common/LocalFileSystem.h"
36+
37+
#if RTS_ZEROHOUR
38+
#include "Common/Registry.h"
39+
#endif
40+
3641
#include "Win32Device/Common/Win32BIGFile.h"
3742
#include "Win32Device/Common/Win32BIGFileSystem.h"
3843
#include "Utility/endian_compat.h"
@@ -53,6 +58,16 @@ void Win32BIGFileSystem::init() {
5358
}
5459

5560
loadBigFilesFromDirectory("", "*.big");
61+
62+
#if RTS_ZEROHOUR
63+
// load original Generals assets
64+
AsciiString installPath;
65+
GetStringFromGeneralsRegistry("", "InstallPath", installPath );
66+
//@todo this will need to be ramped up to a crash for release
67+
DEBUG_ASSERTCRASH(installPath != "", ("Be 1337! Go install Generals!"));
68+
if (installPath!="")
69+
loadBigFilesFromDirectory(installPath, "*.big");
70+
#endif
5671
}
5772

5873
void Win32BIGFileSystem::reset() {

Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,4 @@ AsciiString Win32LocalFileSystem::normalizePath(const AsciiString& filePath) con
233233
}
234234

235235
return normalizedFilePath;
236-
}
236+
}

GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Bool FileSystem::createDirectory(AsciiString directory)
272272
Bool FileSystem::areMusicFilesOnCD()
273273
{
274274
#if 1
275-
return TRUE;
275+
return TRUE;
276276
#else
277277
if (!TheCDManager) {
278278
DEBUG_LOG(("FileSystem::areMusicFilesOnCD() - No CD Manager; returning false"));
@@ -291,7 +291,11 @@ Bool FileSystem::areMusicFilesOnCD()
291291
cdRoot = cdi->getPath();
292292
if (!cdRoot.endsWith("\\"))
293293
cdRoot.concat("\\");
294+
#if RTS_GENERALS
295+
cdRoot.concat("gensec.big");
296+
#elif RTS_ZEROHOUR
294297
cdRoot.concat("genseczh.big");
298+
#endif
295299
DEBUG_LOG(("FileSystem::areMusicFilesOnCD() - checking for %s", cdRoot.str()));
296300
File *musicBig = TheLocalFileSystem->openFile(cdRoot.str());
297301
if (musicBig)

GeneralsMD/Code/GameEngineDevice/Source/StdDevice/Common/StdBIGFileSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333
#include "Common/GameAudio.h"
3434
#include "Common/GameMemory.h"
3535
#include "Common/LocalFileSystem.h"
36+
37+
#if RTS_ZEROHOUR
38+
#include "Common/Registry.h"
39+
#endif
40+
3641
#include "StdDevice/Common/StdBIGFile.h"
3742
#include "StdDevice/Common/StdBIGFileSystem.h"
38-
#include "Common/Registry.h"
3943
#include "Utility/endian_compat.h"
4044

4145
static const char *BIGFileIdentifier = "BIGF";
@@ -54,13 +58,15 @@ void StdBIGFileSystem::init() {
5458

5559
loadBigFilesFromDirectory("", "*.big");
5660

61+
#if RTS_ZEROHOUR
5762
// load original Generals assets
5863
AsciiString installPath;
5964
GetStringFromGeneralsRegistry("", "InstallPath", installPath );
6065
//@todo this will need to be ramped up to a crash for release
6166
DEBUG_ASSERTCRASH(installPath != "", ("Be 1337! Go install Generals!"));
6267
if (installPath!="")
6368
loadBigFilesFromDirectory(installPath, "*.big");
69+
#endif
6470
}
6571

6672
void StdBIGFileSystem::reset() {

GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333
#include "Common/GameAudio.h"
3434
#include "Common/GameMemory.h"
3535
#include "Common/LocalFileSystem.h"
36+
37+
#if RTS_ZEROHOUR
38+
#include "Common/Registry.h"
39+
#endif
40+
3641
#include "Win32Device/Common/Win32BIGFile.h"
3742
#include "Win32Device/Common/Win32BIGFileSystem.h"
38-
#include "Common/Registry.h"
3943
#include "Utility/endian_compat.h"
4044

4145

@@ -55,13 +59,15 @@ void Win32BIGFileSystem::init() {
5559

5660
loadBigFilesFromDirectory("", "*.big");
5761

62+
#if RTS_ZEROHOUR
5863
// load original Generals assets
5964
AsciiString installPath;
6065
GetStringFromGeneralsRegistry("", "InstallPath", installPath );
6166
//@todo this will need to be ramped up to a crash for release
6267
DEBUG_ASSERTCRASH(installPath != "", ("Be 1337! Go install Generals!"));
6368
if (installPath!="")
6469
loadBigFilesFromDirectory(installPath, "*.big");
70+
#endif
6571
}
6672

6773
void Win32BIGFileSystem::reset() {

0 commit comments

Comments
 (0)