From 5e6203f300c0004b96e41f74dc9a03f4c20d0b8d Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Sep 08 2017 05:26:03 +0000 Subject: Fix crash on using preference template (#1456) * fix crash on using preference template --- diff --git a/toonz/sources/common/tsystem/tsystem.cpp b/toonz/sources/common/tsystem/tsystem.cpp index 8e1a141..faffa21 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.cpp index 9127209..f683a56 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)); - } } //-----------------------------------------------------------------