mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-17 11:18:30 -04:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user