Skip to content
Permalink
Browse files
Retrieve the last valid version of qgd file
  • Loading branch information
pblottiere committed Jun 15, 2021
1 parent 1689690 commit 6dc608d66a23e27bae6ba2bde1c1f654ebdc539a
Showing with 23 additions and 5 deletions.
  1. +1 −1 python/core/auto_generated/qgsarchive.sip.in
  2. +6 −1 src/core/project/qgsproject.cpp
  3. +15 −2 src/core/qgsarchive.cpp
  4. +1 −1 src/core/qgsarchive.h
@@ -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.
@@ -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
{
@@ -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 )
@@ -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.

0 comments on commit 6dc608d

Please sign in to comment.