Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Keep multiple backups preference

manongjohn177b7c8bac2d
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h
index 0d66221bb..18e8e8121 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 16ac3ca77..62beb7715 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 d3b469fa6..b1c2546b0 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 29e2051af..97cfcf977 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 5dab4bbc6..ccd1635dc 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 272574e9b..50a943591 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);