Browse Source

Save temporary patch file and rename it over desired patch.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
e92b9d0339
2 changed files with 6 additions and 5 deletions
  1. +1
    -1
      src/app/RackScrollWidget.cpp
  2. +5
    -4
      src/patch.cpp

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

@@ -43,7 +43,7 @@ void RackScrollWidget::step() {
math::Rect scrollBox = moduleBox; math::Rect scrollBox = moduleBox;
scrollBox.pos = scrollBox.pos.mult(zoom); scrollBox.pos = scrollBox.pos.mult(zoom);
scrollBox.size = scrollBox.size.mult(zoom); scrollBox.size = scrollBox.size.mult(zoom);
scrollBox = scrollBox.grow(box.size.div(2));
scrollBox = scrollBox.grow(box.size.mult(0.6666));


// Expand to the current viewport box so that moving modules (and thus changing the module bounding box) doesn't clamp the scroll offset. // Expand to the current viewport box so that moving modules (and thus changing the module bounding box) doesn't clamp the scroll offset.
math::Rect viewportBox; math::Rect viewportBox;


+ 5
- 4
src/patch.cpp View File

@@ -81,16 +81,17 @@ void PatchManager::save(std::string path) {
json_decref(rootJ); json_decref(rootJ);
}); });


FILE *file = std::fopen(path.c_str(), "w");
// Write to temporary path and then rename it to the correct path
std::string tmpPath = path + ".tmp";
FILE *file = std::fopen(tmpPath.c_str(), "w");
if (!file) { if (!file) {
// Fail silently // Fail silently
return; return;
} }
DEFER({
std::fclose(file);
});


json_dumpf(rootJ, file, JSON_INDENT(2) | JSON_REAL_PRECISION(9)); json_dumpf(rootJ, file, JSON_INDENT(2) | JSON_REAL_PRECISION(9));
std::fclose(file);
std::rename(tmpPath.c_str(), path.c_str());
} }


void PatchManager::saveDialog() { void PatchManager::saveDialog() {


Loading…
Cancel
Save