74 lines
1.8 KiB
C++
74 lines
1.8 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 scenery;
|
|
std::string token;
|
|
|
|
inline void writeFile() const
|
|
{
|
|
std::ofstream out(BASE_DIRECTORY CONFIG);
|
|
out << "scenery=" << this->scenery << "\n";
|
|
out << "user=" << this->user << "\n";
|
|
out << "token=" << this->token << "\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 = util::split(line, '=');
|
|
if (fields.size() >= 2) {
|
|
util::trim(fields[0]);
|
|
util::trim(fields[1]);
|
|
if (fields[0] == "scenery") {
|
|
this->scenery = fields[1];
|
|
} else if (fields[0] == "user") {
|
|
this->user = fields[1];
|
|
} else if (fields[0] == "token") {
|
|
this->token = fields[1];
|
|
}
|
|
}
|
|
}
|
|
in.close();
|
|
}
|
|
|
|
inline void updateScenery(std::string scenery)
|
|
{
|
|
this->scenery = scenery;
|
|
|
|
this->writeFile();
|
|
}
|
|
|
|
inline const std::string getUser() const { return this->user; }
|
|
inline const std::string getScenery() const { return this->scenery; }
|
|
inline const std::string getToken() const { return this->token; }
|
|
};
|
|
} // namespace config
|
|
} // namespace file
|
|
} // namespace germanairlinesva
|
|
|
|
#endif
|