1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

AUP3: Mostly rework of CopyTo()

It now uses VACUUM INTO instead of the SQLite backup API
in hopes that the copies will be smaller. And VACUUM INTO
is "supposed" to be faster, but time will tell.  It's easy
to put the backup API usage back in.

This also fixes a bit I missed with redoing the orphan block
handling that was reported by Paul.

And finally, it renames the AutoRecovery.cpp/.h files and AutoSaveFile
class to ProjectSerializer since the AutoSaveFile class is being
used for regular project documents now and it doesn't write to a
file anymore.

If anyone has a better idea for a name other than ProjectSerializer
feel free to change it.  I hate naming things.
This commit is contained in:
Leland Lucius
2020-07-10 00:50:52 -05:00
parent 7ad8849d32
commit 5b41115bd0
7 changed files with 164 additions and 182 deletions

85
src/ProjectSerializer.h Normal file
View File

@@ -0,0 +1,85 @@
/**********************************************************************
Audacity: A Digital Audio Editor
Audacity(R) is copyright (c) 1999-2010 Audacity Team.
License: GPL v2. See License.txt.
ProjectSerializer.h
*******************************************************************/
#ifndef __AUDACITY_PROJECTSERIALIZER__
#define __AUDACITY_PROJECTSERIALIZER__
#include "xml/XMLTagHandler.h"
#include <wx/mstream.h> // member variables
#include <set>
#include <unordered_map>
#include "audacity/Types.h"
// From SampleBlock.h
using SampleBlockID = long long;
// From ProjectFileiIO.h
using BlockIDs = std::set<SampleBlockID>;
///
/// ProjectSerializer
///
using NameMap = std::unordered_map<wxString, short>;
using IdMap = std::unordered_map<short, wxString>;
// This class's overrides do NOT throw AudacityException.
class AUDACITY_DLL_API ProjectSerializer final : public XMLWriter
{
public:
static TranslatableString FailureMessage( const FilePath &filePath );
ProjectSerializer(size_t allocSize = 1024 * 1024);
virtual ~ProjectSerializer();
void StartTag(const wxString & name) override;
void EndTag(const wxString & name) override;
void WriteAttr(const wxString & name, const wxString &value) override;
void WriteAttr(const wxString & name, const wxChar *value) override;
void WriteAttr(const wxString & name, int value) override;
void WriteAttr(const wxString & name, bool value) override;
void WriteAttr(const wxString & name, long value) override;
void WriteAttr(const wxString & name, long long value) override;
void WriteAttr(const wxString & name, size_t value) override;
void WriteAttr(const wxString & name, float value, int digits = -1) override;
void WriteAttr(const wxString & name, double value, int digits = -1) override;
void WriteData(const wxString & value) override;
void Write(const wxString & data) override;
// Non-override functions
void WriteSubTree(const ProjectSerializer & value);
const wxMemoryBuffer &GetDict() const;
const wxMemoryBuffer &GetData() const;
bool IsEmpty() const;
bool DictChanged() const;
// Returns empty string if decoding fails
static wxString Decode(const wxMemoryBuffer &buffer, BlockIDs &blockids);
private:
void WriteName(const wxString & name);
private:
wxMemoryBuffer mBuffer;
bool mDictChanged;
static NameMap mNames;
static wxMemoryBuffer mDict;
};
#endif