24 #include <QStandardPaths> 28 : mDir( new QTemporaryDir() )
33 : mFiles( other.mFiles )
34 , mDir( new QTemporaryDir() )
41 mFiles = other.mFiles;
53 mDir.reset(
new QTemporaryDir() );
59 QString tempPath = QStandardPaths::standardLocations( QStandardPaths::TempLocation ).at( 0 );
60 QString uuid = QUuid::createUuid().toString();
61 QFile tmpFile( tempPath + QDir::separator() + uuid );
66 QString err = QObject::tr(
"Unable to zip content" );
72 if ( QFile::exists( filename ) )
73 QFile::remove( filename );
76 if ( ! tmpFile.rename( filename ) )
78 QString err = QObject::tr(
"Unable to save zip file '%1'" ).arg( filename );
94 mFiles.append( file );
101 if ( !file.isEmpty() && mFiles.contains( file ) && QFile::exists( file ) )
102 rc = QFile::remove( file );
104 mFiles.removeOne( file );
116 const auto constFiles =
files();
117 for (
const QString &file : constFiles )
119 QFileInfo fileInfo( file );
120 if ( fileInfo.suffix().compare( QLatin1String(
"qgs" ), Qt::CaseInsensitive ) == 0 )
130 return ! projectFile().isEmpty();
144 const QStringList fileList =
files();
145 for (
const QString &file : fileList )
147 const QFileInfo fileInfo( file );
148 if ( fileInfo.suffix().compare( extension, Qt::CaseInsensitive ) == 0 )
Class allowing to manage the zip/unzip actions.
bool unzip(const QString &zipFilename) override
Clear the current content of this archive and unzip.
void clear()
Clear the current content of this archive and create a new temporary directory.
bool removeFile(const QString &filename)
Remove a file from this archive and from the filesystem.
bool zip(const QString &zipFilename)
Zip the content of this archive.
static QString extension()
Returns the extension used for auxiliary databases.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
QString projectFile() const
Returns the current .qgs project file or an empty string if there's none.
virtual bool unzip(const QString &zipFilename)
Clear the current content of this archive and unzip.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QgsArchive & operator=(const QgsArchive &other)
void addFile(const QString &filename)
Add a new file to this archive.
QStringList files() const
Returns the list of files within this archive.
QString auxiliaryStorageFile() const
Returns the current .qgd auxiliary storage file or an empty string if there's none.
bool clearProjectFile()
Remove the current .qgs project file from the temporary directory.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
QString dir() const
Returns the current temporary directory.