Don't clear tags until after loading to guard against bad XML file

This commit is contained in:
Leland Lucius 2021-01-23 16:05:27 -06:00
parent 82014bacd9
commit 4e6d11fe0c
1 changed files with 10 additions and 8 deletions

View File

@ -1245,24 +1245,26 @@ void TagsEditorDialog::OnLoad(wxCommandEvent & WXUNUSED(event))
return;
}
// Remember title and track in case they're read only
wxString title = mLocal.GetTag(TAG_TITLE);
wxString track = mLocal.GetTag(TAG_TRACK);
// Clear current contents
mLocal.Clear();
// Load the metadata
decltype(mLocal) temp;
XMLFileReader reader;
if (!reader.Parse(&mLocal, fn)) {
if (!reader.Parse(&temp, fn)) {
// Inform user of load failure
AudacityMessageBox(
reader.GetErrorStr(),
XO("Error Loading Metadata"),
wxOK | wxCENTRE,
this);
return;
}
// Remember title and track in case they're read only
wxString title = mLocal.GetTag(TAG_TITLE);
wxString track = mLocal.GetTag(TAG_TRACK);
// Replace existing tags with loaded ones
mLocal = temp;
// Restore title
if (!mEditTitle) {
mLocal.SetTag(TAG_TITLE, title);