From ea41b0385bfae9268d88dac667eb283504742956 Mon Sep 17 00:00:00 2001 From: adv Date: Thu, 12 May 2016 11:54:31 +0300 Subject: [PATCH] USUL Internal 0003884: 'Restore session' operation doesn't work. --- src/LightApp/LightApp_Study.cxx | 69 ++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index dda081079..a42d7bfd0 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -495,36 +495,45 @@ void LightApp_Study::backup( const QString& fName ) { QList list; dataModels( list ); + if ( list.isEmpty() ) + return; - QListIterator itList( list ); - while ( itList.hasNext() ) + QString dataName = Qtx::addSlash( fName ) + "data"; + FILE* f = fopen( dataName.toLatin1().constData(), "w" ); + if ( f ) { - LightApp_DataModel* model = (LightApp_DataModel*)itList.next(); - if ( model && model->getModule() ) + bool header = false; + + QListIterator itList( list ); + while ( itList.hasNext() ) { - // writes location of hdf-file - QString hdfName = QString( "HDF:" ) + studyName() + "\n"; - - //QString tmpName = QString( " ) + GetTmpDir( "", false ).c_str() + "\n"; - QString tmpName( "TMP:" ); - - LightApp_Driver::ListOfFiles files = - myDriver->GetListOfFiles( model->getModule()->name().toLatin1().constData() ); - if ( files.size() > 0 ) - tmpName += files.front().c_str(); - else + LightApp_DataModel* model = (LightApp_DataModel*)itList.next(); + if ( model && model->getModule() ) { - // New (not saved study). Use backup folder as default - tmpName += fName; - } - tmpName += '\n'; + if ( !header ) + { + // writes location of hdf-file + QString hdfName = QString( "HDF:" ) + studyName() + "\n"; + + //QString tmpName = QString( " ) + GetTmpDir( "", false ).c_str() + "\n"; + QString tmpName( "TMP:" ); + + LightApp_Driver::ListOfFiles files = + myDriver->GetListOfFiles( model->getModule()->name().toLatin1().constData() ); + if ( files.size() > 0 ) + tmpName += files.front().c_str(); + else + { + // New (not saved study). Use backup folder as default + tmpName += fName; + } + tmpName += '\n'; - QString dataName = Qtx::addSlash( fName ) + "data"; - FILE* f = fopen( dataName.toLatin1().constData(), "w" ); - if ( f ) - { - fputs( hdfName.toLatin1().constData(), f ); - fputs( tmpName.toLatin1().constData(), f ); + fputs( hdfName.toLatin1().constData(), f ); + fputs( tmpName.toLatin1().constData(), f ); + + header = true; + } // backup model QStringList backupFiles; @@ -540,11 +549,16 @@ void LightApp_Study::backup( const QString& fName ) const QString& curr = * it; modStr += QString( "*" ) + curr; } + modStr += '\n'; + fputs( modStr.toLatin1().constData(), f ); } - fclose( f ); } } + + fclose( f ); + if ( !header ) + remove( dataName.toLatin1().constData() ); // Remove empty created file } } @@ -604,6 +618,9 @@ bool LightApp_Study::openBackupData() memset( buff, 0, 1024 ); fgets( buff, 1024, f ); QString modStr( buff ); + modStr.remove( '\n' ); + if ( modStr.isEmpty() ) + continue; QStringList lst = modStr.split( "*" ); QStringList::iterator it = lst.begin(); -- 2.39.2