Skip to content

Commit

Permalink
Retrieve the last valid version of qgd file
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jun 15, 2021
1 parent 1689690 commit 6dc608d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsarchive.sip.in
Expand Up @@ -61,7 +61,7 @@ Clear the current content of this archive and create a new temporary
directory.
%End

void addFile( const QString &filename );
void addFile( const QString &filename, bool copy = false );
%Docstring
Add a new file to this archive. During a zip action, this file will be
part of the resulting zipped file.
Expand Down
7 changes: 6 additions & 1 deletion src/core/project/qgsproject.cpp
Expand Up @@ -3346,8 +3346,13 @@ bool QgsProject::zip( const QString &filename )
if ( ! saveAuxiliaryStorage( asFileName ) )
{
const QString err = mAuxiliaryStorage->errorString();
setError( tr( "Unable to save auxiliary storage ('%1')" ).arg( err ) );
setError( tr( "Unable to save auxiliary storage file ('%1'). The project is still saved but last changes on auxiliary data are lost." ).arg( err ) );
asOk = false;

// try to retrieve the previous version
QgsProjectArchive tmpArchive;
tmpArchive.unzip( mFile.fileName() );
archive->addFile( tmpArchive.auxiliaryStorageFile(), true );
}
else
{
Expand Down
17 changes: 15 additions & 2 deletions src/core/qgsarchive.cpp
Expand Up @@ -104,9 +104,22 @@ bool QgsArchive::unzip( const QString &filename )
return QgsZipUtils::unzip( filename, mDir->path(), mFiles );
}

void QgsArchive::addFile( const QString &file )
void QgsArchive::addFile( const QString &file, bool copy )
{
mFiles.append( file );
if ( copy )
{
QFileInfo fi( file );
if ( ! fi.exists() )
return;

const QString newFile = mDir->path() + QDir::separator() + fi.fileName();
QFile::copy( file, newFile );
mFiles.append( newFile );
}
else
{
mFiles.append( file );
}
}

bool QgsArchive::removeFile( const QString &file )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsarchive.h
Expand Up @@ -79,7 +79,7 @@ class CORE_EXPORT QgsArchive
* part of the resulting zipped file.
* \param filename A file to add when zipping this archive
*/
void addFile( const QString &filename );
void addFile( const QString &filename, bool copy = false );

/**
* Remove a file from this archive and from the filesystem.
Expand Down

0 comments on commit 6dc608d

Please sign in to comment.