MCPcopy Create free account
hub / github.com/MrKepzie/Natron / saveProjectInternal

Method saveProjectInternal

Engine/Project.cpp:467–606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465}
466
467QString
468Project::saveProjectInternal(const QString & path,
469 const QString & name,
470 bool autoSave,
471 bool updateProjectProperties)
472{
473 bool isRenderSave = name.contains( QString::fromUtf8("RENDER_SAVE") );
474 QDateTime time = QDateTime::currentDateTime();
475 QString timeStr = time.toString();
476 QString filePath;
477
478 if (autoSave) {
479 bool appendTimeHash = false;
480 if ( path.isEmpty() ) {
481 filePath = autoSavesDir();
482
483 //If the auto-save is saved in the AutoSaves directory, there will be other autosaves for other opened
484 //projects. We uniquely identity it with the time hash of the current time
485 appendTimeHash = true;
486 } else {
487 filePath = path;
488 }
489 filePath.append( QLatin1Char('/') );
490 filePath.append(name);
491 if (!isRenderSave) {
492 filePath.append( QString::fromUtf8(".autosave") );
493 }
494 if (!isRenderSave) {
495 if (appendTimeHash) {
496 Hash64 timeHash;
497
498 Q_FOREACH(QChar ch, timeStr) {
499 timeHash.append<unsigned short>( ch.unicode() );
500 }
501 timeHash.computeHash();
502 QString timeHashStr = QString::number( timeHash.value() );
503 filePath.append(QLatin1Char('.') + timeHashStr);
504 }
505 }
506
507 if (updateProjectProperties) {
508 QMutexLocker l(&_imp->projectLock);
509 _imp->lastAutoSaveFilePath = filePath;
510 }
511 } else {
512 filePath = path + name;
513 }
514
515 std::string newFilePath = _imp->runOnProjectSaveCallback(filePath.toStdString(), autoSave);
516 filePath = QString::fromUtf8( newFilePath.c_str() );
517
518 ///Use a temporary file to save, so if Natron crashes it doesn't corrupt the user save.
519 QString tmpFilename = StandardPaths::writableLocation(StandardPaths::eStandardLocationTemp);
520 StrUtils::ensureLastPathSeparator(tmpFilename);
521 tmpFilename.append( QString::number( time.toMSecsSinceEpoch() ) );
522
523 {
524 FStreamsSupport::ofstream ofile;

Callers

nothing calls this directly

Calls 15

openFunction · 0.85
generateGUIUserNameFunction · 0.85
getAppFunction · 0.85
fileCopyFunction · 0.85
appendMethod · 0.80
toStdStringMethod · 0.80
setProjectFilenameMethod · 0.80
setProjectPathMethod · 0.80
saveFunction · 0.70

Tested by

no test coverage detected