diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index c1a46ece..8effa5ba 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -72,19 +72,22 @@ void XournalMain::initLocalisation() { std::cout.imbue(std::locale()); } -void XournalMain::migrateSettings() { - Path newConfigPath(g_get_user_config_dir()); - newConfigPath /= g_get_prgname(); +bool XournalMain::migrateSettings() { + Path newConfigPath = Util::getConfigFolder(); if (!newConfigPath.exists()) { Path oldConfigPath(g_get_home_dir()); oldConfigPath /= ".xournalpp"; if (oldConfigPath.exists()) { + g_message("Migrating configuration from %s to %s", oldConfigPath.str().c_str(), + newConfigPath.str().c_str()); fs::create_directories(newConfigPath.str()); fs::copy(oldConfigPath.str(), newConfigPath.str(), fs::copy_options::recursive); + return true; } } + return false; } void XournalMain::checkForErrorlog() { @@ -276,7 +279,7 @@ auto XournalMain::exportPdf(const char* input, const char* output) -> int { auto XournalMain::run(int argc, char* argv[]) -> int { g_set_prgname("com.github.xournalpp.xournalpp"); this->initLocalisation(); - this->migrateSettings(); + bool hasMigrated = this->migrateSettings(); GError* error = nullptr; GOptionContext* context = g_option_context_new("FILE"); @@ -393,6 +396,17 @@ auto XournalMain::run(int argc, char* argv[]) -> int { // This fixes it, see #405 Util::execInUiThread([=]() { control->getWindow()->getXournal()->layoutPages(); }); + if (hasMigrated) { + Util::execInUiThread([=]() { + Path oldConfigPath(g_get_home_dir()); + oldConfigPath /= ".xournalpp"; + const char* msg = "Due to a recent update, Xournal++ has changed where its configuration files are " + "stored.\nThey have been automatically copied from\n{1}\nto\n{2}"; + XojMsgBox::showErrorToUser(control->getGtkWindow(), + FS(_F(msg) % oldConfigPath.c_str() % Util::getConfigFolder().c_str())); + }); + } + gtk_main(); control->saveSettings(); diff --git a/src/control/XournalMain.h b/src/control/XournalMain.h index f0cfac86..756e3743 100644 --- a/src/control/XournalMain.h +++ b/src/control/XournalMain.h @@ -31,7 +31,11 @@ public: private: static void initLocalisation(); - static void migrateSettings(); + + /** + * Returns true if configuration settings were migrated. + */ + static bool migrateSettings(); static void checkForErrorlog(); static void checkForEmergencySave(Control* control); diff --git a/src/util/Util.cpp b/src/util/Util.cpp index 6ded130b..07541ce7 100644 --- a/src/util/Util.cpp +++ b/src/util/Util.cpp @@ -80,9 +80,14 @@ auto Util::getAutosaveFilename() -> Path { return p; } -auto Util::getConfigSubfolder(const Path& subfolder) -> Path { +auto Util::getConfigFolder() -> Path { Path p(g_get_user_config_dir()); p /= g_get_prgname(); + return p; +} + +auto Util::getConfigSubfolder(const Path& subfolder) -> Path { + Path p = getConfigFolder(); p /= subfolder; return Util::ensureFolderExists(p); diff --git a/src/util/Util.h b/src/util/Util.h index 42e89532..c9466f30 100644 --- a/src/util/Util.h +++ b/src/util/Util.h @@ -38,6 +38,10 @@ pid_t getPid(); void openFileWithDefaultApplicaion(const Path& filename); void openFileWithFilebrowser(const Path& filename); +/** + * Return the configuration folder path (may not be guaranteed to exist). + */ +Path getConfigFolder(); Path getConfigSubfolder(const Path& subfolder = ""); Path getCacheSubfolder(const Path& subfolder = ""); Path getDataSubfolder(const Path& subfolder = "");