1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-08 12:42:03 +01:00

more progress on bug 113

better handling of error conditions in all BuildFromXML methods, per comment: 

// BuildFromXML methods should always return a BlockFile, not NULL,  
// even if the result is flawed (e.g., refers to nonexistent file), 
// as testing will be done in DirManager::ProjectFSCK().
This commit is contained in:
v.audacity
2010-07-30 03:04:37 +00:00
parent 874e530d84
commit 3729f067be
9 changed files with 139 additions and 188 deletions

View File

@@ -283,6 +283,9 @@ void LegacyBlockFile::SaveXML(XMLWriter &xmlFile)
xmlFile.EndTag(wxT("legacyblockfile"));
}
// BuildFromXML methods should always return a BlockFile, not NULL,
// even if the result is flawed (e.g., refers to nonexistent file),
// as testing will be done in DirManager::ProjectFSCK().
/// static
BlockFile *LegacyBlockFile::BuildFromXML(wxString projDir, const wxChar **attrs,
sampleCount len, sampleFormat format)
@@ -296,39 +299,28 @@ BlockFile *LegacyBlockFile::BuildFromXML(wxString projDir, const wxChar **attrs,
{
const wxChar *attr = *attrs++;
const wxChar *value = *attrs++;
if (!value)
break;
const wxString strValue = value;
if( !wxStrcmp(attr, wxT("name")) )
{
if (!XMLValueChecker::IsGoodFileName(strValue, projDir))
return NULL;
if (!wxStricmp(attr, wxT("name")) && XMLValueChecker::IsGoodFileName(strValue, projDir))
//vvv Should this be
// dm.AssignFile(fileName, strValue, false);
// as in PCMAliasBlockFile::BuildFromXML? Test with an old project.
fileName.Assign(projDir, strValue);
}
else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
{ // integer parameters
if( !wxStrcmp(attr, wxT("len")) )
{ // integer parameters
if (!wxStrcmp(attr, wxT("len")) && (nValue >= 0))
len = nValue;
if( !wxStrcmp(attr, wxT("norms")) )
else if (!wxStrcmp(attr, wxT("norms")))
noRMS = (nValue != 0);
if( !wxStrcmp(attr, wxT("format")) )
{
if (!XMLValueChecker::IsValidSampleFormat(nValue))
return NULL;
else if (!wxStrcmp(attr, wxT("format")) && XMLValueChecker::IsValidSampleFormat(nValue))
format = (sampleFormat)nValue;
}
if( !wxStrcmp(attr, wxT("summarylen")) )
else if (!wxStrcmp(attr, wxT("summarylen")) && (nValue > 0))
summaryLen = nValue;
}
}
if (!XMLValueChecker::IsGoodFileName(fileName.GetFullName(),
fileName.GetPath(wxPATH_GET_VOLUME)) ||
(len <= 0) || (summaryLen <= 0))
return NULL;
return new LegacyBlockFile(fileName, format, summaryLen, len, noRMS);
}