29#include <QStandardPaths>
33 : mDir( new QTemporaryDir() )
38 : mFiles( other.mFiles )
39 , mDir( new QTemporaryDir() )
47 mFiles = other.mFiles;
48 mDir.reset(
new QTemporaryDir() );
61 mDir.reset(
new QTemporaryDir() );
67 const QString tempPath = QStandardPaths::standardLocations( QStandardPaths::TempLocation ).at( 0 );
68 const QString uuid = QUuid::createUuid().toString();
69 QFile tmpFile( tempPath + QDir::separator() + uuid );
74 const QString err = QObject::tr(
"Unable to zip content" );
79 QString target {filename};
82 if ( QFile::exists( target ) )
85 const QFileInfo targetFileInfo( target );
86 target = targetFileInfo.canonicalFilePath();
88 if ( QFile::exists( target ) )
89 QFile::remove( target );
96 dwAttrs = GetFileAttributes( qUtf16Printable( tmpFile.fileName() ) );
97 SetFileAttributes( qUtf16Printable( tmpFile.fileName() ), dwAttrs & ~ FILE_ATTRIBUTE_TEMPORARY );
99 dwAttrs = GetFileAttributes( tmpFile.fileName().toLocal8Bit( ).data( ) );
100 SetFileAttributes( tmpFile.fileName().toLocal8Bit( ).data( ), dwAttrs & ~ FILE_ATTRIBUTE_TEMPORARY );
106 if ( ! tmpFile.rename( target ) )
108 const QString err = QObject::tr(
"Unable to save zip file '%1'" ).arg( target );
124 mFiles.append( file );
131 if ( !file.isEmpty() && mFiles.contains( file ) && QFile::exists( file ) )
132 rc = QFile::remove( file );
134 mFiles.removeOne( file );
146 return QFileInfo::exists( mDir->path() );
151 const auto constFiles =
files();
152 for (
const QString &file : constFiles )
154 const QFileInfo fileInfo( file );
155 if ( fileInfo.suffix().compare( QLatin1String(
"qgs" ), Qt::CaseInsensitive ) == 0 )
179 const QStringList fileList =
files();
180 for (
const QString &file : fileList )
182 const QFileInfo fileInfo( file );
183 if ( fileInfo.suffix().compare( extension, Qt::CaseInsensitive ) == 0 )
Class allowing to manage the zip/unzip actions.
QgsArchive & operator=(const QgsArchive &other)
virtual bool unzip(const QString &zipFilename)
Clear the current content of this archive and unzip.
bool zip(const QString &zipFilename)
Zip the content of this archive.
void clear()
Clear the current content of this archive and create a new temporary directory.
bool exists() const
Returns true if the archive exists on the filesystem, false otherwise.
void addFile(const QString &filename)
Add a new file to this archive.
bool removeFile(const QString &filename)
Remove a file from this archive and from the filesystem.
QString dir() const
Returns the current temporary directory.
QStringList files() const
Returns the list of files within this archive.
static QString extension()
Returns the extension used for auxiliary databases.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
QString projectFile() const
Returns the current .qgs project file or an empty string if there's none.
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.
bool unzip(const QString &zipFilename) override
Clear the current content of this archive and unzip.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files, bool checkConsistency=true)
Unzip a zip file in an output directory.