Fix crash when saving read-only palette file
This commit is contained in:
parent
41fdd18cf8
commit
35a3a8bd7e
3 changed files with 22 additions and 2 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue