27using namespace Qt::StringLiterals;
33#include <QStandardPaths>
38 : mDir( new QTemporaryDir() )
43 : mFiles( other.mFiles )
44 , mDir( new QTemporaryDir() )
52 mFiles = other.mFiles;
53 mDir = std::make_unique<QTemporaryDir>( );
66 mDir = std::make_unique<QTemporaryDir>( );
72 const QString tempPath( QDir::temp().absoluteFilePath( u
"qgis-project-XXXXXX.zip"_s ) );
77 const QString err = QObject::tr(
"Unable to zip content" );
82 QString target {filename};
85 if ( QFile::exists( target ) )
88 const QFileInfo targetFileInfo( target );
89 target = targetFileInfo.canonicalFilePath();
91 if ( QFile::exists( target ) )
92 QFile::remove( target );
99 dwAttrs = GetFileAttributes( qUtf16Printable( tempPath ) );
100 SetFileAttributes( qUtf16Printable( tempPath ), dwAttrs & ~ FILE_ATTRIBUTE_TEMPORARY );
102 dwAttrs = GetFileAttributes( tempPath.toLocal8Bit( ).data( ) );
103 SetFileAttributes( tempPath.toLocal8Bit( ).data( ), dwAttrs & ~ FILE_ATTRIBUTE_TEMPORARY );
109 if ( !QFile::rename( tempPath, target ) )
111 const QString err = QObject::tr(
"Unable to save zip file '%1'" ).arg( target );
127 mFiles.append( file );
134 if ( !file.isEmpty() && mFiles.contains( file ) && QFile::exists( file ) )
135 rc = QFile::remove( file );
137 mFiles.removeOne( file );
149 return QFileInfo::exists( mDir->path() );
154 const auto constFiles =
files();
155 for (
const QString &file : constFiles )
157 const QFileInfo fileInfo( file );
158 if ( fileInfo.suffix().compare(
"qgs"_L1, Qt::CaseInsensitive ) == 0 )
182 const QStringList fileList =
files();
183 for (
const QString &file : fileList )
185 const QFileInfo fileInfo( file );
186 if ( fileInfo.suffix().compare( extension, Qt::CaseInsensitive ) == 0 )
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.
static bool zip(const QString &zip, const QStringList &files, bool overwrite=false)
Zip the list of files in the zip file.
static bool unzip(const QString &zip, const QString &dir, QStringList &files, bool checkConsistency=true)
Unzip a zip file in an output directory.