11#include " Configuration.h"
22#include " Color.h"
33#include " CommonFunctions.h"
4+ #include " CommonRegexes.h"
45#include " Log.h"
56#include " OSCompatibilityLayer.h"
67#include " ParserHelpers.h"
7- #include " CommonRegexes.h"
88
99
1010
1111auto laFabricaDeColor = commonItems::Color::Factory{};
1212
1313
14- Configuration::Configuration () {
14+ Configuration::Configuration (const commonItems::ConverterVersion& converterVersion ) {
1515 LOG (LogLevel::Info) << " Reading configuration file" ;
1616 registerKeys ();
1717 parseFile (" configuration.txt" );
1818 clearRegisteredKeywords ();
1919 setOutputName ();
2020 verifyImperatorPath ();
21+ verifyImperatorVersion (converterVersion);
2122 verifyCK3Path ();
23+ verifyCK3Version (converterVersion);
2224}
2325
2426
@@ -35,18 +37,10 @@ void Configuration::registerKeys() {
3537 SaveGamePath = commonItems::getString (theStream);
3638 Log (LogLevel::Info) << " Save Game set to: " << SaveGamePath;
3739 });
38- registerKeyword (" ImperatorDirectory" , [this ](std::istream& theStream) {
39- ImperatorPath = commonItems::getString (theStream);
40- });
41- registerKeyword (" ImperatorModsDirectory" , [this ](std::istream& theStream) {
42- ImperatorModsPath = commonItems::getString (theStream);
43- });
44- registerKeyword (" CK3directory" , [this ](std::istream& theStream) {
45- CK3Path = commonItems::getString (theStream);
46- });
47- registerKeyword (" CK3ModsDirectory" , [this ](std::istream& theStream) {
48- CK3ModsPath = commonItems::getString (theStream);
49- });
40+ registerKeyword (" ImperatorDirectory" , [this ](std::istream& theStream) { ImperatorPath = commonItems::getString (theStream); });
41+ registerKeyword (" ImperatorModsDirectory" , [this ](std::istream& theStream) { ImperatorModsPath = commonItems::getString (theStream); });
42+ registerKeyword (" CK3directory" , [this ](std::istream& theStream) { CK3Path = commonItems::getString (theStream); });
43+ registerKeyword (" CK3ModsDirectory" , [this ](std::istream& theStream) { CK3ModsPath = commonItems::getString (theStream); });
5044 registerKeyword (" output_name" , [this ](std::istream& theStream) {
5145 outputModName = commonItems::getString (theStream);
5246 Log (LogLevel::Info) << " Output name set to: " << outputModName;
@@ -56,8 +50,7 @@ void Configuration::registerKeys() {
5650 try {
5751 imperatorDeJure = static_cast <IMPERATOR_DE_JURE>(stoi (deJureString));
5852 Log (LogLevel::Info) << " ImperatorDeJure set to: " << deJureString;
59- }
60- catch (const std::exception& e) {
53+ } catch (const std::exception& e) {
6154 Log (LogLevel::Error) << " Undefined error, ImperatorDeJure value was: " << deJureString << " ; Error message: " << e.what ();
6255 }
6356 });
@@ -91,9 +84,8 @@ void Configuration::verifyCK3Path() const {
9184}
9285
9386
94- void Configuration::setOutputName ()
95- {
96- if (outputModName.empty ()) {
87+ void Configuration::setOutputName () {
88+ if (outputModName.empty ()) {
9789 outputModName = trimPath (SaveGamePath);
9890 }
9991 outputModName = trimExtension (outputModName);
@@ -102,4 +94,46 @@ void Configuration::setOutputName()
10294
10395 outputModName = commonItems::normalizeUTF8Path (outputModName);
10496 LOG (LogLevel::Info) << " Using output name " << outputModName;
105- }
97+ }
98+
99+ void Configuration::verifyImperatorVersion (const commonItems::ConverterVersion& converterVersion) const {
100+ const auto ImpVersion = GameVersion::extractVersionFromLauncher (ImperatorPath + " /launcher/launcher-settings.json" );
101+ if (!ImpVersion) {
102+ Log (LogLevel::Error) << " Imperator version could not be determined, proceeding blind!" ;
103+ return ;
104+ }
105+
106+ Log (LogLevel::Info) << " Imperator version: " << ImpVersion->toShortString ();
107+
108+ if (converterVersion.getMinSource () > *ImpVersion) {
109+ Log (LogLevel::Error) << " Imperator version is v" << ImpVersion->toShortString () << " , converter requires minimum v"
110+ << converterVersion.getMinSource ().toShortString () << " !" ;
111+ throw std::runtime_error (" Converter vs Imperator installation mismatch!" );
112+ }
113+ if (!converterVersion.getMaxSource ().isLargerishThan (*ImpVersion)) {
114+ Log (LogLevel::Error) << " Imperator version is v" << ImpVersion->toShortString () << " , converter requires maximum v"
115+ << converterVersion.getMaxSource ().toShortString () << " !" ;
116+ throw std::runtime_error (" Converter vs Imperator installation mismatch!" );
117+ }
118+ }
119+
120+ void Configuration::verifyCK3Version (const commonItems::ConverterVersion& converterVersion) const {
121+ const auto CK3Version = GameVersion::extractVersionFromLauncher (CK3Path + " /launcher/launcher-settings.json" );
122+ if (!CK3Version) {
123+ Log (LogLevel::Error) << " CK3 version could not be determined, proceeding blind!" ;
124+ return ;
125+ }
126+
127+ Log (LogLevel::Info) << " CK3 version: " << CK3Version->toShortString ();
128+
129+ if (converterVersion.getMinTarget () > *CK3Version) {
130+ Log (LogLevel::Error) << " CK3 version is v" << CK3Version->toShortString () << " , converter requires minimum v"
131+ << converterVersion.getMinTarget ().toShortString () << " !" ;
132+ throw std::runtime_error (" Converter vs CK3 installation mismatch!" );
133+ }
134+ if (!converterVersion.getMaxTarget ().isLargerishThan (*CK3Version)) {
135+ Log (LogLevel::Error) << " CK3 version is v" << CK3Version->toShortString () << " , converter requires maximum v"
136+ << converterVersion.getMaxTarget ().toShortString () << " !" ;
137+ throw std::runtime_error (" Converter vs CK3 installation mismatch!" );
138+ }
139+ }
0 commit comments