Files
spice2x.github.io/src/spice2x/cfg/config.h
T
drmext b558df3340 cfg: optimize saving config (#714)
## Link to GitHub Issue or related Pull Request, if one exists
#0

## Description of change
Save config xml once instead of ~33 times

## Testing
xml is still saved properly
2026-05-29 09:09:02 -07:00

68 lines
1.8 KiB
C++

#pragma once
#include <filesystem>
#include <fstream>
#include <iostream>
#include "external/tinyxml2/tinyxml2.h"
#include "game.h"
// settings
extern std::string CONFIG_PATH_OVERRIDE;
struct ConfigKeypadBindings {
std::string keypads[2];
std::filesystem::path card_paths[2];
};
class Config {
public:
static Config &getInstance();
bool getStatus();
bool createConfigFile();
bool addGame(Game &game, bool save = true);
// flush pending in-memory changes to disk; intended to be paired with
// addGame(game, false) in bulk-init paths so we write the XML once instead
// of once per game
void save();
bool updateBinding(const Game &game, const Button &button, int alternative);
bool updateBinding(const Game &game, const Analog &analog);
bool updateBinding(const Game &game, ConfigKeypadBindings &keypads);
bool updateBinding(const Game &game, const Light &light, int alternative);
bool updateBinding(const Game &game, const Option &option);
std::vector<Button> getButtons(const std::string &game);
std::vector<Button> getButtons(Game *);
std::vector<Analog> getAnalogs(const std::string &game);
std::vector<Analog> getAnalogs(Game *);
ConfigKeypadBindings getKeypadBindings(const std::string &game);
ConfigKeypadBindings getKeypadBindings(Game *);
std::vector<Light> getLights(const std::string &game);
std::vector<Light> getLights(Game *);
std::vector<Option> getOptions(const std::string &game);
std::vector<Option> getOptions(Game *);
private:
Config();
Config(const Config &);
~Config() = default;
const Config &operator=(const Config &);
tinyxml2::XMLDocument configFile;
bool status;
std::filesystem::path configLocation;
std::filesystem::path configLocationTemp;
bool firstFillConfigFile();
void saveConfigFile();
};