From 33dd77f55ca7088a3e123e8364463017534653a4 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 (cherry picked from commit c0794d0c416e4846960c7be45683551acc8a42fb) --- 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 2d23eeccb..dbec23aaf 100644 --- a/src/core/mmp.cpp +++ b/src/core/mmp.cpp @@ -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();