When config migration occurs, log a message and show a notice dialog

presentation
Bryan Tan 6 years ago committed by Bryan Tan
parent 93433f74e2
commit d425bb3374
  1. 22
      src/control/XournalMain.cpp
  2. 6
      src/control/XournalMain.h
  3. 7
      src/util/Util.cpp
  4. 4
      src/util/Util.h

@ -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();

@ -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);

@ -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);

@ -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 = "");

Loading…
Cancel
Save