OpenToonz - An open-source full-featured 2D animation creation software
C
Fix crash when saving read-only palette file
John Dancel35a3a8bd7e48
diff --git a/toonz/sources/toonzlib/studiopalette.cpp b/toonz/sources/toonzlib/studiopalette.cppindex 20b072971..9964a7c2b 100644--- a/toonz/sources/toonzlib/studiopalette.cpp+++ b/toonz/sources/toonzlib/studiopalette.cpp@@ -579,6 +579,13 @@ void StudioPalette::setStylesGlobalNames(TPalette *palette) {//-------------------------------------------------------------------void StudioPalette::save(const TFilePath &path, TPalette *palette) {+ TFileStatus fs(path);+ if (!fs.isWritable()) {+ throw TSystemException(path,+ "The studio palette cannot be saved: it is a read "+ "only studio palette.");+ }+TOStream os(path);std::map<std::string, std::string> attr;attr["name"] = ::to_string(palette->getGlobalName());diff --git a/toonz/sources/toonzlib/txshpalettelevel.cpp b/toonz/sources/toonzlib/txshpalettelevel.cppindex e24db02d7..13da70f8c 100644--- a/toonz/sources/toonzlib/txshpalettelevel.cpp+++ b/toonz/sources/toonzlib/txshpalettelevel.cpp@@ -101,6 +101,11 @@ void TXshPaletteLevel::load() {void TXshPaletteLevel::save() {TFilePath path = getScene()->decodeFilePath(m_path);if (TSystem::doesExistFileOrLevel(path) && m_palette) {+ TFileStatus fs(path);+ if (!fs.isWritable()) {+ throw TSystemException(+ path, "The palette cannot be saved: it is a read only palette.");+ }TOStream os(path);os << m_palette;}diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cppindex ddb8ace26..333d2e085 100644--- a/toonz/sources/toonzqt/paletteviewer.cpp+++ b/toonz/sources/toonzqt/paletteviewer.cpp@@ -22,6 +22,7 @@// TnzCore includes#include "tconvert.h"+#include "tsystem.h"// Qt includes#include <QVBoxLayout>@@ -894,8 +895,15 @@ void PaletteViewer::saveStudioPalette() {int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"),QObject::tr("Don't Overwrite"), 0);if (ret == 2 || ret == 0) return;- StudioPalette::instance()->save(palettePath, palette);- palette->setDirtyFlag(false);+ try {+ StudioPalette::instance()->save(palettePath, palette);+ palette->setDirtyFlag(false);+ } catch (TSystemException se) {+ QApplication::restoreOverrideCursor();+ DVGui::warning(QString::fromStdWString(se.getMessage()));+ return;+ } catch (...) {+ }}}return;