Browse Source

Add default argument to settings::save() and load().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
4450bd7ef1
4 changed files with 13 additions and 7 deletions
  1. +2
    -2
      include/settings.hpp
  2. +1
    -1
      src/app/Scene.cpp
  3. +8
    -2
      src/settings.cpp
  4. +2
    -2
      standalone/main.cpp

+ 2
- 2
include/settings.hpp View File

@@ -93,8 +93,8 @@ ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& mo
void init();
json_t* toJson();
void fromJson(json_t* rootJ);
void save(const std::string& path);
void load(const std::string& path);
void save(std::string path = "");
void load(std::string path = "");


} // namespace settings


+ 1
- 1
src/app/Scene.cpp View File

@@ -83,7 +83,7 @@ void Scene::step() {
if (time - lastAutosaveTime >= settings::autosaveInterval) {
lastAutosaveTime = time;
APP->patch->saveAutosave();
settings::save(settings::settingsPath);
settings::save();
}
}



+ 8
- 2
src/settings.cpp View File

@@ -351,7 +351,10 @@ void fromJson(json_t* rootJ) {
}
}

void save(const std::string& path) {
void save(std::string path) {
if (path.empty())
path = settingsPath;

INFO("Saving settings %s", path.c_str());
json_t* rootJ = toJson();
if (!rootJ)
@@ -367,7 +370,10 @@ void save(const std::string& path) {
json_decref(rootJ);
}

void load(const std::string& path) {
void load(std::string path) {
if (path.empty())
path = settingsPath;

INFO("Loading settings %s", path.c_str());
FILE* file = std::fopen(path.c_str(), "r");
if (!file)


+ 2
- 2
standalone/main.cpp View File

@@ -146,7 +146,7 @@ int main(int argc, char* argv[]) {
// Load settings
settings::init();
try {
settings::load(settings::settingsPath);
settings::load();
}
catch (Exception& e) {
std::string msg = e.what();
@@ -241,7 +241,7 @@ int main(int argc, char* argv[]) {
delete APP;
contextSet(NULL);
if (!settings::headless) {
settings::save(settings::settingsPath);
settings::save();
}

// Destroy environment


Loading…
Cancel
Save