Skip to content

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

C

Backup scene file

manongjohne1c9282ee25c
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h
index 2dc09f055..0d66221bb 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 73c23e4f2..16ac3ca77 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 02e1d6139..d3b469fa6 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 79b498b32..29e2051af 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 b0e43ac81..8fdeff387 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<int, TFilePath> 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(0<index);
- assert(oldBackups.count(index)==0);
- oldBackups[index] = fp2;
- }
-
- int m = 3;
- if((int)oldBackups.size()>m)
- {
- std::map<int, TFilePath>::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");
+static void saveBackup(TFilePath path) {
+ try {
+ TFilePath backup = path.withName(path.getName() + "_backup");
+ if (TSystem::doesExistFileOrLevel(backup))
+ TSystem::removeFileOrLevel_throw(backup);
+ TSystem::copyFileOrLevel_throw(backup, path);
+ } catch (...) {
}
-
- 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 b22ae3553..8b5bac1c8 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());
}
//-----------------------------------------------------------------------------