From c0794d0c416e4846960c7be45683551acc8a42fb Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 15 Jun 2009 13:58:40 +0200 Subject: [PATCH] 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 --- src/core/mmp.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/core/mmp.cpp b/src/core/mmp.cpp index f0d97f910..4013cffec 100644 --- a/src/core/mmp.cpp +++ b/src/core/mmp.cpp @@ -103,14 +103,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 ); } @@ -687,15 +680,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();