184 lines
5.9 KiB
C++

#ifndef GERMANAIRLINESVA_FILE_CONFIG_CONFIG_H
#define GERMANAIRLINESVA_FILE_CONFIG_CONFIG_H
#include <map>
#include <fstream>
#include <map>
#include <string>
#include <vector>
#include "constants.h"
#include "util.hpp"
namespace germanairlinesva
{
namespace file
{
namespace config
{
class Config
{
private:
std::string user;
std::string XP11Scenery;
std::string XP12Scenery;
std::string FSXScenery;
std::string FSXSEScenery;
std::string P3D3Scenery;
std::string P3D4Scenery;
std::string P3D5Scenery;
std::string token;
std::string FSXPath;
std::string FSXSEPath;
std::string P3D3Path;
std::string P3D4Path;
std::string P3D5Path;
std::string MSFSPath;
inline void writeFile() const
{
std::ofstream out(BASE_DIRECTORY CONFIG);
out << "xp11Scenery=" << this->XP11Scenery << "\n";
out << "xp12Scenery=" << this->XP12Scenery << "\n";
out << "fsxScenery=" << this->FSXScenery << "\n";
out << "fsxSEScenery=" << this->FSXSEScenery << "\n";
out << "p3d3Scenery=" << this->P3D3Scenery << "\n";
out << "p3d4Scenery=" << this->P3D4Scenery << "\n";
out << "p3d5Scenery=" << this->P3D5Scenery << "\n";
out << "user=" << this->user << "\n";
out << "token=" << this->token << "\n";
out << "fsxPath=" << this->FSXPath << "\n";
out << "fsxSEPath=" << this->FSXSEPath << "\n";
out << "p3d3Path=" << this->P3D3Path << "\n";
out << "p3d4Path=" << this->P3D4Path << "\n";
out << "p3d5Path=" << this->P3D5Path << "\n";
out << "msfsPath=" << this->MSFSPath << "\n";
out.close();
}
public:
inline Config()
{
std::ifstream in(BASE_DIRECTORY CONFIG);
std::string line;
while (std::getline(in, line)) {
std::vector<std::string> fields = utilities::split(line, '=');
if (fields.size() >= 2) {
utilities::trim(fields[0]);
utilities::trim(fields[1]);
if (fields[0] == "xp11Scenery") {
this->XP11Scenery = fields[1];
} else if (fields[0] == "xp12Scenery") {
this->XP12Scenery = fields[1];
} else if (fields[0] == "fsxScenery") {
this->FSXScenery = fields[1];
} else if (fields[0] == "fsxSEScenery") {
this->FSXSEScenery = fields[1];
} else if (fields[0] == "p3d3Scenery") {
this->P3D3Scenery = fields[1];
} else if (fields[0] == "p3d4Scenery") {
this->P3D4Scenery = fields[1];
} else if (fields[0] == "p3d5Scenery") {
this->P3D5Scenery = fields[1];
} else if (fields[0] == "user") {
this->user = fields[1];
} else if (fields[0] == "token") {
this->token = fields[1];
} else if (fields[0] == "fsxPath") {
this->FSXPath = fields[1];
} else if (fields[0] == "fsxSEPath") {
this->FSXSEPath = fields[1];
} else if (fields[0] == "p3d3Path") {
this->P3D3Path = fields[1];
} else if (fields[0] == "p3d4Paht") {
this->P3D4Path = fields[1];
} else if (fields[0] == "p3d5Path") {
this->P3D5Path = fields[1];
} else if (fields[0] == "msfsPath") {
this->MSFSPath = fields[1];
}
}
}
in.close();
}
inline void updateScenery(int simVersion, std::string scenery)
{
switch (simVersion) {
case FSX_VERSION:
this->FSXScenery = scenery;
break;
case FSXSE_VERSION:
this->FSXSEScenery = scenery;
break;
case P3D3_VERSION:
this->P3D3Scenery = scenery;
break;
case P3D4_VERSION:
this->P3D4Scenery = scenery;
break;
case P3D5_VERSION:
this->P3D5Scenery = scenery;
break;
default:
if (simVersion < 12000) {
this->XP11Scenery = scenery;
} else {
this->XP12Scenery = scenery;
}
break;
}
this->writeFile();
}
inline const std::string getUser() const { return this->user; }
inline const std::string getScenery(int simVersion) const
{
switch (simVersion) {
case FSX_VERSION:
return this->FSXScenery;
case FSXSE_VERSION:
return this->FSXSEScenery;
case P3D3_VERSION:
return this->P3D3Scenery;
case P3D4_VERSION:
return this->P3D4Scenery;
case P3D5_VERSION:
return this->P3D5Scenery;
default:
if (simVersion < 12000) {
return this->XP11Scenery;
} else {
return this->XP12Scenery;
}
}
}
inline const std::string getToken() const { return this->token; }
inline const std::string getPath(int simVersion) const
{
switch (simVersion) {
case FSX_VERSION:
return this->FSXPath;
case FSXSE_VERSION:
return this->FSXSEPath;
case P3D3_VERSION:
return this->P3D3Path;
case P3D4_VERSION:
return this->P3D4Path;
case P3D5_VERSION:
return this->P3D5Path;
case MSFS_VERSION:
return this->MSFSPath;
default:
return "/";
}
}
};
} // namespace config
} // namespace file
} // namespace germanairlinesva
#endif