Skip to content

Commit fc8906d

Browse files
Add look up for generals.csf in for big archives
1 parent d270bee commit fc8906d

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/GUI/SetUpWindowsWrapper.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#include <QDir>
12
#include <QLineEdit>
2-
#include <QFile>
33
#include <QMessageBox>
44

5+
#include "../Parsers/CSFParser.hpp"
56
#include "../Windows/Registry.hpp"
67
#include "../Logger.hpp"
8+
#include "../Exception.hpp"
79
#include "WindowManager.hpp"
810
#include "ImageManager.hpp"
911
#include "LoadFromTheGameWindow.hpp"
@@ -122,18 +124,8 @@ void SetUpWindowsWrapper::BtnBack_Clicked() { WINDOW_MANAGER->SetCSFFile
122124

123125
void SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration()
124126
{
125-
// TODO: Make it load vanila Generals
126-
// Also as search in all big-archives (see more at GZH source code)
127127
const QString gamePath = QString::fromStdWString(Windows::Registry::GetPathToGame(Windows::Registry::Games::GeneralsZeroHour));
128128
const QString pathDataEngGenCsf = gamePath + "Data\\English\\generals.csf";
129-
const QString pathEngBig = gamePath + "\\EnglishZH.big";
130-
131-
if (!QFile::exists(pathDataEngGenCsf) && !QFile::exists(pathEngBig))
132-
{
133-
QMessageBox::critical(nullptr, L10N(PROGRAM_CONSTANTS->GMFILES_SRCH_ERR_HEADER),
134-
L10N(PROGRAM_CONSTANTS->BIG_NO_ENGLISH_ZH).arg(pathEngBig));
135-
return;
136-
}
137129

138130
if (QFile::exists(pathDataEngGenCsf))
139131
{
@@ -142,8 +134,31 @@ void SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration()
142134
else
143135
{
144136
LOGMSG("Unable to find " + pathDataEngGenCsf);
145-
LOGMSG("Loading " + pathEngBig + "...");
146-
WINDOW_MANAGER->SetCSFFilePath(pathEngBig);
137+
LOGMSG("Searching generals.csf in all archives");
138+
139+
QDir gameDir(gamePath);
140+
QFileInfoList fileList = gameDir.entryInfoList(QDir::Filter::Files
141+
| QDir::Filter::NoDotAndDotDot
142+
| QDir::Filter::Readable,
143+
QDir::SortFlag::Name);
144+
for(const QFileInfo& elem : fileList)
145+
{
146+
if (elem.suffix().toUpper() != "BIG")
147+
continue;
148+
149+
LOGMSG("Processing " + elem.absoluteFilePath() + "...");
150+
try
151+
{
152+
CSFParser parser(elem.absoluteFilePath());
153+
WINDOW_MANAGER->SetCSFFilePath(elem.absoluteFilePath());
154+
break;
155+
}
156+
catch(...)
157+
{
158+
LOGMSG("String table doesn't exist in archive");
159+
continue;
160+
}
161+
}
147162
}
148163

149164
WINDOW_MANAGER->StartUpWindow_AcceptConfiguration();

src/GUI/Translations/ru.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,22 @@
236236
<translation>Невозможно найти &quot;EnglishZH.big&quot; в папке &quot;%1&quot;.</translation>
237237
</message>
238238
<message>
239-
<location filename="../../ProgramConstants.hpp" line="113"/>
239+
<location filename="../../ProgramConstants.hpp" line="114"/>
240240
<source>Buildings</source>
241241
<translation>Здания</translation>
242242
</message>
243243
<message>
244-
<location filename="../../ProgramConstants.hpp" line="114"/>
244+
<location filename="../../ProgramConstants.hpp" line="115"/>
245245
<source>Infantry</source>
246246
<translation>Пехота</translation>
247247
</message>
248248
<message>
249-
<location filename="../../ProgramConstants.hpp" line="115"/>
249+
<location filename="../../ProgramConstants.hpp" line="116"/>
250250
<source>Vehicles</source>
251251
<translation>Техника</translation>
252252
</message>
253253
<message>
254-
<location filename="../../ProgramConstants.hpp" line="116"/>
254+
<location filename="../../ProgramConstants.hpp" line="117"/>
255255
<source>Aircrafts</source>
256256
<translation>Авиация</translation>
257257
</message>

src/ProgramConstants.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ class ProgramConstants
8282
const QString CSF_NO_OBJECT_ERROR = QObject::tr("Choosen CSF file doesn't have OBJECT category. Make sure that you are load correct file.");
8383
const QString CSF_EMPTY_DATA_ENGLISH = QObject::tr("Unable to find \"generals.csf\" file in \"%1\" folder.");
8484
const QString CSF_NO_CSF_IN_BIG = QObject::tr("Unable to find CSF file inside BIG archive \"%1\"");
85-
const QString GMFILES_SRCH_ERR_HEADER = QObject::tr("Game files search error");
86-
const QString BIG_NO_ENGLISH_ZH = QObject::tr("Unable to find \"EnglishZH.big\" archive in \"%1\" folder.");
8785

8886
// Other string constants
8987
const QString HOTKEY_CSF_CATEGORY = "CONTROLBAR";
9088
const QString OBJECT_CSF_CATEGORY = "OBJECT";
89+
const QString BIG_ARCHIVE_CSF_PATH = "Data\\English\\generals.csf";
9190

9291
// Constant containers
9392
const QVector<QString> GLA_SHORT_NAMES = {"GLA", "TOX", "STL", "DML"};

0 commit comments

Comments
 (0)