From 357b0128d838ade76d1d100174116ba9109226f6 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 12 Dec 2017 10:12:20 -0500 Subject: [PATCH] Don't write empty file if toJson is unsuccessful --- src/app/RackWidget.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index a8003e93..d01cf012 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -102,20 +102,19 @@ void RackWidget::saveAsDialog() { } } - void RackWidget::savePatch(std::string path) { info("Saving patch %s", path.c_str()); - FILE *file = fopen(path.c_str(), "w"); - if (!file) + json_t *rootJ = toJson(); + if (!rootJ) return; - json_t *rootJ = toJson(); - if (rootJ) { + FILE *file = fopen(path.c_str(), "w"); + if (file) { json_dumpf(rootJ, file, JSON_INDENT(2)); - json_decref(rootJ); + fclose(file); } - fclose(file); + json_decref(rootJ); } void RackWidget::loadPatch(std::string path) {