Browse Source

Add securityAccepted to global settings file.

tags/v1.3.0
Andrew Belt 5 years ago
parent
commit
3c9f22c359
1 changed files with 47 additions and 0 deletions
  1. +47
    -0
      src/Prototype.cpp

+ 47
- 0
src/Prototype.cpp View File

@@ -17,6 +17,50 @@ Plugin* pluginInstance;
bool securityRequested = false;
bool securityAccepted = false;

json_t *settingsToJson() {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "securityAccepted", json_boolean(securityAccepted));
return rootJ;
}

void settingsFromJson(json_t *rootJ) {
json_t *securityAcceptedJ = json_object_get(rootJ, "securityAccepted");
if (securityAcceptedJ)
securityAccepted = json_boolean_value(securityAcceptedJ);
}

void settingsLoad() {
// Load plugin settings
std::string filename = asset::user("VCV-Prototype.json");
FILE *file = fopen(filename.c_str(), "r");
if (!file) {
return;
}
DEFER({
fclose(file);
});

json_error_t error;
json_t *rootJ = json_loadf(file, 0, &error);
if (rootJ) {
settingsFromJson(rootJ);
json_decref(rootJ);
}
}

void settingsSave() {
json_t *rootJ = settingsToJson();

std::string filename = asset::user("VCV-Prototype.json");
FILE *file = fopen(filename.c_str(), "w");
if (file) {
json_dumpf(rootJ, file, JSON_INDENT(2) | JSON_REAL_PRECISION(9));
fclose(file);
}

json_decref(rootJ);
}


struct Prototype : Module {
enum ParamIds {
@@ -510,6 +554,7 @@ struct PrototypeWidget : ModuleWidget {
if (securityRequested) {
if (osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "VCV Prototype is about to load a script from a patch or module preset. Running Prototype scripts from untrusted sources may compromise your computer and personal information. Proceed and don't display this message again?")) {
securityAccepted = true;
settingsSave();
}
securityRequested = false;
}
@@ -521,4 +566,6 @@ void init(Plugin* p) {
pluginInstance = p;

p->addModel(createModel<Prototype, PrototypeWidget>("Prototype"));

settingsLoad();
}

Loading…
Cancel
Save