Skip to content

Commit

Permalink
Added support of saving not compressed ini files GrandOrgue#1199 (Gra…
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 authored Feb 23, 2025
1 parent 4779a50 commit e3ddb91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
29 changes: 16 additions & 13 deletions src/core/config/GOConfigFileWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand All @@ -23,7 +23,8 @@ void GOConfigFileWriter::AddEntry(
g[name] = value;
}

bool GOConfigFileWriter::GetFileContent(GOBuffer<uint8_t> &buf) {
bool GOConfigFileWriter::GetFileContent(
GOBuffer<uint8_t> &buf, bool isToCompress) {
uint8_t bom[] = {0xEF, 0xBB, 0xBF};
wxString content = wxEmptyString;

Expand All @@ -49,24 +50,26 @@ bool GOConfigFileWriter::GetFileContent(GOBuffer<uint8_t> &buf) {
buf.Append(bom, sizeof(bom));
buf.Append((const uint8_t *)b.data(), b.length());

if (!compressBuffer(buf))
if (isToCompress && !compressBuffer(buf))
return false;

return true;
}

bool GOConfigFileWriter::Save(wxString filename) {
bool GOConfigFileWriter::Save(const wxString &fileName, bool isToCompress) {
wxFile out;
GOBuffer<uint8_t> buf;
if (!GetFileContent(buf))
return false;

if (!out.Create(filename, true))
return false;
bool isOk = GetFileContent(buf, isToCompress);

if (!out.Write(buf.get(), buf.GetSize()))
return false;
out.Flush();
out.Close();
return true;
if (isOk)
isOk = out.Create(fileName, true);

if (isOk)
isOk = out.Write(buf.get(), buf.GetSize());
if (isOk)
isOk = out.Flush();
if (isOk)
isOk = out.Close();
return isOk;
}
6 changes: 3 additions & 3 deletions src/core/config/GOConfigFileWriter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand All @@ -23,8 +23,8 @@ class GOConfigFileWriter {
GOConfigFileWriter();

void AddEntry(wxString group, wxString name, wxString value);
bool GetFileContent(GOBuffer<uint8_t> &buffer);
bool Save(wxString filename);
bool GetFileContent(GOBuffer<uint8_t> &buffer, bool isToCompress = true);
bool Save(const wxString &fileName, bool isToCompress = true);
};

#endif

0 comments on commit e3ddb91

Please sign in to comment.