From f9e47b27028b7f513cea29843249894ae105ebc7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Sat, 8 Aug 2020 17:03:20 +0200 Subject: [PATCH] Code refactoring: AppConfig.cpp(hpp) are removed from the GUI to libslic3r --- src/PrusaSlicer.cpp | 2 +- src/{slic3r/GUI => libslic3r}/AppConfig.cpp | 12 +++++++++--- src/{slic3r/GUI => libslic3r}/AppConfig.hpp | 3 ++- src/libslic3r/CMakeLists.txt | 2 ++ src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PresetBundle.hpp | 3 +-- src/slic3r/CMakeLists.txt | 2 -- src/slic3r/Config/Snapshot.cpp | 1 - src/slic3r/GUI/3DScene.cpp | 2 +- src/slic3r/GUI/Camera.cpp | 2 +- src/slic3r/GUI/ConfigWizard_private.hpp | 1 - src/slic3r/GUI/GUI_App.cpp | 9 +++++++-- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 1 - src/slic3r/GUI/MainFrame.cpp | 1 - src/slic3r/GUI/Mouse3DController.cpp | 1 - src/slic3r/GUI/Preferences.cpp | 2 +- src/slic3r/GUI/PrintHostDialogs.cpp | 2 +- 17 files changed, 27 insertions(+), 21 deletions(-) rename src/{slic3r/GUI => libslic3r}/AppConfig.cpp (97%) rename src/{slic3r/GUI => libslic3r}/AppConfig.hpp (99%) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index a0422f5fa..c37afb805 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -44,6 +44,7 @@ #include "libslic3r/Format/OBJ.hpp" #include "libslic3r/Format/SL1.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/AppConfig.hpp" #include "PrusaSlicer.hpp" @@ -52,7 +53,6 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/InstanceCheck.hpp" - #include "slic3r/GUI/AppConfig.hpp" #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Plater.hpp" #endif /* SLIC3R_GUI */ diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/libslic3r/AppConfig.cpp similarity index 97% rename from src/slic3r/GUI/AppConfig.cpp rename to src/libslic3r/AppConfig.cpp index 93589e536..8b41bd271 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -15,8 +15,8 @@ #include #include -#include -#include "I18N.hpp" +//#include +//#include "I18N.hpp" namespace Slic3r { @@ -110,7 +110,7 @@ void AppConfig::set_defaults() erase("", "object_settings_size"); } -void AppConfig::load() +std::string AppConfig::load() { // 1) Read the complete config file into a boost::property_tree. namespace pt = boost::property_tree; @@ -120,10 +120,15 @@ void AppConfig::load() pt::read_ini(ifs, tree); } catch (pt::ptree_error& ex) { // Error while parsing config file. We'll customize the error message and rethrow to be displayed. + // ! But to avoid the use of _utf8 (related to use of wxWidgets) + // we will rethrow this exception from the place of load() call, if returned value wouldn't be empty + /* throw std::runtime_error( _utf8(L("Error parsing PrusaSlicer config file, it is probably corrupted. " "Try to manually delete the file to recover from the error. Your user profiles will not be affected.")) + "\n\n" + AppConfig::config_path() + "\n\n" + ex.what()); + */ + return ex.what(); } // 2) Parse the property_tree, extract the sections and key / value pairs. @@ -169,6 +174,7 @@ void AppConfig::load() // Override missing or keys with their defaults. this->set_defaults(); m_dirty = false; + return ""; } void AppConfig::save() diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/libslic3r/AppConfig.hpp similarity index 99% rename from src/slic3r/GUI/AppConfig.hpp rename to src/libslic3r/AppConfig.hpp index 1e90d32e0..ffd1b9fdf 100644 --- a/src/slic3r/GUI/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -29,7 +29,8 @@ public: void set_defaults(); // Load the slic3r.ini from a user profile directory (or a datadir, if configured). - void load(); + // return error string or empty strinf + std::string load(); // Store the slic3r.ini into a user profile directory (or a datadir, if configured). void save(); diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index f11a6e7c2..290b8953c 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -151,6 +151,8 @@ add_library(libslic3r STATIC Preset.hpp PresetBundle.cpp PresetBundle.hpp + AppConfig.cpp + AppConfig.hpp Print.cpp Print.hpp PrintBase.cpp diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 44e6675d1..7176ca81a 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1,7 +1,7 @@ #include #include "Preset.hpp" -#include "slic3r/GUI/AppConfig.hpp" +#include "AppConfig.hpp" #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 2906584d3..567a12331 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -2,13 +2,12 @@ #define slic3r_PresetBundle_hpp_ #include "Preset.hpp" +#include "AppConfig.hpp" #include #include #include -#include "slic3r/GUI/AppConfig.hpp" - namespace Slic3r { // Bundle of Print + Filament + Printer presets. diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 849460792..f8598cea0 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -12,8 +12,6 @@ set(SLIC3R_GUI_SOURCES GUI/SysInfoDialog.hpp GUI/KBShortcutsDialog.cpp GUI/KBShortcutsDialog.hpp - GUI/AppConfig.cpp - GUI/AppConfig.hpp GUI/BackgroundSlicingProcess.cpp GUI/BackgroundSlicingProcess.hpp GUI/BitmapCache.cpp diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp index f7d313418..30596b614 100644 --- a/src/slic3r/Config/Snapshot.cpp +++ b/src/slic3r/Config/Snapshot.cpp @@ -1,5 +1,4 @@ #include "Snapshot.hpp" -#include "../GUI/AppConfig.hpp" #include diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 5dc0d430f..d683fd90c 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -10,7 +10,6 @@ #if ENABLE_ENVIRONMENT_MAP #include "GUI_App.hpp" #include "Plater.hpp" -#include "AppConfig.hpp" #endif // ENABLE_ENVIRONMENT_MAP #include "libslic3r/ExtrusionEntity.hpp" @@ -24,6 +23,7 @@ #include "slic3r/GUI/BitmapCache.hpp" #include "libslic3r/Format/STL.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/AppConfig.hpp" #include #include diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index ac32767c4..c1bf8e825 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -1,8 +1,8 @@ #include "libslic3r/libslic3r.h" +#include "libslic3r/AppConfig.hpp" #include "Camera.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #if ENABLE_CAMERA_STATISTICS #include "Mouse3DController.hpp" #endif // ENABLE_CAMERA_STATISTICS diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index be2919861..9921552a7 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -22,7 +22,6 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/PresetBundle.hpp" #include "slic3r/Utils/PresetUpdater.hpp" -#include "AppConfig.hpp" #include "BedShapeDialog.hpp" #include "GUI.hpp" #include "wxExtensions.hpp" diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 38bda5f5e..82c2861bc 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -38,7 +38,6 @@ #include "GUI.hpp" #include "GUI_Utils.hpp" -#include "AppConfig.hpp" #include "3DScene.hpp" #include "MainFrame.hpp" #include "Plater.hpp" @@ -326,7 +325,13 @@ void GUI_App::init_app_config() // load settings app_conf_exists = app_config->exists(); if (app_conf_exists) { - app_config->load(); + std::string error = app_config->load(); + if (!error.empty()) + // Error while parsing config file. We'll customize the error message and rethrow to be displayed. + throw std::runtime_error( + _u8L("Error parsing PrusaSlicer config file, it is probably corrupted. " + "Try to manually delete the file to recover from the error. Your user profiles will not be affected.") + + "\n\n" + AppConfig::config_path() + "\n\n" + error); } } diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index cc779df2a..2d5d5b072 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -2,7 +2,6 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/AppConfig.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/Utils/SLAImport.hpp" diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 084280300..bbc1da534 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -20,7 +20,6 @@ #include "Tab.hpp" #include "ProgressStatusBar.hpp" #include "3DScene.hpp" -#include "AppConfig.hpp" #include "PrintHostDialogs.hpp" #include "wxExtensions.hpp" #include "GUI_ObjectList.hpp" diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 9bbbf92a0..4c5ee2076 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -4,7 +4,6 @@ #include "Camera.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #include "GLCanvas3D.hpp" #include "Plater.hpp" #include "NotificationManager.hpp" diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 4b5808e16..242c3d851 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1,8 +1,8 @@ #include "Preferences.hpp" -#include "AppConfig.hpp" #include "OptionsGroup.hpp" #include "GUI_App.hpp" #include "I18N.hpp" +#include "libslic3r/AppConfig.hpp" namespace Slic3r { namespace GUI { diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index bae60e47f..216af5df4 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -15,11 +15,11 @@ #include "GUI.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #include "MsgDialog.hpp" #include "I18N.hpp" #include "../Utils/PrintHost.hpp" #include "wxExtensions.hpp" +#include "libslic3r/AppConfig.hpp" namespace fs = boost::filesystem;