GUI: fix user presets loading for real

issue #2025
This commit is contained in:
tildearrow 2024-11-08 03:41:58 -05:00
parent 826d1730e0
commit 77374cf740

View file

@ -50,7 +50,7 @@ std::vector<FurnaceGUISysDef>* digDeep(std::vector<FurnaceGUISysDef>& entries, i
bool FurnaceGUI::loadUserPresets(bool redundancy, String path, bool append) { bool FurnaceGUI::loadUserPresets(bool redundancy, String path, bool append) {
if (path.empty()) path=e->getConfigPath()+PRESETS_FILE; if (path.empty()) path=e->getConfigPath()+PRESETS_FILE;
String line; String line, lineStr;
logD("opening user presets: %s",path); logD("opening user presets: %s",path);
FILE* f=NULL; FILE* f=NULL;
@ -145,19 +145,27 @@ bool FurnaceGUI::loadUserPresets(bool redundancy, String path, bool append) {
if (!append) userCategory->systems.clear(); if (!append) userCategory->systems.clear();
char nextLine[4096]; char nextLine[4096];
lineStr="";
while (!feof(f)) { while (!feof(f)) {
if (fgets(nextLine,4095,f)==NULL) { if (fgets(nextLine,4095,f)==NULL) {
break; break;
} }
lineStr+=nextLine;
if (!lineStr.empty() && !feof(f)) {
if (lineStr[lineStr.size()-1]!='\n') {
continue;
}
}
int indent=0; int indent=0;
bool readIndent=true; bool readIndent=true;
bool keyOrValue=false; bool keyOrValue=false;
String key=""; String key="";
String value=""; String value="";
for (char* i=nextLine; *i; i++) { for (char i: lineStr) {
if ((*i)=='\n') break; if (i=='\n') break;
if (readIndent) { if (readIndent) {
if ((*i)==' ') { if (i==' ') {
indent++; indent++;
} else { } else {
readIndent=false; readIndent=false;
@ -165,12 +173,12 @@ bool FurnaceGUI::loadUserPresets(bool redundancy, String path, bool append) {
} }
if (!readIndent) { if (!readIndent) {
if (keyOrValue) { if (keyOrValue) {
value+=*i; value+=i;
} else { } else {
if ((*i)=='=') { if (i=='=') {
keyOrValue=true; keyOrValue=true;
} else { } else {
key+=*i; key+=i;
} }
} }
} }
@ -181,6 +189,9 @@ bool FurnaceGUI::loadUserPresets(bool redundancy, String path, bool append) {
std::vector<FurnaceGUISysDef>* where=digDeep(userCategory->systems,indent); std::vector<FurnaceGUISysDef>* where=digDeep(userCategory->systems,indent);
where->push_back(FurnaceGUISysDef(key.c_str(),value.c_str(),e)); where->push_back(FurnaceGUISysDef(key.c_str(),value.c_str(),e));
} }
lineStr="";
lineStr.reserve(4096);
} }
fclose(f); fclose(f);