diff --git a/include/mmp.h b/include/mmp.h index 55f289427..403f90f5e 100644 --- a/include/mmp.h +++ b/include/mmp.h @@ -2,6 +2,7 @@ * mmp.h - class for reading and writing multimedia-project-files * * Copyright (c) 2004-2009 Tobias Doerffel + * Copyright (c) 2012-2013 Paul Giblock

* * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -27,6 +28,7 @@ #define _MMP_H #include +#include #include "export.h" #include "lmms_basics.h" @@ -59,6 +61,7 @@ public: QString nameWithExtension( const QString & _fn ) const; + void write( QTextStream & _strm ); bool writeFile( const QString & _fn ); inline QDomElement & content() diff --git a/src/core/main.cpp b/src/core/main.cpp index c94898b15..55490628d 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -168,7 +168,8 @@ int main( int argc, char * * argv ) "-x, --oversampling specify oversampling\n" " possible values: 1, 2, 4, 8\n" " default: 2\n" - "-u, --upgrade upgrade file and save as \n" + "-u, --upgrade [out] upgrade file and save as \n" + " standard out is used if no output file is specifed\n" "-d, --dump dump XML of compressed file \n" "-v, --version show version information and exit.\n" "-h, --help show this usage information and exit.\n\n", @@ -179,9 +180,15 @@ int main( int argc, char * * argv ) QString( argv[i] ) == "-u" ) ) { multimediaProject mmp( QString( argv[i + 1] ) ); - if (argc > i+1) + if (argc > i+2) { - mmp.writeFile(argv[i + 2]); + mmp.writeFile( argv[i + 2] ); + } + else + { + QTextStream ts( stdout ); + mmp.write( ts ); + fflush( stdout ); } return( EXIT_SUCCESS ); } diff --git a/src/core/mmp.cpp b/src/core/mmp.cpp index cd71651f7..adc438fdf 100644 --- a/src/core/mmp.cpp +++ b/src/core/mmp.cpp @@ -165,7 +165,7 @@ QString multimediaProject::nameWithExtension( const QString & _fn ) const -bool multimediaProject::writeFile( const QString & _fn ) +void multimediaProject::write( QTextStream & _strm ) { if( type() == SongProject || type() == SongProjectTemplate || type() == InstrumentTrackSettings ) @@ -173,7 +173,14 @@ bool multimediaProject::writeFile( const QString & _fn ) cleanMetaNodes( documentElement() ); } + save(_strm, 2); +} + + + +bool multimediaProject::writeFile( const QString & _fn ) +{ QString fn = nameWithExtension( _fn ); QFile outfile( fn ); if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) @@ -191,14 +198,18 @@ bool multimediaProject::writeFile( const QString & _fn ) ).arg( fn ) ); return false; } - QString xml = toString( 2 ); + if( fn.section( '.', -1 ) == "mmpz" ) { + QString xml; + QTextStream ts( &xml ); + write( ts ); outfile.write( qCompress( xml.toUtf8() ) ); } else { - QTextStream( &outfile ) << xml; + QTextStream ts( &outfile ); + write( ts ); } outfile.close();