From 88013f3f45af5249b7d1de12d495426137095a5c Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 31 Oct 2007 21:53:05 +0000 Subject: [PATCH] improved detection of old gimp user directories and handle migration from 2007-10-31 Sven Neumann * app/core/gimp-user-install.c: improved detection of old gimp user directories and handle migration from 2.4. svn path=/trunk/; revision=24023 --- ChangeLog | 5 ++ app/core/gimp-user-install.c | 95 +++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index b09e2c0388..80ecdfff09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-31 Sven Neumann + + * app/core/gimp-user-install.c: improved detection of old gimp + user directories and handle migration from 2.4. + 2007-10-31 Michael Natterer * app/core/gimpparamspecs.[ch] (GimpParamSpecString): remove diff --git a/app/core/gimp-user-install.c b/app/core/gimp-user-install.c index ca613eae5b..52f8ec4c16 100644 --- a/app/core/gimp-user-install.c +++ b/app/core/gimp-user-install.c @@ -104,6 +104,7 @@ gimp_user_install_items[] = }; +static gboolean gimp_user_install_detect_old (GimpUserInstall *install); static void user_install_log (GimpUserInstall *install, const gchar *format, ...) G_GNUC_PRINTF (2, 3); @@ -131,54 +132,10 @@ GimpUserInstall * gimp_user_install_new (gboolean verbose) { GimpUserInstall *install = g_slice_new0 (GimpUserInstall); - gchar *dir; - gchar *version; - gboolean migrate; install->verbose = verbose; - dir = g_strdup (gimp_directory ()); - - version = strstr (dir, GIMP_APP_VERSION); - - if (! version) - { - g_free (dir); - return install; - } - - /* we assume that GIMP_APP_VERSION is in the form '2.x' */ - version[2] = '2'; - - migrate = g_file_test (dir, G_FILE_TEST_IS_DIR); - - if (migrate) - { - install->old_major = 2; - install->old_minor = 2; - } - else - { - version[2] = '0'; - - migrate = g_file_test (dir, G_FILE_TEST_IS_DIR); - - if (migrate) - { - install->old_major = 2; - install->old_minor = 0; - } - } - - if (migrate) - { - install->old_dir = dir; - install->migrate = (const gchar *) version; - } - else - { - g_free (dir); - } + gimp_user_install_detect_old (install); return install; } @@ -241,6 +198,54 @@ gimp_user_install_set_log_handler (GimpUserInstall *install, /* Local functions */ +static gboolean +gimp_user_install_detect_old (GimpUserInstall *install) +{ + gchar *dir; + gchar *version; + gboolean migrate = FALSE; + + dir = g_strdup (gimp_directory ()); + + version = strstr (dir, GIMP_APP_VERSION); + + if (version) + { + gint i; + + for (i = 4; i >= 0; i -= 2) + { + /* we assume that GIMP_APP_VERSION is in the form '2.x' */ + g_snprintf (version + 2, 2, "%d", i); + + migrate = g_file_test (dir, G_FILE_TEST_IS_DIR); + +#ifdef GIMP_UNSTABLE + g_printerr ("gimp-user-install: migrating from %s\n", dir); +#endif + if (migrate) + { + install->old_major = 2; + install->old_minor = i; + + break; + } + } + } + + if (migrate) + { + install->old_dir = dir; + install->migrate = (const gchar *) version; + } + else + { + g_free (dir); + } + + return migrate; +} + static void user_install_log (GimpUserInstall *install, const gchar *format,