Skip to content

Commit

Permalink
params: parse_preset_config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesmann authored and flightlessmango committed Sep 23, 2023
1 parent 41e4859 commit 6342056
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/overlay_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <cctype>
#include <array>
Expand Down Expand Up @@ -962,38 +963,39 @@ bool parse_preset_config(int preset, struct overlay_params *params){
const std::string data_dir = get_data_dir();
const std::string config_dir = get_config_dir();
std::string preset_path = config_dir + "/MangoHud/" + "presets.conf";
FILE *preset_file = fopen(preset_path.c_str(), "r");
char line[20];

char preset_string[20];
snprintf(preset_string, sizeof(preset_string), "[preset %d]\n", preset);
bool found_preset = false;
snprintf(preset_string, sizeof(preset_string), "[preset %d]", preset);

if (preset_file == NULL)
std::ifstream stream(preset_path);
stream.imbue(std::locale::classic());

if (!stream.good()) {
return false;
}

while (fgets(line, sizeof(line), preset_file)){
if (strcmp(line, preset_string) == 0){
std::string line;
bool found_preset = false;

while (std::getline(stream, line)) {
trim(line);

if (line == preset_string) {
found_preset = true;
continue;
}

if (found_preset){
if(strcmp(line, "preset") == 0 || line[0] == '\n' || line[0] == '\0')
if (found_preset) {
if (line.front() == '[' && line.back() == ']')
break;

printf("line: %s\n", line);
std::string s;
s = line;
trim(s);

if (strcmp(s.c_str(), "inherit") == 0)
if (line == "inherit")
presets(preset, params, true);

parseConfigLine(line, params->options);
}
}

fclose(preset_file);
return found_preset;
}

Expand Down

0 comments on commit 6342056

Please sign in to comment.