Skip to content
Permalink
Browse files
Try to autofix qgz with last version of qgd file
  • Loading branch information
pblottiere committed Jun 15, 2021
1 parent 6dc608d commit a2168b377616ee2ab02c4966e9596f862ec3f1e0
Showing with 28 additions and 22 deletions.
  1. +3 −1 python/core/auto_generated/qgsarchive.sip.in
  2. +15 −5 src/core/project/qgsproject.cpp
  3. +7 −15 src/core/qgsarchive.cpp
  4. +3 −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, bool copy = false );
void addFile( const QString &filename );
%Docstring
Add a new file to this archive. During a zip action, this file will be
part of the resulting zipped file.
@@ -88,6 +88,8 @@ Returns the list of files within this archive
Returns the current temporary directory.
%End

bool exists() const;

};

class QgsProjectArchive : QgsArchive
@@ -3346,13 +3346,23 @@ bool QgsProject::zip( const QString &filename )
if ( ! saveAuxiliaryStorage( asFileName ) )
{
const QString err = mAuxiliaryStorage->errorString();
setError( tr( "Unable to save auxiliary storage file ('%1'). The project is still saved but last changes on auxiliary data are lost." ).arg( err ) );
setError( tr( "Unable to save auxiliary storage file ('%1'). The project is still saved but last changes on auxiliary data are lost. It is recommended to reload the project." ).arg( err ) );
asOk = false;

// try to retrieve the previous version
QgsProjectArchive tmpArchive;
tmpArchive.unzip( mFile.fileName() );
archive->addFile( tmpArchive.auxiliaryStorageFile(), true );
// fixes the current archive and keep the previous version of qgd
if ( !mArchive->exists() )
{
mArchive.reset( new QgsProjectArchive() );
mArchive->unzip( mFile.fileName() );
mArchive->clearProjectFile();

const QString asFile = mArchive->auxiliaryStorageFile();
if ( ! asFile.isEmpty() )
{
archive->addFile( asFile );
mAuxiliaryStorage.reset( new QgsAuxiliaryStorage( asFile, false ) );
}
}
}
else
{
@@ -104,22 +104,9 @@ bool QgsArchive::unzip( const QString &filename )
return QgsZipUtils::unzip( filename, mDir->path(), mFiles );
}

void QgsArchive::addFile( const QString &file, bool copy )
void QgsArchive::addFile( const QString &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 );
}
mFiles.append( file );
}

bool QgsArchive::removeFile( const QString &file )
@@ -139,6 +126,11 @@ QStringList QgsArchive::files() const
return mFiles;
}

bool QgsArchive::exists() const
{
return QFileInfo::exists( mDir->path() );
}

QString QgsProjectArchive::projectFile() const
{
const auto constFiles = files();
@@ -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, bool copy = false );
void addFile( const QString &filename );

/**
* Remove a file from this archive and from the filesystem.
@@ -98,6 +98,8 @@ class CORE_EXPORT QgsArchive
*/
QString dir() const;

bool exists() const;

private:
// content of the archive
QStringList mFiles;

0 comments on commit a2168b3

Please sign in to comment.