| 197 | }; |
| 198 | |
| 199 | NATRON_NAMESPACE_ANONYMOUS_EXIT |
| 200 | |
| 201 | bool |
| 202 | Project::loadProject(const QString & path, |
| 203 | const QString & name, |
| 204 | bool isUntitledAutosave, |
| 205 | bool attemptToLoadAutosave) |
| 206 | { |
| 207 | reset(false, true); |
| 208 | |
| 209 | try { |
| 210 | QString realPath = path; |
| 211 | StrUtils::ensureLastPathSeparator(realPath); |
| 212 | QString realName = name; |
| 213 | bool isAutoSave = isUntitledAutosave; |
| 214 | if (!getApp()->isBackground() && !isUntitledAutosave) { |
| 215 | // In Gui mode, attempt to load an auto-save for this project if there's one. |
| 216 | QString autosaveFileName; |
| 217 | bool hasAutoSave = findAutoSaveForProject(realPath, name, &autosaveFileName); |
| 218 | if (hasAutoSave) { |
| 219 | StandardButtonEnum ret = eStandardButtonNo; |
| 220 | if (attemptToLoadAutosave) { |
| 221 | QString text = tr("A recent auto-save of %1 was found.\n" |
| 222 | "Would you like to use it instead? " |
| 223 | "Clicking No will remove this auto-save.").arg(name); |
| 224 | ret = Dialogs::questionDialog(tr("Auto-save").toStdString(), |
| 225 | text.toStdString(), false, StandardButtons(eStandardButtonYes | eStandardButtonNo), |
| 226 | eStandardButtonYes); |
| 227 | } |
| 228 | if ( (ret == eStandardButtonNo) || (ret == eStandardButtonEscape) ) { |
| 229 | QFile::remove(realPath + autosaveFileName); |
| 230 | } else { |
| 231 | realName = autosaveFileName; |
| 232 | isAutoSave = true; |
| 233 | { |
| 234 | QMutexLocker k(&_imp->projectLock); |
| 235 | _imp->lastAutoSaveFilePath = realPath + realName; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | bool mustSave = false; |
| 242 | if ( !loadProjectInternal(realPath, realName, isAutoSave, isUntitledAutosave, &mustSave) ) { |
| 243 | appPTR->showErrorLog(); |
| 244 | } else if (mustSave) { |
| 245 | saveProject(realPath, realName, 0); |
| 246 | } |
| 247 | } catch (const std::exception & e) { |
| 248 | Dialogs::errorDialog( tr("Project loader").toStdString(), tr("Error while loading project: %1").arg( QString::fromUtf8( e.what() ) ).toStdString() ); |
| 249 | if ( !getApp()->isBackground() ) { |
| 250 | CreateNodeArgs args(PLUGINID_NATRON_VIEWER, shared_from_this() ); |
| 251 | args.setProperty<bool>(kCreateNodeArgsPropAutoConnect, false); |
| 252 | args.setProperty<bool>(kCreateNodeArgsPropAddUndoRedoCommand, false); |
| 253 | getApp()->createNode(args); |
| 254 | } |
| 255 | |
| 256 | return false; |
no test coverage detected