MMP: detect compressed files rather than guessing by extension
Detect whether a given file is compressed by first trying to parse
its content as XML data. If it failed, try to uncompress and
parse again. This is more flexible than just looking whether the
filename extension is "mmpz".
Signed-off-by: Tobias Doerffel <tobias.doerffel@gmail.com>
(cherry picked from commit c0794d0c41)
This commit is contained in:
@@ -101,14 +101,7 @@ multimediaProject::multimediaProject( const QString & _fileName ) :
|
||||
return;
|
||||
}
|
||||
|
||||
if( _fileName.section( '.', -1 ) == "mmpz" )
|
||||
{
|
||||
loadData( qUncompress( inFile.readAll() ), _fileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
loadData( inFile.readAll(), _fileName );
|
||||
}
|
||||
loadData( inFile.readAll(), _fileName );
|
||||
}
|
||||
|
||||
|
||||
@@ -685,15 +678,29 @@ void multimediaProject::loadData( const QByteArray & _data,
|
||||
const QString & _sourceFile )
|
||||
{
|
||||
QString errorMsg;
|
||||
int line, col;
|
||||
int line = -1, col = -1;
|
||||
if( !setContent( _data, &errorMsg, &line, &col ) )
|
||||
{
|
||||
qWarning() << "at line" << line << "column" << errorMsg;
|
||||
QMessageBox::critical( NULL, songEditor::tr( "Error in file" ),
|
||||
songEditor::tr( "The file %1 seems to contain errors "
|
||||
"and therefore can't be loaded." ).
|
||||
// parsing failed? then try to uncompress data
|
||||
QByteArray uncompressed = qUncompress( _data );
|
||||
if( !uncompressed.isEmpty() )
|
||||
{
|
||||
if( setContent( uncompressed, &errorMsg, &line, &col ) )
|
||||
{
|
||||
line = col = -1;
|
||||
}
|
||||
}
|
||||
if( line >= 0 && col >= 0 )
|
||||
{
|
||||
qWarning() << "at line" << line << "column" << errorMsg;
|
||||
QMessageBox::critical( NULL,
|
||||
songEditor::tr( "Error in file" ),
|
||||
songEditor::tr( "The file %1 seems to contain "
|
||||
"errors and therefore can't be "
|
||||
"loaded." ).
|
||||
arg( _sourceFile ) );
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QDomElement root = documentElement();
|
||||
|
||||
Reference in New Issue
Block a user