| 418 | } // load |
| 419 | |
| 420 | bool |
| 421 | GuiAppInstance::findAndTryLoadUntitledAutoSave() |
| 422 | { |
| 423 | if ( !appPTR->getCurrentSettings()->isAutoSaveEnabledForUnsavedProjects() ) { |
| 424 | return false; |
| 425 | } |
| 426 | |
| 427 | QDir savesDir( Project::autoSavesDir() ); |
| 428 | QStringList entries = savesDir.entryList(QDir::Files | QDir::NoDotAndDotDot); |
| 429 | QStringList foundAutosaves; |
| 430 | for (int i = 0; i < entries.size(); ++i) { |
| 431 | const QString & entry = entries.at(i); |
| 432 | QString searchStr( QLatin1Char('.') ); |
| 433 | searchStr.append( QString::fromUtf8(NATRON_PROJECT_FILE_EXT) ); |
| 434 | searchStr.append( QString::fromUtf8(".autosave") ); |
| 435 | int suffixPos = entry.indexOf(searchStr); |
| 436 | if ( (suffixPos == -1) || entry.contains( QString::fromUtf8("RENDER_SAVE") ) ) { |
| 437 | continue; |
| 438 | } |
| 439 | |
| 440 | foundAutosaves << entry; |
| 441 | } |
| 442 | if ( foundAutosaves.empty() ) { |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | QString text = tr("An auto-saved project was found with no associated project file.\n" |
| 447 | "Would you like to restore it?\n" |
| 448 | "Clicking No will remove this auto-save."); |
| 449 | |
| 450 | StandardButtonEnum ret = Dialogs::questionDialog(tr("Auto-save").toStdString(), |
| 451 | text.toStdString(), false, StandardButtons(eStandardButtonYes | eStandardButtonNo), |
| 452 | eStandardButtonYes); |
| 453 | if ( (ret == eStandardButtonNo) || (ret == eStandardButtonEscape) ) { |
| 454 | Project::clearAutoSavesDir(); |
| 455 | |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | for (int i = 0; i < foundAutosaves.size(); ++i) { |
| 460 | const QString& autoSaveFileName = foundAutosaves[i]; |
| 461 | if (i == 0) { |
| 462 | //Load the first one into the current instance of Natron, then open-up new instances |
| 463 | if ( !getProject()->loadProject(savesDir.path() + QLatin1Char('/'), autoSaveFileName, true) ) { |
| 464 | return false; |
| 465 | } |
| 466 | } else { |
| 467 | CLArgs cl; |
| 468 | AppInstancePtr newApp = appPTR->newAppInstance(cl, false); |
| 469 | if ( !newApp->getProject()->loadProject(savesDir.path() + QLatin1Char('/'), autoSaveFileName, true) ) { |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return true; |
| 476 | } // findAndTryLoadAutoSave |
| 477 |
nothing calls this directly
no test coverage detected