OpenToonz - An open-source full-featured 2D animation creation software
C
Fix crash on using preference template (#1456)
shun-iwasawa5e6203f300c0
diff --git a/toonz/sources/common/tsystem/tsystem.cpp b/toonz/sources/common/tsystem/tsystem.cppindex 8e1a1413a..faffa219b 100644--- a/toonz/sources/common/tsystem/tsystem.cpp+++ b/toonz/sources/common/tsystem/tsystem.cpp@@ -362,6 +362,9 @@ void TSystem::copyFile(const TFilePath &dst, const TFilePath &src,if (dst == src) return;+ // Create the containing folder before trying to copy or it will crash!+ touchParentDir(dst);+const QString &qDst = toQString(dst);if (overwrite && QFile::exists(qDst)) QFile::remove(qDst);diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cppindex 912720961..f683a56fb 100644--- a/toonz/sources/toonzlib/preferences.cpp+++ b/toonz/sources/toonzlib/preferences.cpp@@ -325,13 +325,19 @@ Preferences::Preferences()m_defLevelDpi = camera.getDpi().x;TFilePath layoutDir = ToonzFolder::getMyModuleDir();- TFilePath savePath = layoutDir + TFilePath("preferences.ini");-- // If no personal settings found, then try to load template settings- TFilePath loadPath = ToonzFolder::getModuleFile(TFilePath("preferences.ini"));+ TFilePath prefPath = layoutDir + TFilePath("preferences.ini");++ // In case the personal settings is not exist (for new users)+ if (!TFileStatus(prefPath).doesExist()) {+ TFilePath templatePath =+ ToonzFolder::getTemplateModuleDir() + TFilePath("preferences.ini");+ // If there is the template, copy it to the personal one+ if (TFileStatus(templatePath).doesExist())+ TSystem::copyFile(prefPath, templatePath);+ }m_settings.reset(new QSettings(- QString::fromStdWString(loadPath.getWideString()), QSettings::IniFormat));+ QString::fromStdWString(prefPath.getWideString()), QSettings::IniFormat));getValue(*m_settings, "autoExposeEnabled", m_autoExposeEnabled);getValue(*m_settings, "autoCreateEnabled", m_autoCreateEnabled);@@ -606,16 +612,6 @@ Preferences::Preferences()m_inputCellsWithoutDoubleClickingEnabled);getValue(*m_settings, "importPolicy", m_importPolicy);getValue(*m_settings, "watchFileSystemEnabled", m_watchFileSystem);-- // in case there is no personal settings- if (savePath != loadPath) {- // copy the template settins to the personal one- if (TFileStatus(loadPath).doesExist())- TSystem::copyFile(savePath, loadPath);- m_settings.reset(- new QSettings(QString::fromStdWString(savePath.getWideString()),- QSettings::IniFormat));- }}//-----------------------------------------------------------------