diff --git a/src/AutoRecovery.cpp b/src/AutoRecovery.cpp index 2315b78dc..55cb556e4 100644 --- a/src/AutoRecovery.cpp +++ b/src/AutoRecovery.cpp @@ -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 tag is preset. + + // Close the file so we can reopen it in read/write mode + file.Close(); + + // Add 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 + // "" 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, "") == 0) + { + // End of file does not contain closing tag, so add it + if (file.Seek(0, wxFromEnd) != wxInvalidOffset) + { + strcpy(buf, "\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; } diff --git a/src/Project.cpp b/src/Project.cpp index bceca619d..2052eceb6 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -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 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)