Skip to content

Commit 9dab0ac

Browse files
authored
Fixes to filesystem classes. Stuff now matches ZH WB much more closely. (#781)
1 parent 52747d6 commit 9dab0ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+749
-721
lines changed

src/game/client/gametext.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void GameTextManager::Reverse_Word(char *start, char *end)
343343
// Get the count of strings in a str file.
344344
bool GameTextManager::Get_String_Count(const char *filename, int &count)
345345
{
346-
File *file = g_theFileSystem->Open(filename, File::TEXT | File::READ);
346+
File *file = g_theFileSystem->Open_File(filename, File::TEXT | File::READ);
347347
count = 0;
348348

349349
if (file == nullptr) {
@@ -375,7 +375,7 @@ bool GameTextManager::Get_CSF_Info(const char *filename)
375375
{
376376
static_assert(sizeof(CSFHeader) == 24, "CSFHeader struct not expected size.");
377377
CSFHeader header;
378-
File *file = g_theFileSystem->Open(filename, File::BINARY | File::READ);
378+
File *file = g_theFileSystem->Open_File(filename, File::BINARY | File::READ);
379379

380380
if (file == nullptr || file->Read(&header, sizeof(header)) != sizeof(header)
381381
|| header.id != FourCC<' ', 'F', 'S', 'C'>::value) {
@@ -399,7 +399,7 @@ bool GameTextManager::Get_CSF_Info(const char *filename)
399399
bool GameTextManager::Parse_String_File(const char *filename)
400400
{
401401
captainslog_info("Parsing string file '%s'.", filename);
402-
File *file = g_theFileSystem->Open(filename, File::TEXT | File::READ);
402+
File *file = g_theFileSystem->Open_File(filename, File::TEXT | File::READ);
403403

404404
if (file == nullptr) {
405405
return false;
@@ -485,7 +485,7 @@ bool GameTextManager::Parse_CSF_File(const char *filename)
485485
{
486486
captainslog_info("Parsing CSF file '%s'.", filename);
487487
CSFHeader header;
488-
File *file = g_theFileSystem->Open(filename, File::BINARY | File::READ);
488+
File *file = g_theFileSystem->Open_File(filename, File::BINARY | File::READ);
489489

490490
if (file == nullptr || file->Read(&header, sizeof(header)) != sizeof(header)) {
491491
return false;
@@ -588,7 +588,7 @@ bool GameTextManager::Parse_CSF_File(const char *filename)
588588
bool GameTextManager::Parse_Map_String_File(const char *filename)
589589
{
590590
captainslog_info("Parsing map string file '%s'.", filename);
591-
File *file = g_theFileSystem->Open(filename, File::TEXT | File::READ);
591+
File *file = g_theFileSystem->Open_File(filename, File::TEXT | File::READ);
592592

593593
if (file == nullptr) {
594594
return false;

src/game/client/shadermanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ long W3DShaderManager::Load_And_Create_D3D_Shader(
409409
if (W3DShaderManager::Get_Chipset() < GPU_PS11) {
410410
return E_FAIL;
411411
}
412-
File *file = g_theFileSystem->Open(path, File::BINARY | File::READ);
412+
File *file = g_theFileSystem->Open_File(path, File::BINARY | File::READ);
413413

414414
if (file == nullptr) {
415415
captainslog_debug("Could not find file \n");

src/game/client/water/w3dwatertracks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void WaterTracksRenderSystem::Load_Tracks()
799799
char fname[256];
800800
strcpy(fname, filename.Str());
801801
strcpy(&fname[strlen(fname) - 4], ".wak");
802-
File *f = g_theFileSystem->Open(fname, File::BINARY | File::READ);
802+
File *f = g_theFileSystem->Open_File(fname, File::BINARY | File::READ);
803803
int count = 0;
804804
int flip = 0;
805805
Vector2 start;

src/game/client/worldheightmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,11 @@ void WorldHeightMap::Read_Tex_Class(TXTextureClass *tex_class, TileData **tile_d
793793
TerrainType *terrain = g_theTerrainTypes->Find_Terrain(tex_class->name);
794794

795795
if (!terrain) {
796-
file = g_theFileSystem->Open(tex_class->name, File::BINARY | File::READ);
796+
file = g_theFileSystem->Open_File(tex_class->name, File::BINARY | File::READ);
797797
} else {
798798
char fname[260];
799799
sprintf(fname, "%s%s", "Art/Terrain/", terrain->Get_Texture().Str());
800-
file = g_theFileSystem->Open(fname, File::BINARY | File::READ);
800+
file = g_theFileSystem->Open_File(fname, File::BINARY | File::READ);
801801
}
802802

803803
if (file) {

src/game/common/audio/audioeventrts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ Utf8String AudioEventRTS::Generate_Filename_Extension(AudioType type)
454454
void AudioEventRTS::Adjust_For_Localization(Utf8String &filename)
455455
{
456456
// Search for both posix and windows path separator, original only searches windows.
457-
char *tmp = filename.Reverse_Find('/');
457+
const char *tmp = filename.Reverse_Find('/');
458458

459459
if (tmp == nullptr) {
460460
tmp = filename.Reverse_Find('\\');

src/game/common/audio/audiomanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void AudioManager::Init()
9292

9393
if (!Is_Music_Already_Loaded()) {
9494
m_fromCD = true;
95-
captainslog_warn("Music not detected as loaded, this shouldn't happen with released game data.");
95+
captainslog_dbgassert(false, "Music not detected as loaded, this shouldn't happen with released game data.");
9696
// Original code prompts to insert disc at this point, but it shouldn't be possible with the shipped
9797
// installer to install without the audio installed to the hard drive.
9898
}

src/game/common/globaldata.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,15 @@ GlobalData::GlobalData()
10161016
// crc the skirmish and multiplayer scripts.
10171017
int read = 0;
10181018
uint8_t buffer[CRC_BUFFER_SIZE];
1019-
File *scriptfile = g_theFileSystem->Open("Data/Scripts/SkirmishScripts.scb", File::BINARY | File::READ);
1019+
File *scriptfile = g_theFileSystem->Open_File("Data/Scripts/SkirmishScripts.scb", File::BINARY | File::READ);
10201020
if (scriptfile) {
10211021
while ((read = scriptfile->Read(buffer, sizeof(buffer))) != 0) {
10221022
crc.Compute_CRC(buffer, read);
10231023
}
10241024

10251025
scriptfile->Close();
10261026
}
1027-
scriptfile = g_theFileSystem->Open("Data/Scripts/MultiplayerScripts.scb", File::BINARY | File::READ);
1027+
scriptfile = g_theFileSystem->Open_File("Data/Scripts/MultiplayerScripts.scb", File::BINARY | File::READ);
10281028
if (scriptfile) {
10291029
while ((read = scriptfile->Read(buffer, sizeof(buffer))) != 0) {
10301030
crc.Compute_CRC(buffer, read);
@@ -1050,7 +1050,7 @@ GlobalData::GlobalData()
10501050
#elif PLATFORM_OSX
10511051
// TODO
10521052
#endif // PLATFORM_WINDOWS
1053-
g_theFileSystem->Create_Dir(m_userDataDirectory);
1053+
g_theFileSystem->Create_Directory(m_userDataDirectory);
10541054
m_retaliationModeEnabled = true;
10551055
captainslog_info("User data directory is set to '%s'.", m_userDataDirectory.Str());
10561056
}

src/game/common/ini/ini.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void INI::Load_Directory(Utf8String dir, bool search_subdirs, INILoadType type,
247247
std::set<Utf8String, rts::less_than_nocase<Utf8String>> files;
248248
dir += '/';
249249

250-
g_theFileSystem->Get_File_List_From_Dir(dir, "*.ini", files, true);
250+
g_theFileSystem->Get_File_List_In_Directory(dir, "*.ini", files, true);
251251

252252
// Load everything from the top level directory first.
253253
for (auto it = files.begin(); it != files.end(); ++it) {
@@ -274,7 +274,7 @@ void INI::Prep_File(Utf8String filename, INILoadType type)
274274
{
275275
captainslog_relassert(m_backingFile == nullptr, 0xDEAD0006, "Cannot open file %s, file already open.", filename.Str());
276276

277-
m_backingFile = g_theFileSystem->Open(filename.Str(), File::READ);
277+
m_backingFile = g_theFileSystem->Open_File(filename.Str(), File::READ);
278278

279279
captainslog_relassert(m_backingFile != nullptr, 0xDEAD0006, "Could not open file %s.", filename.Str());
280280

src/game/common/system/archivefile.cpp

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
*/
1515
#include "archivefile.h"
1616
#include "file.h"
17+
bool Search_String_Matches(Utf8String string, Utf8String search);
1718

18-
ArchivedFileInfo *ArchiveFile::Get_Archived_File_Info(Utf8String const &filename)
19+
const ArchivedFileInfo *ArchiveFile::Get_Archived_File_Info(Utf8String const &filename) const
1920
{
2021
Utf8String path = filename;
2122
Utf8String token;
22-
DetailedArchiveDirectoryInfo *dirp = &m_archiveInfo;
23+
const DetailedArchivedDirectoryInfo *dirp = &m_archiveInfo;
2324

2425
// Lower case for matching and get first item of the path.
2526
path.To_Lower();
@@ -28,102 +29,102 @@ ArchivedFileInfo *ArchiveFile::Get_Archived_File_Info(Utf8String const &filename
2829
// Consider existence of '.' to indicate file as all should have .ext format
2930
// checks the remaining path does not contain one to catch directories in path
3031
// that do.
31-
while (strchr(token.Str(), '.') == nullptr || strchr(path.Str(), '.') != nullptr) {
32-
if (dirp->directories.find(token) == dirp->directories.end()) {
32+
while (token.Find('.') == nullptr || path.Find('.') != nullptr) {
33+
auto it = dirp->directories.find(token);
34+
35+
if (!(it != dirp->directories.end())) {
3336
return nullptr;
3437
}
3538

36-
dirp = &dirp->directories[token];
39+
dirp = &it->second;
3740
path.Next_Token(&token, "\\/");
3841
}
3942

4043
// Assuming we didn't run out of directories to try, find the file
4144
// in the reached directory.
4245
auto file_it = dirp->files.find(token);
4346

44-
if (file_it == dirp->files.end()) {
45-
return nullptr;
47+
if (file_it != dirp->files.end()) {
48+
return &file_it->second;
4649
}
4750

48-
return &file_it->second;
51+
return nullptr;
4952
}
5053

5154
void ArchiveFile::Add_File(Utf8String const &filepath, ArchivedFileInfo const *info)
5255
{
53-
// DEBUG_LOG("Adding '%s' to interal archive for '%s'.\n", filepath.Str(), info->archive_name.Str());
5456
Utf8String path = filepath;
5557
Utf8String token;
56-
DetailedArchiveDirectoryInfo *dirp = &m_archiveInfo;
57-
58-
// Lower case for matching and get first item of the path.
58+
DetailedArchivedDirectoryInfo *dirp = &m_archiveInfo;
5959
path.To_Lower();
60+
path.Next_Token(&token, "\\/");
6061

61-
for (path.Next_Token(&token, "\\/"); !token.Is_Empty(); path.Next_Token(&token, "\\/")) {
62-
// If an element of the path doesn't have a directory node, add it.
63-
// DEBUG_LOG("Searching for path element '%s'.\n", token.Str());
62+
while (token.Get_Length() > 0) {
6463
if (dirp->directories.find(token) == dirp->directories.end()) {
65-
// DEBUG_LOG("Adding path element '%s'.\n", token.Str());
64+
dirp->directories[token].Clear();
6665
dirp->directories[token].name = token;
6766
}
6867

6968
dirp = &dirp->directories[token];
69+
path.Next_Token(&token, "\\/");
7070
}
7171

7272
dirp->files[info->file_name] = *info;
7373
}
7474

7575
void ArchiveFile::Attach_File(File *file)
7676
{
77-
if (m_backingFile != nullptr) {
78-
m_backingFile->Close();
79-
m_backingFile = nullptr;
77+
if (m_attachedFile != nullptr) {
78+
m_attachedFile->Close();
79+
m_attachedFile = nullptr;
8080
}
8181

82-
m_backingFile = file;
82+
m_attachedFile = file;
8383
}
8484

85-
void ArchiveFile::Get_File_List_From_Dir(Utf8String const &subdir,
85+
void ArchiveFile::Get_File_List_In_Directory(Utf8String const &subdir,
8686
Utf8String const &dirpath,
8787
Utf8String const &filter,
8888
std::set<Utf8String, rts::less_than_nocase<Utf8String>> &filelist,
8989
bool search_subdir) const
9090
{
9191
Utf8String path = dirpath;
92+
path.To_Lower();
9293
Utf8String token;
93-
DetailedArchiveDirectoryInfo const *dirp = &m_archiveInfo;
94+
DetailedArchivedDirectoryInfo const *dirp = &m_archiveInfo;
95+
path.Next_Token(&token, "\\/");
9496

95-
// Lower case for matching and get first item of the path.
96-
path.To_Lower();
97+
while (token.Get_Length() > 0) {
98+
auto it = dirp->directories.find(token);
9799

98-
// Go to the last InfoNode in the path to extract file contents from.
99-
for (path.Next_Token(&token, "\\/"); token.Is_Not_Empty(); path.Next_Token(&token, "\\/")) {
100-
// If an element of the path doesn't have a node for our next directory, return.
101-
if (dirp->directories.find(token) == dirp->directories.end()) {
100+
if (!(it != dirp->directories.end())) {
102101
return;
103102
}
104103

105-
dirp = &dirp->directories[token];
104+
dirp = &it->second;
105+
path.Next_Token(&token, "\\/");
106106
}
107107

108-
Get_File_List_From_Dir(dirp, dirpath, filter, filelist, search_subdir);
108+
Get_File_List_In_Directory(dirp, dirpath, filter, filelist, search_subdir);
109109
}
110110

111-
void ArchiveFile::Get_File_List_From_Dir(DetailedArchiveDirectoryInfo const *dir_info,
111+
void ArchiveFile::Get_File_List_In_Directory(DetailedArchivedDirectoryInfo const *dir_info,
112112
Utf8String const &dirpath,
113113
Utf8String const &filter,
114114
std::set<Utf8String, rts::less_than_nocase<Utf8String>> &filelist,
115115
bool search_subdir) const
116116
{
117117
// Add the files from any subdirectories, recursive call.
118118
for (auto it = dir_info->directories.begin(); it != dir_info->directories.end(); ++it) {
119+
const DetailedArchivedDirectoryInfo *info = &it->second;
119120
Utf8String path = dirpath;
120121

121-
if (!path.Is_Empty() && !path.Ends_With("\\") && !path.Ends_With("/")) {
122-
path += "/";
122+
if (path.Get_Length() > 0 && !path.Ends_With("\\") && !path.Ends_With("/")) {
123+
path.Concat("/");
123124
}
124125

125-
path += it->second.name;
126-
Get_File_List_From_Dir(&(it->second), path, filter, filelist, search_subdir);
126+
path += info->name;
127+
Get_File_List_In_Directory(info, path, filter, filelist, search_subdir);
127128
}
128129

129130
// Add all the files that match the search pattern.
@@ -132,25 +133,30 @@ void ArchiveFile::Get_File_List_From_Dir(DetailedArchiveDirectoryInfo const *dir
132133
Utf8String path = dirpath;
133134

134135
if (!path.Is_Empty() && !path.Ends_With("\\") && !path.Ends_With("/")) {
135-
path += "/";
136+
path.Concat("/");
136137
}
137138

138139
path += it->second.file_name;
140+
139141
filelist.insert(path);
140142
}
141143
}
142144
}
143145

144146
// Helper funtion to check if a string matches the search string.
145-
bool ArchiveFile::Search_String_Matches(Utf8String string, Utf8String search)
147+
bool Search_String_Matches(Utf8String string, Utf8String search)
146148
{
147149
// Trivial case if first string is empty.
148-
if (string.Is_Empty()) {
149-
return search.Is_Empty();
150+
if (string.Get_Length() == 0) {
151+
if (search.Get_Length() == 0) {
152+
return true;
153+
}
154+
155+
return false;
150156
}
151157

152158
// If there is no seach string, there cannot be a match.
153-
if (search.Is_Empty()) {
159+
if (search.Get_Length() == 0) {
154160
return false;
155161
}
156162

@@ -195,5 +201,9 @@ bool ArchiveFile::Search_String_Matches(Utf8String string, Utf8String search)
195201
}
196202
}
197203

198-
return *csearch == '\0';
204+
if (*csearch == '\0') {
205+
return true;
206+
} else {
207+
return false;
208+
}
199209
}

0 commit comments

Comments
 (0)