From e1c9282ee25cbe5c61ca597b6e86a8509211725e Mon Sep 17 00:00:00 2001 From: manongjohn Date: Wed, 6 Feb 2019 21:25:45 -0500 Subject: [PATCH 1/4] Backup scene file --- toonz/sources/include/toonz/preferences.h | 9 ++- toonz/sources/toonz/preferencespopup.cpp | 15 +++-- toonz/sources/toonz/preferencespopup.h | 4 +- toonz/sources/toonzlib/preferences.cpp | 10 +-- toonz/sources/toonzlib/toonzscene.cpp | 73 +++------------------- toonz/sources/toonzlib/txshsimplelevel.cpp | 11 ++-- 6 files changed, 33 insertions(+), 89 deletions(-) diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 2dc09f05..0d66221b 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -121,8 +121,8 @@ public: return m_autosaveOtherFilesEnabled; } - void enableLevelsBackup(bool enabled); - bool isLevelsBackupEnabled() const { return m_levelsBackupEnabled; } + void enableBackup(bool enabled); + bool isBackupEnabled() const { return m_backupEnabled; } void enableSceneNumbering(bool enabled); bool isSceneNumberingEnabled() const { return m_sceneNumberingEnabled; } @@ -635,9 +635,8 @@ private: m_expandFunctionHeader, m_showColumnNumbers, m_animatedGuidedDrawing; bool m_rasterOptimizedMemory, m_saveUnpaintedInCleanup, m_askForOverrideRender, m_automaticSVNFolderRefreshEnabled, m_SVNEnabled, - m_levelsBackupEnabled, m_minimizeSaveboxAfterEditing, - m_sceneNumberingEnabled, m_animationSheetEnabled, m_inksOnly, - m_startupPopupEnabled; + m_backupEnabled, m_minimizeSaveboxAfterEditing, m_sceneNumberingEnabled, + m_animationSheetEnabled, m_inksOnly, m_startupPopupEnabled; bool m_fillOnlySavebox, m_show0ThickLines, m_regionAntialias; bool m_onionSkinDuringPlayback, m_ignoreImageDpi, m_syncLevelRenumberWithXsheet; diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 73c23e4f..16ac3ca7 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -927,8 +927,8 @@ void PreferencesPopup::onLineTestFpsCapture(int index) { //----------------------------------------------------------------------------- -void PreferencesPopup::onLevelsBackupChanged(int index) { - m_pref->enableLevelsBackup(index == Qt::Checked); +void PreferencesPopup::onBackupChanged(int index) { + m_pref->enableBackup(index == Qt::Checked); } //----------------------------------------------------------------------------- @@ -1298,7 +1298,7 @@ PreferencesPopup::PreferencesPopup() m_undoMemorySize = new DVGui::IntLineEdit(this, m_pref->getUndoMemorySize(), 0, 2000); - m_levelsBackup = new CheckBox(tr("Backup Animation Levels when Saving")); + m_backup = new CheckBox(tr("Backup Scene and Animation Levels when Saving")); m_chunkSizeFld = new DVGui::IntLineEdit(this, m_pref->getDefaultTaskChunkSize(), 1, 2000); CheckBox *sceneNumberingCB = new CheckBox(tr("Show Info in Rendered Frames")); @@ -1631,7 +1631,7 @@ PreferencesPopup::PreferencesPopup() replaceAfterSaveLevelAsCB->setChecked( m_pref->isReplaceAfterSaveLevelAsEnabled()); - m_levelsBackup->setChecked(m_pref->isLevelsBackupEnabled()); + m_backup->setChecked(m_pref->isBackupEnabled()); sceneNumberingCB->setChecked(m_pref->isSceneNumberingEnabled()); watchFileSystemCB->setChecked(m_pref->isWatchFileSystemEnabled()); @@ -2017,8 +2017,7 @@ PreferencesPopup::PreferencesPopup() generalFrameLay->addWidget(replaceAfterSaveLevelAsCB, 0, Qt::AlignLeft | Qt::AlignVCenter); - generalFrameLay->addWidget(m_levelsBackup, 0, - Qt::AlignLeft | Qt::AlignVCenter); + generalFrameLay->addWidget(m_backup, 0, Qt::AlignLeft | Qt::AlignVCenter); generalFrameLay->addWidget(sceneNumberingCB, 0, Qt::AlignLeft | Qt::AlignVCenter); generalFrameLay->addWidget(watchFileSystemCB, 0, @@ -2768,8 +2767,8 @@ PreferencesPopup::PreferencesPopup() SLOT(onDragCellsBehaviourChanged(int))); ret = ret && connect(m_undoMemorySize, SIGNAL(editingFinished()), SLOT(onUndoMemorySizeChanged())); - ret = ret && connect(m_levelsBackup, SIGNAL(stateChanged(int)), - SLOT(onLevelsBackupChanged(int))); + ret = ret && connect(m_backup, SIGNAL(stateChanged(int)), + SLOT(onBackupChanged(int))); ret = ret && connect(sceneNumberingCB, SIGNAL(stateChanged(int)), SLOT(onSceneNumberingChanged(int))); ret = ret && connect(watchFileSystemCB, SIGNAL(stateChanged(int)), diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 02e1d613..d3b469fa 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -74,7 +74,7 @@ private: QPushButton *m_addLevelFormat, *m_removeLevelFormat, *m_editLevelFormat; - DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_levelsBackup, + DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_backup, *m_onionSkinVisibility, *m_pixelsOnlyCB, *m_projectRootDocuments, *m_projectRootDesktop, *m_projectRootCustom, *m_projectRootStuff, *m_onionSkinDuringPlayback, *m_autoSaveSceneCB, *m_autoSaveOtherFilesCB, @@ -147,7 +147,7 @@ private slots: void onSVNEnabledChanged(int); void onAutomaticSVNRefreshChanged(int); void onDragCellsBehaviourChanged(int); - void onLevelsBackupChanged(int); + void onBackupChanged(int); void onSceneNumberingChanged(int); void onChunkSizeChanged(); void onDefLevelTypeChanged(int); diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 79b498b3..29e2051a 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -286,7 +286,7 @@ Preferences::Preferences() , m_automaticSVNFolderRefreshEnabled(true) , m_SVNEnabled(false) , m_minimizeSaveboxAfterEditing(true) - , m_levelsBackupEnabled(false) + , m_backupEnabled(true) , m_sceneNumberingEnabled(false) , m_animationSheetEnabled(false) , m_inksOnly(false) @@ -390,7 +390,7 @@ Preferences::Preferences() getValue(*m_settings, "SVNEnabled", m_SVNEnabled); getValue(*m_settings, "minimizeSaveboxAfterEditing", m_minimizeSaveboxAfterEditing); - getValue(*m_settings, "levelsBackupEnabled", m_levelsBackupEnabled); + getValue(*m_settings, "backupEnabled", m_backupEnabled); getValue(*m_settings, "sceneNumberingEnabled", m_sceneNumberingEnabled); getValue(*m_settings, "animationSheetEnabled", m_animationSheetEnabled); getValue(*m_settings, "autosaveEnabled", m_autosaveEnabled); @@ -1433,9 +1433,9 @@ void Preferences::setDownArrowLevelStripNewFrame(bool on) { //----------------------------------------------------------------- -void Preferences::enableLevelsBackup(bool enabled) { - m_levelsBackupEnabled = enabled; - m_settings->setValue("levelsBackupEnabled", enabled ? "1" : "0"); +void Preferences::enableBackup(bool enabled) { + m_backupEnabled = enabled; + m_settings->setValue("backupEnabled", enabled ? "1" : "0"); } //----------------------------------------------------------------- diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index b0e43ac8..8fdeff38 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -169,71 +169,16 @@ void deleteUntitledScene(const TFilePath &fp) { } //----------------------------------------------------------------------------- -/*-- TODO: オプション化して復活させるか、検討のこと --*/ -/* -void saveBackup(const TFilePath &fp) -{ - if(!TFileStatus(fp).doesExist()) return; - wstring sceneName = fp.getWideName(); - TFilePath bckDir = fp.getParentDir() + "backups" + sceneName; - if(!TFileStatus(bckDir).doesExist()) - { - try {TSystem::mkDir(bckDir);} - catch(...) {return;} - } - std::map oldBackups; - TFilePathSet lst = TSystem::readDirectory(bckDir); - for(TFilePathSet::iterator it = lst.begin(); it != lst.end(); ++it) - { - TFilePath fp2 = *it; - if(fp2.getType() != "tnz" && fp2.getType() != "tab") continue; - wstring name = fp2.getWideName(); - if(name.find_first_of(L"0123456789") == wstring::npos) continue; - int i = name.find(sceneName); - if(i != wstring::npos) - name = name.substr(sceneName.size()+1); - if(name == L"" || name.find_first_not_of(L"0123456789") != wstring::npos) - continue; - int index = toInt(name); - assert(0m) - { - std::map::iterator it = oldBackups.begin(); - for(int i=0;i+m<(int)oldBackups.size();i++) - { - assert(it != oldBackups.end()); - TFilePath toKill = it->second; - try {TSystem::deleteFile(toKill); } catch(...) {} - ++it; - } - } - - TFilePath bckFp; - if(oldBackups.empty()) - { - if(fp.getType() == "tnz") - bckFp = bckDir + TFilePath(sceneName + L"_1.tnz"); - else if(fp.getType() == "tab") - bckFp = bckDir + TFilePath(sceneName + L"_1.tab"); - } - else - { - int id = oldBackups.rbegin()->first + 1; - if(fp.getType() == "tnz") - bckFp = bckDir + TFilePath(sceneName + L"_" + ::to_wstring(id) + L".tnz"); - else if(fp.getType() == "tab") - bckFp = bckDir + TFilePath(sceneName + L"_" + ::to_wstring(id) + L".tab"); - } - - TSystem::renameFile(bckFp, fp); } -*/ //----------------------------------------------------------------------------- @@ -635,7 +580,9 @@ void ToonzScene::save(const TFilePath &fp, TXsheet *subxsh) { TFilePath scenePathTemp(scenePath.getWideString() + QString(".tmp").toStdWString()); - // if(TFileStatus(scenePath).doesExist()) saveBackup(scenePath); + if (Preferences::instance()->isBackupEnabled() && + oldScenePath == newScenePath && TFileStatus(scenePath).doesExist()) + saveBackup(scenePath); if (TFileStatus(scenePathTemp).doesExist()) TSystem::removeFileOrLevel(scenePathTemp); diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index b22ae355..8b5bac1c 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -1397,8 +1397,8 @@ void TXshSimpleLevel::save(const TFilePath &fp, const TFilePath &oldFp, "The level cannot be saved: failed to access the target folder."); // backup - if (Preferences::instance()->isLevelsBackupEnabled() && - dOldPath == dDstPath && TSystem::doesExistFileOrLevel(dDstPath)) + if (Preferences::instance()->isBackupEnabled() && dOldPath == dDstPath && + TSystem::doesExistFileOrLevel(dDstPath)) saveBackup(dDstPath); if (isAreadOnlyLevel(dDstPath)) { @@ -1638,7 +1638,7 @@ void TXshSimpleLevel::saveSimpleLevel(const TFilePath &decodedFp, lw = TLevelWriterP(); // TLevelWriterP's destructor saves the palette } else if (isPaletteModified && overwritePalette) { TFilePath palettePath = decodedFp.withNoFrame().withType("tpl"); - if (Preferences::instance()->isLevelsBackupEnabled() && + if (Preferences::instance()->isBackupEnabled() && TSystem::doesExistFileOrLevel(palettePath)) saveBackup(palettePath); TOStream os(palettePath); @@ -2199,9 +2199,8 @@ TFilePath TXshSimpleLevel::getExistingHookFile( } assert(h >= 0); - return (h < 0) ? TFilePath() - : decodedLevelPath.getParentDir() + - TFilePath(hookFiles[h].toStdWString()); + return (h < 0) ? TFilePath() : decodedLevelPath.getParentDir() + + TFilePath(hookFiles[h].toStdWString()); } //----------------------------------------------------------------------------- From 3d043c55387dc59330737ecd97e0a74993de2b8d Mon Sep 17 00:00:00 2001 From: manongjohn Date: Fri, 8 Feb 2019 20:11:06 -0500 Subject: [PATCH 2/4] Change backup naming convention to use .bak --- toonz/sources/toonzlib/toonzscene.cpp | 2 +- toonz/sources/toonzlib/txshsimplelevel.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index 8fdeff38..5dab4bbc 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -172,7 +172,7 @@ void deleteUntitledScene(const TFilePath &fp) { static void saveBackup(TFilePath path) { try { - TFilePath backup = path.withName(path.getName() + "_backup"); + TFilePath backup = path.withType(path.getType() + ".bak"); if (TSystem::doesExistFileOrLevel(backup)) TSystem::removeFileOrLevel_throw(backup); TSystem::copyFileOrLevel_throw(backup, path); diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index 8b5bac1c..272574e9 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -1375,7 +1375,7 @@ void TXshSimpleLevel::save() { static void saveBackup(TFilePath path) { try { - TFilePath backup = path.withName(path.getName() + "_backup"); + TFilePath backup = path.withType(path.getType() + ".bak"); if (TSystem::doesExistFileOrLevel(backup)) TSystem::removeFileOrLevel_throw(backup); TSystem::copyFileOrLevel_throw(backup, path); From 177b7c8bac2d25d0884ebea05d9cb81263ad6939 Mon Sep 17 00:00:00 2001 From: manongjohn Date: Fri, 8 Feb 2019 21:28:00 -0500 Subject: [PATCH 3/4] Keep multiple backups preference --- toonz/sources/include/toonz/preferences.h | 5 +++ toonz/sources/toonz/preferencespopup.cpp | 40 ++++++++++++++++++---- toonz/sources/toonz/preferencespopup.h | 16 +++++---- toonz/sources/toonzlib/preferences.cpp | 11 +++++- toonz/sources/toonzlib/toonzscene.cpp | 20 ++++++++++- toonz/sources/toonzlib/txshsimplelevel.cpp | 20 ++++++++++- 6 files changed, 96 insertions(+), 16 deletions(-) diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 0d66221b..18e8e812 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -124,6 +124,9 @@ public: void enableBackup(bool enabled); bool isBackupEnabled() const { return m_backupEnabled; } + void setBackupKeepCount(int count); + int getBackupKeepCount() { return m_backupKeepCount; } + void enableSceneNumbering(bool enabled); bool isSceneNumberingEnabled() const { return m_sceneNumberingEnabled; } @@ -723,6 +726,8 @@ private: bool m_enableWinInk = false; bool m_useOnionColorsForShiftAndTraceGhosts = false; + int m_backupKeepCount; + private: Preferences(); ~Preferences(); diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 16ac3ca7..62beb771 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -927,8 +927,14 @@ void PreferencesPopup::onLineTestFpsCapture(int index) { //----------------------------------------------------------------------------- -void PreferencesPopup::onBackupChanged(int index) { - m_pref->enableBackup(index == Qt::Checked); +void PreferencesPopup::onBackupChanged(bool enabled) { + m_pref->enableBackup(enabled); +} + +//----------------------------------------------------------------------------- + +void PreferencesPopup::onBackupKeepCountChanged() { + m_pref->setBackupKeepCount(m_backupKeepCount->getValue()); } //----------------------------------------------------------------------------- @@ -1298,7 +1304,10 @@ PreferencesPopup::PreferencesPopup() m_undoMemorySize = new DVGui::IntLineEdit(this, m_pref->getUndoMemorySize(), 0, 2000); - m_backup = new CheckBox(tr("Backup Scene and Animation Levels when Saving")); + m_backup = new QGroupBox(tr("Backup Scene and Animation Levels when Saving")); + m_backup->setCheckable(true); + m_backupKeepCount = + new DVGui::IntLineEdit(this, m_pref->getBackupKeepCount(), 1); m_chunkSizeFld = new DVGui::IntLineEdit(this, m_pref->getDefaultTaskChunkSize(), 1, 2000); CheckBox *sceneNumberingCB = new CheckBox(tr("Show Info in Rendered Frames")); @@ -2017,7 +2026,24 @@ PreferencesPopup::PreferencesPopup() generalFrameLay->addWidget(replaceAfterSaveLevelAsCB, 0, Qt::AlignLeft | Qt::AlignVCenter); - generalFrameLay->addWidget(m_backup, 0, Qt::AlignLeft | Qt::AlignVCenter); + + QVBoxLayout *backupLay = new QVBoxLayout(); + backupLay->setMargin(10); + { + QHBoxLayout *backupCountLay = new QHBoxLayout(); + backupCountLay->setMargin(0); + backupCountLay->setSpacing(5); + { + backupCountLay->addWidget( + new QLabel(tr("# of backups to keep: "), this)); + backupCountLay->addWidget(m_backupKeepCount, 0); + backupCountLay->addStretch(1); + } + backupLay->addLayout(backupCountLay, 0); + } + m_backup->setLayout(backupLay); + generalFrameLay->addWidget(m_backup); + generalFrameLay->addWidget(sceneNumberingCB, 0, Qt::AlignLeft | Qt::AlignVCenter); generalFrameLay->addWidget(watchFileSystemCB, 0, @@ -2767,8 +2793,10 @@ PreferencesPopup::PreferencesPopup() SLOT(onDragCellsBehaviourChanged(int))); ret = ret && connect(m_undoMemorySize, SIGNAL(editingFinished()), SLOT(onUndoMemorySizeChanged())); - ret = ret && connect(m_backup, SIGNAL(stateChanged(int)), - SLOT(onBackupChanged(int))); + ret = ret && + connect(m_backup, SIGNAL(toggled(bool)), SLOT(onBackupChanged(bool))); + ret = ret && connect(m_backupKeepCount, SIGNAL(editingFinished()), this, + SLOT(onBackupKeepCountChanged())); ret = ret && connect(sceneNumberingCB, SIGNAL(stateChanged(int)), SLOT(onSceneNumberingChanged(int))); ret = ret && connect(watchFileSystemCB, SIGNAL(stateChanged(int)), diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index d3b469fa..b1c2546b 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -70,14 +70,14 @@ private: DVGui::IntLineEdit *m_minuteFld, *m_chunkSizeFld, *m_iconSizeLx, *m_iconSizeLy, *m_viewShrink, *m_viewStep, *m_blanksCount, *m_onionPaperThickness, *m_animationStepField, *m_undoMemorySize, - *m_xsheetStep, *m_ffmpegTimeout; + *m_xsheetStep, *m_ffmpegTimeout, *m_backupKeepCount; QPushButton *m_addLevelFormat, *m_removeLevelFormat, *m_editLevelFormat; - DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_backup, - *m_onionSkinVisibility, *m_pixelsOnlyCB, *m_projectRootDocuments, - *m_projectRootDesktop, *m_projectRootCustom, *m_projectRootStuff, - *m_onionSkinDuringPlayback, *m_autoSaveSceneCB, *m_autoSaveOtherFilesCB, + DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_onionSkinVisibility, + *m_pixelsOnlyCB, *m_projectRootDocuments, *m_projectRootDesktop, + *m_projectRootCustom, *m_projectRootStuff, *m_onionSkinDuringPlayback, + *m_autoSaveSceneCB, *m_autoSaveOtherFilesCB, *m_useNumpadForSwitchingStyles, *m_expandFunctionHeader, *m_useHigherDpiOnVectorSimplifyCB, *m_keepFillOnVectorSimplifyCB, *m_newLevelToCameraSizeCB, *m_ignoreImageDpiCB, @@ -90,7 +90,8 @@ private: DVGui::FileField *m_ffmpegPathFileFld, *m_fastRenderPathFileField, *m_lutPathFileField; - QGroupBox *m_autoSaveGroup, *m_showXSheetToolbar, *m_colorCalibration; + QGroupBox *m_autoSaveGroup, *m_showXSheetToolbar, *m_colorCalibration, + *m_backup; DVGui::ColorField *m_currentColumnColor; @@ -147,7 +148,7 @@ private slots: void onSVNEnabledChanged(int); void onAutomaticSVNRefreshChanged(int); void onDragCellsBehaviourChanged(int); - void onBackupChanged(int); + void onBackupChanged(bool enabled); void onSceneNumberingChanged(int); void onChunkSizeChanged(); void onDefLevelTypeChanged(int); @@ -221,6 +222,7 @@ private slots: void onCurrentColumnDataChanged(const TPixel32 &, bool isDragging); void onEnableWinInkChanged(int index); void onRasterBackgroundColorChanged(const TPixel32 &, bool isDragging); + void onBackupKeepCountChanged(); }; //********************************************************************************** diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 29e2051a..97cfcf97 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -347,7 +347,8 @@ Preferences::Preferences() , m_currentColumnColor(TPixel::Black) , m_enableWinInk(false) , m_useOnionColorsForShiftAndTraceGhosts(false) - , m_rasterBackgroundColor(TPixel::White) { + , m_rasterBackgroundColor(TPixel::White) + , m_backupKeepCount(1) { TCamera camera; m_defLevelType = PLI_XSHLEVEL; m_defLevelWidth = camera.getSize().lx; @@ -391,6 +392,7 @@ Preferences::Preferences() getValue(*m_settings, "minimizeSaveboxAfterEditing", m_minimizeSaveboxAfterEditing); getValue(*m_settings, "backupEnabled", m_backupEnabled); + getValue(*m_settings, "backupKeepCount", m_backupKeepCount); getValue(*m_settings, "sceneNumberingEnabled", m_sceneNumberingEnabled); getValue(*m_settings, "animationSheetEnabled", m_animationSheetEnabled); getValue(*m_settings, "autosaveEnabled", m_autosaveEnabled); @@ -1440,6 +1442,13 @@ void Preferences::enableBackup(bool enabled) { //----------------------------------------------------------------- +void Preferences::setBackupKeepCount(int count) { + m_backupKeepCount = count; + m_settings->setValue("backupKeepCount", count); +} + +//----------------------------------------------------------------- + void Preferences::enableSceneNumbering(bool enabled) { m_sceneNumberingEnabled = enabled; m_settings->setValue("sceneNumberingEnabled", enabled ? "1" : "0"); diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index 5dab4bbc..ccd1635d 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -171,8 +171,26 @@ void deleteUntitledScene(const TFilePath &fp) { //----------------------------------------------------------------------------- static void saveBackup(TFilePath path) { + int totalBackups = Preferences::instance()->getBackupKeepCount(); + totalBackups -= 1; + TFilePath backup = path.withType(path.getType() + ".bak"); + TFilePath prevBackup = + path.withType(path.getType() + ".bak" + std::to_string(totalBackups)); + while (--totalBackups >= 0) { + std::string bakExt = + ".bak" + (totalBackups > 0 ? std::to_string(totalBackups) : ""); + backup = path.withType(path.getType() + bakExt); + if (!TSystem::doesExistFileOrLevel(backup)) continue; + try { + if (TSystem::doesExistFileOrLevel(prevBackup)) + TSystem::removeFileOrLevel_throw(prevBackup); + TSystem::copyFileOrLevel_throw(prevBackup, backup); + } catch (...) { + } + prevBackup = backup; + } + try { - TFilePath backup = path.withType(path.getType() + ".bak"); if (TSystem::doesExistFileOrLevel(backup)) TSystem::removeFileOrLevel_throw(backup); TSystem::copyFileOrLevel_throw(backup, path); diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index 272574e9..50a94359 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -1374,8 +1374,26 @@ void TXshSimpleLevel::save() { //----------------------------------------------------------------------------- static void saveBackup(TFilePath path) { + int totalBackups = Preferences::instance()->getBackupKeepCount(); + totalBackups -= 1; + TFilePath backup = path.withType(path.getType() + ".bak"); + TFilePath prevBackup = + path.withType(path.getType() + ".bak" + std::to_string(totalBackups)); + while (--totalBackups >= 0) { + std::string bakExt = + ".bak" + (totalBackups > 0 ? std::to_string(totalBackups) : ""); + backup = path.withType(path.getType() + bakExt); + if (!TSystem::doesExistFileOrLevel(backup)) continue; + try { + if (TSystem::doesExistFileOrLevel(prevBackup)) + TSystem::removeFileOrLevel_throw(prevBackup); + TSystem::copyFileOrLevel_throw(prevBackup, backup); + } catch (...) { + } + prevBackup = backup; + } + try { - TFilePath backup = path.withType(path.getType() + ".bak"); if (TSystem::doesExistFileOrLevel(backup)) TSystem::removeFileOrLevel_throw(backup); TSystem::copyFileOrLevel_throw(backup, path); From 0b37bd9c635bfb2b37a5760af30632c2b8855b02 Mon Sep 17 00:00:00 2001 From: manongjohn Date: Sat, 7 Sep 2019 19:29:05 -0400 Subject: [PATCH 4/4] Fix backup ext. and sequenced files. --- toonz/sources/toonzlib/toonzscene.cpp | 11 +++++----- toonz/sources/toonzlib/txshsimplelevel.cpp | 24 ++++++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp index ccd1635d..5da6ea5f 100644 --- a/toonz/sources/toonzlib/toonzscene.cpp +++ b/toonz/sources/toonzlib/toonzscene.cpp @@ -180,12 +180,11 @@ static void saveBackup(TFilePath path) { std::string bakExt = ".bak" + (totalBackups > 0 ? std::to_string(totalBackups) : ""); backup = path.withType(path.getType() + bakExt); - if (!TSystem::doesExistFileOrLevel(backup)) continue; - try { - if (TSystem::doesExistFileOrLevel(prevBackup)) - TSystem::removeFileOrLevel_throw(prevBackup); - TSystem::copyFileOrLevel_throw(prevBackup, backup); - } catch (...) { + if (TSystem::doesExistFileOrLevel(backup)) { + try { + TSystem::copyFileOrLevel_throw(prevBackup, backup); + } catch (...) { + } } prevBackup = backup; } diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index 50a94359..94cd4c4a 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -1374,6 +1374,19 @@ void TXshSimpleLevel::save() { //----------------------------------------------------------------------------- static void saveBackup(TFilePath path) { + // The additional .bak extension keeps it from being detected as a sequence. + // If the original path is a sequence, find the individual files and back it + // up individually + if (path.isLevelName()) { + TFilePathSet files = + TSystem::readDirectory(path.getParentDir(), false, true); + for (TFilePathSet::iterator file = files.begin(); file != files.end(); + file++) { + if (file->getLevelName() == path.getLevelName()) saveBackup(*file); + } + return; + } + int totalBackups = Preferences::instance()->getBackupKeepCount(); totalBackups -= 1; TFilePath backup = path.withType(path.getType() + ".bak"); @@ -1383,12 +1396,11 @@ static void saveBackup(TFilePath path) { std::string bakExt = ".bak" + (totalBackups > 0 ? std::to_string(totalBackups) : ""); backup = path.withType(path.getType() + bakExt); - if (!TSystem::doesExistFileOrLevel(backup)) continue; - try { - if (TSystem::doesExistFileOrLevel(prevBackup)) - TSystem::removeFileOrLevel_throw(prevBackup); - TSystem::copyFileOrLevel_throw(prevBackup, backup); - } catch (...) { + if (TSystem::doesExistFileOrLevel(backup)) { + try { + TSystem::copyFileOrLevel_throw(prevBackup, backup); + } catch (...) { + } } prevBackup = backup; }