1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 08:30:06 +02:00
audacity/src/AutoRecovery.h
Paul Licameli 2ba17c78d6 Don't destroy auto-save file written by different architecture...
... the error checking might not be complete, but it is sufficient for the
observed cases, where switching between 32 and 64 bit Mac builds causes
auto-recovery in one build to destroy the data saved by the other build.

Now instead, you will see an error message, recommending that you run the
same version of Audacity that produced the file.

Note that decoding of autosave files can also (less commonly) happen with
a command-line argument, and a message is written to standard out.  Give the
same message in that case.

Localization of this changed message unfortunately can't happen this late in
2.3.2 development.
2019-04-30 21:59:23 +01:00

123 lines
3.4 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
Audacity(R) is copyright (c) 1999-2010 Audacity Team.
License: GPL v2. See License.txt.
AutoRecovery.h
*******************************************************************/
#ifndef __AUDACITY_AUTORECOVERY__
#define __AUDACITY_AUTORECOVERY__
#include "xml/XMLTagHandler.h"
#include "xml/XMLWriter.h"
#include <wx/mstream.h> // member variables
#include <unordered_map>
class wxFFile;
class AudacityProject;
//
// Show auto recovery dialog if there are projects to recover. Should be
// called once at Audacity startup.
//
// This function possibly opens NEW project windows while it recovers all
// projects. If so, it will re-use *pproj, if != NULL and set it to NULL.
//
// Returns: True, if the start of Audacity should continue as normal
// False if Audacity should be quit immediately
//
// The didRecoverAnything param is strictly for a return value.
// Any value passed in is ignored.
//
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject** pproj,
bool *didRecoverAnything);
//
// XML Handler for a <recordingrecovery> tag
//
class RecordingRecoveryHandler final : public XMLTagHandler
{
public:
RecordingRecoveryHandler(AudacityProject* proj);
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
void HandleXMLEndTag(const wxChar *tag) override;
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
// This class only knows reading tags
private:
int FindTrack() const;
AudacityProject* mProject;
int mChannel;
int mNumChannels;
int mAutoSaveIdent;
};
///
/// AutoSaveFile
///
// Should be plain ASCII
#define AutoSaveIdent "<?xml autosave>"
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 AutoSaveFile final : public XMLWriter
{
public:
static wxString FailureMessage( const FilePath &filePath );
AutoSaveFile(size_t allocSize = 1024 * 1024);
virtual ~AutoSaveFile();
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 AutoSaveFile & value);
bool Write(wxFFile & file) const;
bool Append(wxFFile & file) const;
bool IsEmpty() const;
bool Decode(const FilePath & fileName);
private:
void WriteName(const wxString & name);
void CheckSpace(wxMemoryOutputStream & buf);
private:
wxMemoryOutputStream mBuffer;
wxMemoryOutputStream mDict;
NameMap mNames;
size_t mAllocSize;
};
#endif