Skip to content

Commit

Permalink
Use wxBufferedOutputStream with a large buffer when saving xml/xsq
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Dec 31, 2024
1 parent 7f6885b commit 0aca0b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
18 changes: 16 additions & 2 deletions xLights/TabSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <wx/clipbrd.h>
#include <wx/xml/xml.h>
#include <wx/config.h>
#include <wx/wfstream.h>

#include "xLightsMain.h"
#include "SeqSettingsDialog.h"
Expand Down Expand Up @@ -713,15 +714,28 @@ bool xLightsFrame::SaveEffectsFile(bool backup)
effectsFile.SetFullName(_(XLIGHTS_RGBEFFECTS_FILE));
}

if (!EffectsXml.Save(effectsFile.GetFullPath())) {
wxFileOutputStream fout(effectsFile.GetFullPath());
wxBufferedOutputStream *bout = new wxBufferedOutputStream(fout, 2 * 1024 * 1024);

if (!EffectsXml.Save(*bout)) {
if (backup) {
logger_base.warn("Unable to save backup of RGB effects file");
} else {
DisplayError("Unable to save RGB effects file", this);
}
delete bout;
return false;
}

delete bout;
if (!fout.Close()) {
if (backup) {
logger_base.warn("Unable to save backup of RGB effects file");
} else {
DisplayError("Unable to save RGB effects file", this);
}
return false;
}

if (!backup) {
#ifndef __WXOSX__
SaveModelsFile();
Expand Down
9 changes: 8 additions & 1 deletion xLights/outputs/OutputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wx/config.h>
#include <wx/filename.h>
#include <wx/dir.h>
#include <wx/wfstream.h>

#include "IPOutput.h"
#include "OutputManager.h"
Expand Down Expand Up @@ -429,9 +430,15 @@ bool OutputManager::Save() {
root->AddChild(it->Save());
}

if (doc.Save(_filename)) {
wxFileOutputStream fout(_filename);
wxBufferedOutputStream *bout = new wxBufferedOutputStream(fout, 2 * 1024 * 1024);
if (doc.Save(*bout)) {
_dirty = false;
}
delete bout;
if (!fout.Close()) {
_dirty = true;
}

return (_dirty == false);
}
Expand Down
10 changes: 9 additions & 1 deletion xLights/xLightsXmlFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2861,9 +2861,17 @@ bool xLightsXmlFile::Save(SequenceElements& seq_elements)
}
#endif

if (!seqDocument.Save(GetFullPath())) {
wxFileOutputStream fout(GetFullPath());
wxBufferedOutputStream *bout = new wxBufferedOutputStream(fout, 2 * 1024 * 1024);
if (!seqDocument.Save(*bout)) {
delete bout;
return false;
}
delete bout;
if (!fout.Close()) {
return false;
}

MarkNewFileRevision(GetFullPath());
return true;
}
Expand Down

0 comments on commit 0aca0b7

Please sign in to comment.