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