@@ -4312,13 +4312,35 @@ bool QgisApp::addProject( const QString& projectFile )
4312
4312
4313
4313
if ( !QgsProject::instance ()->read ( projectFile ) )
4314
4314
{
4315
+ QString backupFile = projectFile + " ~" ;
4316
+ QString loadBackupPrompt;
4317
+ QMessageBox::StandardButtons buttons;
4318
+ if ( QFile ( backupFile ).exists () )
4319
+ {
4320
+ loadBackupPrompt = " \n\n " + tr ( " Do you want to open the backup file\n %1\n instead?" ).arg ( backupFile );
4321
+ buttons |= QMessageBox::Yes;
4322
+ buttons |= QMessageBox::No;
4323
+ }
4324
+ else
4325
+ {
4326
+ buttons |= QMessageBox::Ok;
4327
+ }
4315
4328
QApplication::restoreOverrideCursor ();
4316
4329
statusBar ()->clearMessage ();
4317
4330
4318
- QMessageBox::critical ( this ,
4319
- tr ( " Unable to open project" ),
4320
- QgsProject::instance ()->error () );
4331
+ int r = QMessageBox::critical ( this ,
4332
+ tr ( " Unable to open project" ),
4333
+ QgsProject::instance ()->error () + loadBackupPrompt,
4334
+ buttons );
4321
4335
4336
+ if ( QMessageBox::Yes == r && addProject ( backupFile ) )
4337
+ {
4338
+ // We loaded data from the backup file, but we pretend to work on the original project file.
4339
+ QgsProject::instance ()->setFileName ( projectFile );
4340
+ QgsProject::instance ()->setDirty ( true );
4341
+ mProjectLastModified = pfi.lastModified ();
4342
+ return true ;
4343
+ }
4322
4344
4323
4345
mMapCanvas ->freeze ( false );
4324
4346
mMapCanvas ->refresh ();
0 commit comments