@@ -375,7 +375,7 @@ QgsProject::QgsProject( QObject *parent )
375
375
, mDisplaySettings( new QgsProjectDisplaySettings( this ) )
376
376
, mRootGroup( new QgsLayerTree )
377
377
, mLabelingEngineSettings( new QgsLabelingEngineSettings )
378
- , mArchive( new QgsProjectArchive () )
378
+ , mArchive( new QgsArchive () )
379
379
, mAuxiliaryStorage( new QgsAuxiliaryStorage() )
380
380
{
381
381
mProperties .setName ( QStringLiteral ( " properties" ) );
@@ -829,7 +829,7 @@ void QgsProject::clear()
829
829
mLabelingEngineSettings ->clear ();
830
830
831
831
mAuxiliaryStorage .reset ( new QgsAuxiliaryStorage () );
832
- mArchive .reset ( new QgsProjectArchive () );
832
+ mArchive .reset ( new QgsArchive () );
833
833
834
834
emit labelingEngineSettingsChanged ();
835
835
@@ -1294,6 +1294,16 @@ bool QgsProject::read( QgsProject::ReadFlags flags )
1294
1294
else
1295
1295
{
1296
1296
mAuxiliaryStorage .reset ( new QgsAuxiliaryStorage ( *this ) );
1297
+ QFileInfo finfo ( mFile .fileName () );
1298
+ QString attachmentsZip = finfo.absoluteDir ().absoluteFilePath ( QStringLiteral ( " %1_attachments.zip" ).arg ( finfo.completeBaseName () ) );
1299
+ if ( QFile ( attachmentsZip ).exists () )
1300
+ {
1301
+ std::unique_ptr<QgsArchive> archive ( new QgsArchive () );
1302
+ if ( archive->unzip ( attachmentsZip ) )
1303
+ {
1304
+ mArchive = std::move ( archive );
1305
+ }
1306
+ }
1297
1307
returnValue = readProjectFile ( mFile .fileName (), flags );
1298
1308
}
1299
1309
@@ -1391,7 +1401,7 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
1391
1401
profile.switchTask ( tr ( " Creating auxiliary storage" ) );
1392
1402
QString fileName = mFile .fileName ();
1393
1403
std::unique_ptr<QgsAuxiliaryStorage> aStorage = std::move ( mAuxiliaryStorage );
1394
- std::unique_ptr<QgsProjectArchive > archive = std::move ( mArchive );
1404
+ std::unique_ptr<QgsArchive > archive = std::move ( mArchive );
1395
1405
clear ();
1396
1406
mAuxiliaryStorage = std::move ( aStorage );
1397
1407
mArchive = std::move ( archive );
@@ -2162,15 +2172,31 @@ bool QgsProject::write()
2162
2172
// saved
2163
2173
const bool asOk = saveAuxiliaryStorage ();
2164
2174
const bool writeOk = writeProjectFile ( mFile .fileName () );
2175
+ bool attachmentsOk = true ;
2176
+ if ( !mArchive ->files ().isEmpty () )
2177
+ {
2178
+ QFileInfo finfo ( mFile .fileName () );
2179
+ QString attachmentsZip = finfo.absoluteDir ().absoluteFilePath ( QStringLiteral ( " %1_attachments.zip" ).arg ( finfo.completeBaseName () ) );
2180
+ attachmentsOk = mArchive ->zip ( attachmentsZip );
2181
+ }
2165
2182
2166
2183
// errors raised during writing project file are more important
2167
- if ( !asOk && writeOk )
2184
+ if ( ( !asOk || !attachmentsOk ) && writeOk )
2168
2185
{
2169
- const QString err = mAuxiliaryStorage ->errorString ();
2170
- setError ( tr ( " Unable to save auxiliary storage ('%1')" ).arg ( err ) );
2186
+ QStringList errorMessage;
2187
+ if ( !asOk )
2188
+ {
2189
+ const QString err = mAuxiliaryStorage ->errorString ();
2190
+ errorMessage.append ( tr ( " Unable to save auxiliary storage ('%1')" ).arg ( err ) );
2191
+ }
2192
+ if ( !attachmentsOk )
2193
+ {
2194
+ errorMessage.append ( tr ( " Unable to save attachments archive" ) );
2195
+ }
2196
+ setError ( errorMessage.join ( " \n " ) );
2171
2197
}
2172
2198
2173
- return asOk && writeOk;
2199
+ return asOk && writeOk && attachmentsOk ;
2174
2200
}
2175
2201
}
2176
2202
@@ -3295,26 +3321,26 @@ bool QgsProject::unzip( const QString &filename, QgsProject::ReadFlags flags )
3295
3321
mArchive = std::move ( archive );
3296
3322
3297
3323
// load auxiliary storage
3298
- if ( !mArchive ->auxiliaryStorageFile ().isEmpty () )
3324
+ if ( !static_cast <QgsProjectArchive *>( mArchive . get () ) ->auxiliaryStorageFile ().isEmpty () )
3299
3325
{
3300
3326
// database file is already a copy as it's been unzipped. So we don't open
3301
3327
// auxiliary storage in copy mode in this case
3302
- mAuxiliaryStorage .reset ( new QgsAuxiliaryStorage ( mArchive ->auxiliaryStorageFile (), false ) );
3328
+ mAuxiliaryStorage .reset ( new QgsAuxiliaryStorage ( static_cast <QgsProjectArchive *>( mArchive . get () ) ->auxiliaryStorageFile (), false ) );
3303
3329
}
3304
3330
else
3305
3331
{
3306
3332
mAuxiliaryStorage .reset ( new QgsAuxiliaryStorage ( *this ) );
3307
3333
}
3308
3334
3309
3335
// read the project file
3310
- if ( ! readProjectFile ( mArchive ->projectFile (), flags ) )
3336
+ if ( ! readProjectFile ( static_cast <QgsProjectArchive *>( mArchive . get () ) ->projectFile (), flags ) )
3311
3337
{
3312
3338
setError ( tr ( " Cannot read unzipped qgs project file" ) );
3313
3339
return false ;
3314
3340
}
3315
3341
3316
3342
// Remove the temporary .qgs file
3317
- mArchive ->clearProjectFile ();
3343
+ static_cast <QgsProjectArchive *>( mArchive . get () ) ->clearProjectFile ();
3318
3344
3319
3345
return true ;
3320
3346
}
@@ -3360,9 +3386,9 @@ bool QgsProject::zip( const QString &filename )
3360
3386
{
3361
3387
mArchive .reset ( new QgsProjectArchive () );
3362
3388
mArchive ->unzip ( mFile .fileName () );
3363
- mArchive ->clearProjectFile ();
3389
+ static_cast <QgsProjectArchive *>( mArchive . get () ) ->clearProjectFile ();
3364
3390
3365
- const QString auxiliaryStorageFile = mArchive ->auxiliaryStorageFile ();
3391
+ const QString auxiliaryStorageFile = static_cast <QgsProjectArchive *>( mArchive . get () ) ->auxiliaryStorageFile ();
3366
3392
if ( ! auxiliaryStorageFile.isEmpty () )
3367
3393
{
3368
3394
archive->addFile ( auxiliaryStorageFile );
0 commit comments