mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-01 08:29:27 +02:00
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.
This commit is contained in:
parent
c8d95e1117
commit
2ba17c78d6
@ -1520,7 +1520,7 @@ bool AudacityApp::OnInit()
|
||||
}
|
||||
else
|
||||
{
|
||||
wxPrintf(_("Decoding failed\n"));
|
||||
wxPrintf( AutoSaveFile::FailureMessage( fileName ) );
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -484,6 +484,16 @@ enum FieldTypes
|
||||
FT_Name // type, ID, name length, name
|
||||
};
|
||||
|
||||
wxString AutoSaveFile::FailureMessage( const FilePath &filePath )
|
||||
{
|
||||
return wxString::Format(
|
||||
_("Could not decode crash recovery file: %s\n\n\
|
||||
This file was saved by a version of Audacity built for a different processor architecture. \
|
||||
Try running that version of Audacity to recover its contents."),
|
||||
filePath
|
||||
);
|
||||
}
|
||||
|
||||
AutoSaveFile::AutoSaveFile(size_t allocSize)
|
||||
{
|
||||
mAllocSize = allocSize;
|
||||
@ -767,8 +777,15 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
|
||||
mIds.clear();
|
||||
|
||||
while ( !in.Eof() )
|
||||
{
|
||||
struct Error{};
|
||||
auto Lookup = [&mIds]( short id ) -> const wxString & {
|
||||
auto iter = mIds.find( id );
|
||||
if ( iter == mIds.end() )
|
||||
throw Error{};
|
||||
return iter->second;
|
||||
};
|
||||
|
||||
try { while ( !in.Eof() ) {
|
||||
short id;
|
||||
|
||||
switch (in.GetC())
|
||||
@ -804,7 +821,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
{
|
||||
in.Read(&id, sizeof(id));
|
||||
|
||||
out.StartTag(mIds[id]);
|
||||
out.StartTag(Lookup(id));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -812,7 +829,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
{
|
||||
in.Read(&id, sizeof(id));
|
||||
|
||||
out.EndTag(mIds[id]);
|
||||
out.EndTag(Lookup(id));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -825,7 +842,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
WxChars val{ len / sizeof(wxChar) };
|
||||
in.Read(val.get(), len);
|
||||
|
||||
out.WriteAttr(mIds[id], wxString(val.get(), len / sizeof(wxChar)));
|
||||
out.WriteAttr(Lookup(id), wxString(val.get(), len / sizeof(wxChar)));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -838,7 +855,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&val, sizeof(val));
|
||||
in.Read(&dig, sizeof(dig));
|
||||
|
||||
out.WriteAttr(mIds[id], val, dig);
|
||||
out.WriteAttr(Lookup(id), val, dig);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -851,7 +868,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&val, sizeof(val));
|
||||
in.Read(&dig, sizeof(dig));
|
||||
|
||||
out.WriteAttr(mIds[id], val, dig);
|
||||
out.WriteAttr(Lookup(id), val, dig);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -862,7 +879,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&val, sizeof(val));
|
||||
|
||||
out.WriteAttr(mIds[id], val);
|
||||
out.WriteAttr(Lookup(id), val);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -873,7 +890,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&val, sizeof(val));
|
||||
|
||||
out.WriteAttr(mIds[id], val);
|
||||
out.WriteAttr(Lookup(id), val);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -884,7 +901,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&val, sizeof(val));
|
||||
|
||||
out.WriteAttr(mIds[id], val);
|
||||
out.WriteAttr(Lookup(id), val);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -895,7 +912,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&val, sizeof(val));
|
||||
|
||||
out.WriteAttr(mIds[id], val);
|
||||
out.WriteAttr(Lookup(id), val);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -906,7 +923,7 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&val, sizeof(val));
|
||||
|
||||
out.WriteAttr(mIds[id], val);
|
||||
out.WriteAttr(Lookup(id), val);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -938,6 +955,11 @@ bool AutoSaveFile::Decode(const FilePath & fileName)
|
||||
wxASSERT(true);
|
||||
break;
|
||||
}
|
||||
} }
|
||||
catch( const Error & )
|
||||
{
|
||||
// return before committing, so we do not overwrite the recovery file!
|
||||
return false;
|
||||
}
|
||||
|
||||
out.Commit();
|
||||
|
@ -75,6 +75,8 @@ class AUDACITY_DLL_API AutoSaveFile final : public XMLWriter
|
||||
{
|
||||
public:
|
||||
|
||||
static wxString FailureMessage( const FilePath &filePath );
|
||||
|
||||
AutoSaveFile(size_t allocSize = 1024 * 1024);
|
||||
virtual ~AutoSaveFile();
|
||||
|
||||
|
@ -3070,10 +3070,13 @@ void AudacityProject::OpenFile(const FilePath &fileNameArg, bool addtohistory)
|
||||
AutoSaveFile asf;
|
||||
if (!asf.Decode(fileName))
|
||||
{
|
||||
auto message = AutoSaveFile::FailureMessage( fileName );
|
||||
AudacityMessageBox(
|
||||
wxString::Format( _("Could not decode file: %s"), fileName ),
|
||||
message,
|
||||
_("Error decoding file"),
|
||||
wxOK | wxCENTRE, this);
|
||||
// Important: Prevent deleting any temporary files!
|
||||
DirManager::SetDontDeleteTempFiles();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user