Skip to content

Commit 339b126

Browse files
committed
Get rid of bogus YAML error
1 parent 0fb6adc commit 339b126

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

src/Engine/Options.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,21 @@ void setFolders()
463463
}
464464

465465
/**
466-
* Updates the game's options with those in the configuation
466+
* Updates the game's options with those in the configuration
467467
* file, if it exists yet, and any supplied on the command line.
468468
*/
469469
void updateOptions()
470470
{
471471
// Load existing options
472472
if (CrossPlatform::folderExists(_configFolder))
473473
{
474-
try
474+
if (CrossPlatform::fileExists(_configFolder + "options.cfg"))
475475
{
476476
load();
477477
}
478-
catch (YAML::Exception &e)
478+
else
479479
{
480-
Log(LOG_ERROR) << e.what();
480+
save();
481481
}
482482
}
483483
// Create config folder and save options
@@ -536,19 +536,26 @@ void save(const std::string &filename)
536536
Log(LOG_WARNING) << "Failed to save " << filename << ".cfg";
537537
return;
538538
}
539-
YAML::Emitter out;
539+
try
540+
{
541+
YAML::Emitter out;
540542

541-
YAML::Node doc, node;
542-
for (std::vector<OptionInfo>::iterator i = _info.begin(); i != _info.end(); ++i)
543+
YAML::Node doc, node;
544+
for (std::vector<OptionInfo>::iterator i = _info.begin(); i != _info.end(); ++i)
545+
{
546+
i->save(node);
547+
}
548+
doc["options"] = node;
549+
doc["purchaseexclusions"] = purchaseExclusions;
550+
doc["rulesets"] = rulesets;
551+
out << doc;
552+
553+
sav << out.c_str();
554+
}
555+
catch (YAML::Exception e)
543556
{
544-
i->save(node);
557+
Log(LOG_WARNING) << e.what();
545558
}
546-
doc["options"] = node;
547-
doc["purchaseexclusions"] = purchaseExclusions;
548-
doc["rulesets"] = rulesets;
549-
out << doc;
550-
551-
sav << out.c_str();
552559
sav.close();
553560
}
554561

0 commit comments

Comments
 (0)