mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
Allow recovery of 2.1.0 or earlier autosave files
This commit is contained in:
parent
5d415e69d5
commit
0c0650588a
@ -637,8 +637,41 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
|
||||
if (file.Read(&ident, len) != len || strncmp(ident, AutoSaveIdent, len) != 0)
|
||||
{
|
||||
// Not something we recognize. Could be decoded already. Let the caller
|
||||
// deal with it.
|
||||
// It could be that the file has already been decoded or that it is one
|
||||
// from 2.1.0 or earlier. In the latter case, we need to ensure the
|
||||
// closing </project> tag is preset.
|
||||
|
||||
// Close the file so we can reopen it in read/write mode
|
||||
file.Close();
|
||||
|
||||
// Add </project> tag, if necessary
|
||||
if (!file.Open(fn.GetFullPath(), wxT("r+")))
|
||||
{
|
||||
// Really shouldn't happen, but let the caller deal with it
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the last 16 bytes of the file and check if they contain
|
||||
// "</project>" somewhere.
|
||||
const int bufsize = 16;
|
||||
char buf[bufsize + 1];
|
||||
if (file.SeekEnd(-bufsize) != wxInvalidOffset)
|
||||
{
|
||||
if (file.Read(buf, bufsize) == bufsize)
|
||||
{
|
||||
buf[bufsize] = 0;
|
||||
if (strstr(buf, "</project>") == 0)
|
||||
{
|
||||
// End of file does not contain closing </project> tag, so add it
|
||||
if (file.Seek(0, wxFromEnd) != wxInvalidOffset)
|
||||
{
|
||||
strcpy(buf, "</project>\n");
|
||||
file.Write(buf, strlen(buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.Close();
|
||||
|
||||
return true;
|
||||
@ -650,7 +683,6 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
if (file.Read(buf, len) != len)
|
||||
{
|
||||
delete buf;
|
||||
file.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2548,10 +2548,6 @@ void AudacityProject::OpenFile(wxString fileName, bool addtohistory)
|
||||
|
||||
SetProjectTitle();
|
||||
|
||||
// Auto-save files (which are known by the special ending .autosave) do
|
||||
// not necessarily have the closing </project> tag, because log data can
|
||||
// be added anytime. So before opening an .autosave file, add the necessary
|
||||
// closing bracket to make the XML parser happy.
|
||||
const wxString autoSaveExt = wxT(".autosave");
|
||||
if (mFileName.Length() >= autoSaveExt.Length() &&
|
||||
mFileName.Right(autoSaveExt.Length()) == autoSaveExt)
|
||||
|
Loading…
x
Reference in New Issue
Block a user