1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-11 14:04:29 +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

@@ -284,13 +284,15 @@ void ODPCMAliasBlockFile::SaveXML(XMLWriter &xmlFile)
/// Constructs a ODPCMAliasBlockFile from the xml output of WriteXML.
/// Does not schedule the ODPCMAliasBlockFile for OD loading. Client code must do this.
// 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().
BlockFile *ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
{
wxFileName summaryFileName;
wxFileName aliasFileName;
sampleCount aliasStart=0, aliasLen=0;
int aliasChannel=0;
float rms=0;
long nValue;
while(*attrs)
@@ -301,20 +303,14 @@ BlockFile *ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr
break;
const wxString strValue = value;
if( !wxStricmp(attr, wxT("summaryfile")) )
{
// Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
if (!XMLValueChecker::IsGoodFileString(strValue))
return NULL;
#ifdef _WIN32
if (strValue.Length() + 1 + dm.GetProjectDataDir().Length() > MAX_PATH)
return NULL;
#endif
dm.AssignFile(summaryFileName,value,FALSE);
}
if (!wxStricmp(attr, wxT("summaryfile")) &&
// Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
XMLValueChecker::IsGoodFileString(strValue)
#ifdef _WIN32
&& (strValue.Length() + 1 + dm.GetProjectDataDir().Length() <= MAX_PATH)
#endif
)
dm.AssignFile(summaryFileName, strValue, false);
else if( !wxStricmp(attr, wxT("aliasfile")) )
{
if (XMLValueChecker::IsGoodPathName(strValue))
@@ -322,28 +318,25 @@ BlockFile *ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr
else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
// Allow fallback of looking for the file name, located in the data directory.
aliasFileName.Assign(dm.GetProjectDataDir(), strValue);
else
return NULL;
else if (XMLValueChecker::IsGoodPathString(strValue))
// If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
// and XMLValueChecker::IsGoodFileName, because both do existence tests,
// but we want to keep the reference to the missing file because it's a good path string.
aliasFileName.Assign(strValue);
}
else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
{ // integer parameters
if( !wxStricmp(attr, wxT("aliasstart")) )
{ // integer parameters
if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0))
aliasStart = nValue;
else if( !wxStricmp(attr, wxT("aliaslen")) )
else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
aliasLen = nValue;
else if( !wxStricmp(attr, wxT("aliaschannel")) )
else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
aliasChannel = nValue;
}
}
//file doesn't exist, but IsGoodFileName Checks that it does - maybe we should have a different method to check for valid names?
if ( /*!XMLValueChecker::IsGoodFileName(summaryFileName.GetFullName(), summaryFileName.GetPath(wxPATH_GET_VOLUME)) || */
!XMLValueChecker::IsGoodFileName(aliasFileName.GetFullName(), aliasFileName.GetPath(wxPATH_GET_VOLUME)) ||
(aliasLen <= 0) || (aliasLen < 0.0) || !XMLValueChecker::IsValidChannel(aliasChannel) || (rms < 0.0))
return NULL;
return new ODPCMAliasBlockFile(summaryFileName, aliasFileName,
aliasStart, aliasLen, aliasChannel);
aliasStart, aliasLen, aliasChannel);
}