| 543 | } |
| 544 | |
| 545 | QString |
| 546 | Project::saveProjectInternal(const QString & path, |
| 547 | const QString & name, |
| 548 | bool autoSave, |
| 549 | bool updateProjectProperties) |
| 550 | { |
| 551 | bool isRenderSave = name.contains( QString::fromUtf8("RENDER_SAVE") ); |
| 552 | QDateTime time = QDateTime::currentDateTime(); |
| 553 | QString timeStr = time.toString(); |
| 554 | QString filePath; |
| 555 | |
| 556 | if (autoSave) { |
| 557 | bool appendTimeHash = false; |
| 558 | if ( path.isEmpty() ) { |
| 559 | filePath = autoSavesDir(); |
| 560 | |
| 561 | //If the auto-save is saved in the AutoSaves directory, there will be other autosaves for other opened |
| 562 | //projects. We uniquely identity it with the time hash of the current time |
| 563 | appendTimeHash = true; |
| 564 | } else { |
| 565 | filePath = path; |
| 566 | } |
| 567 | filePath.append( QLatin1Char('/') ); |
| 568 | filePath.append(name); |
| 569 | if (!isRenderSave) { |
| 570 | filePath.append( QString::fromUtf8(".autosave") ); |
| 571 | } |
| 572 | if (!isRenderSave) { |
| 573 | if (appendTimeHash) { |
| 574 | Hash64 timeHash; |
| 575 | |
| 576 | Q_FOREACH(QChar ch, timeStr) { |
| 577 | timeHash.append<unsigned short>( ch.unicode() ); |
| 578 | } |
| 579 | timeHash.computeHash(); |
| 580 | QString timeHashStr = QString::number( timeHash.value() ); |
| 581 | filePath.append(QLatin1Char('.') + timeHashStr); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | if (updateProjectProperties) { |
| 586 | QMutexLocker l(&_imp->projectLock); |
| 587 | _imp->lastAutoSaveFilePath = filePath; |
| 588 | } |
| 589 | } else { |
| 590 | filePath = path + name; |
| 591 | } |
| 592 | |
| 593 | std::string newFilePath = _imp->runOnProjectSaveCallback(filePath.toStdString(), autoSave); |
| 594 | filePath = QString::fromUtf8( newFilePath.c_str() ); |
| 595 | |
| 596 | ///Use a temporary file to save, so if Natron crashes it doesn't corrupt the user save. |
| 597 | QString tmpFilename = StandardPaths::writableLocation(StandardPaths::eStandardLocationTemp); |
| 598 | StrUtils::ensureLastPathSeparator(tmpFilename); |
| 599 | tmpFilename.append( QString::number( time.toMSecsSinceEpoch() ) ); |
| 600 | |
| 601 | { |
| 602 | FStreamsSupport::ofstream ofile; |
nothing calls this directly
no test coverage detected