MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / findAndTryLoadUntitledAutoSave

Method findAndTryLoadUntitledAutoSave

Gui/GuiAppInstance.cpp:420–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418} // load
419
420bool
421GuiAppInstance::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

Callers

nothing calls this directly

Calls 12

getCurrentSettingsMethod · 0.80
atMethod · 0.80
appendMethod · 0.80
emptyMethod · 0.80
toStdStringMethod · 0.80
newAppInstanceMethod · 0.80
getProjectMethod · 0.80
sizeMethod · 0.45
containsMethod · 0.45
loadProjectMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected