From 3c9f22c359e5d284af4560330db7296e7fe44ee3 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 21 Oct 2019 07:16:19 -0400 Subject: [PATCH] Add securityAccepted to global settings file. --- src/Prototype.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Prototype.cpp b/src/Prototype.cpp index 8d3608c..c496437 100644 --- a/src/Prototype.cpp +++ b/src/Prototype.cpp @@ -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")); + + settingsLoad(); }