mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-19 15:11:23 +01:00
Allow recovery of 2.1.0 or earlier autosave files
This commit is contained in:
@@ -637,8 +637,41 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
|||||||
|
|
||||||
if (file.Read(&ident, len) != len || strncmp(ident, AutoSaveIdent, len) != 0)
|
if (file.Read(&ident, len) != len || strncmp(ident, AutoSaveIdent, len) != 0)
|
||||||
{
|
{
|
||||||
// Not something we recognize. Could be decoded already. Let the caller
|
// It could be that the file has already been decoded or that it is one
|
||||||
// deal with it.
|
// 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();
|
file.Close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -650,7 +683,6 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
|||||||
if (file.Read(buf, len) != len)
|
if (file.Read(buf, len) != len)
|
||||||
{
|
{
|
||||||
delete buf;
|
delete buf;
|
||||||
file.Close();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2548,10 +2548,6 @@ void AudacityProject::OpenFile(wxString fileName, bool addtohistory)
|
|||||||
|
|
||||||
SetProjectTitle();
|
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");
|
const wxString autoSaveExt = wxT(".autosave");
|
||||||
if (mFileName.Length() >= autoSaveExt.Length() &&
|
if (mFileName.Length() >= autoSaveExt.Length() &&
|
||||||
mFileName.Right(autoSaveExt.Length()) == autoSaveExt)
|
mFileName.Right(autoSaveExt.Length()) == autoSaveExt)
|
||||||
|
|||||||
Reference in New Issue
Block a user