Added Checking of filetypes from the xml. Added a static function fileTypeFromData to the DataFile class. This opens the given file and checks the xml for its file type, as oposed to relying on the file extension

This commit is contained in:
Dave French
2015-02-23 21:16:38 +00:00
parent bf38b15d63
commit 7037faedd3
3 changed files with 46 additions and 1 deletions

View File

@@ -56,6 +56,11 @@ public:
DataFile( const QByteArray& data );
DataFile( Type type );
/// \brief fileTypeFromData
/// Reads the given file and checks the xml for the type
/// returns UnknownType if the file is not reconised
static DataFile::Type fileTypeFromData( const QString fileName);
virtual ~DataFile();
QString nameWithExtension( const QString& fn ) const;

View File

@@ -114,6 +114,45 @@ DataFile::DataFile( Type type ) :
}
DataFile::Type DataFile::fileTypeFromData(const QString fileName)
{
QString errorMsg;
DataFile::Type t;
QDomDocument doc;
QFile inFile( fileName );
if( !inFile.open( QIODevice::ReadOnly ) )
{
return DataFile::Type::UnknownType;
}
QByteArray data = inFile.readAll();
inFile.close();
int line = -1, col = -1;
if( !doc.setContent( data, &errorMsg, &line, &col ) )
{
// parsing failed? then try to uncompress data
QByteArray uncompressed = qUncompress( data );
if( !uncompressed.isEmpty() )
{
if( doc.setContent( uncompressed, &errorMsg, &line, &col ) )
{
line = col = -1;
}
}
if( line >= 0 && col >= 0 )
{
return DataFile::Type::UnknownType;
}
}
QDomElement root = doc.documentElement();
t = type( root.attribute( "type" ) );
return t;
}

View File

@@ -459,7 +459,8 @@ void FileBrowserTreeWidget::mousePressEvent(QMouseEvent * me )
}
else if( f->type() != FileItem::VstPluginFile &&
( f->handling() == FileItem::LoadAsPreset ||
f->handling() == FileItem::LoadByPlugin ) )
f->handling() == FileItem::LoadByPlugin )
&& DataFile::fileTypeFromData( f->fullName() ) == DataFile::Type::InstrumentTrackSettings )
{
m_previewPlayHandle = new PresetPreviewPlayHandle( f->fullName(), f->handling() == FileItem::LoadByPlugin );
}