rework check for old configuration files
authorRobin Gareus <robin@gareus.org>
Mon, 23 Mar 2015 17:31:55 +0000 (18:31 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 23 Mar 2015 17:31:55 +0000 (18:31 +0100)
check early on (before announcement-check, bundle-
env and ARDOUR_UI ctor have a chance to create the
new config dir)

gtk2_ardour/ardour_ui.cc
gtk2_ardour/bundle_env_linux.cc
gtk2_ardour/main.cc
libs/ardour/ardour/ardour.h
libs/ardour/globals.cc

index 0c73609f3ce8f631e861f76e6abad5f7196228e8..443bba7057fa0cfc85c207add0a510f51597b88c 100644 (file)
@@ -238,7 +238,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
 {
        Gtkmm2ext::init(localedir);
 
-       if (ARDOUR::check_for_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
+       if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
                MessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true);
                msg.run ();
                /* configuration was modified, exit immediately */
index a7027506fe81abe4f1dd5208fdbfc5fa097f7396..54404b14fb7fa83ae5376432edb54965926ee54e 100644 (file)
@@ -60,7 +60,6 @@ fixup_bundle_environment (int /*argc*/, char* argv[], const char** localedir)
 
        std::string path;
        std::string dir_path = Glib::path_get_dirname (Glib::path_get_dirname (argv[0]));
-       std::string userconfigdir = user_config_directory();
 
 #ifdef ENABLE_NLS
        if (!ARDOUR::translations_are_enabled ()) {
index 998337ed0994b3a8b499bf3a9dd8fea0b7599950..42f94522c2d31dd9435e0e547655bf3f182918c5 100644 (file)
@@ -251,6 +251,8 @@ int ardour_main (int argc, char *argv[])
 int main (int argc, char *argv[])
 #endif
 {
+       ARDOUR::check_for_old_configuration_files();
+
        fixup_bundle_environment (argc, argv, &localedir);
 
        load_custom_fonts(); /* needs to happen before any gtk and pango init calls */
index 3865ce6eceae39dddb6ee4e52f5c30420a529ebc..8be99a4aba86b2adf93b5aef6a18f3c09dcc202e 100644 (file)
@@ -88,7 +88,8 @@ namespace ARDOUR {
         * action, and return true or false depending on whether or not the
         * copy should take place.
         */
-       LIBARDOUR_API int check_for_old_configuration_files (boost::function<bool (std::string const&, std::string const&, int)> ui_handler);
+       LIBARDOUR_API void check_for_old_configuration_files ();
+       LIBARDOUR_API int handle_old_configuration_files (boost::function<bool (std::string const&, std::string const&, int)> ui_handler);
 }
 
 #endif /* __ardour_ardour_h__ */
index f097ce84f57c95c8fc7745906905125e104fe679..6e16d5480fff557d3d6a3d486fed7d27975c2bdb 100644 (file)
@@ -138,6 +138,8 @@ PBD::Signal1<void,int> ARDOUR::PluginScanTimeout;
 PBD::Signal0<void> ARDOUR::GUIIdle;
 PBD::Signal3<bool,std::string,std::string,int> ARDOUR::CopyConfigurationFiles;
 
+static bool have_old_configuration_files = false;
+
 namespace ARDOUR {
 extern void setup_enum_writer ();
 }
@@ -263,6 +265,11 @@ copy_configuration_files (string const & old_dir, string const & new_dir, int ol
 
                copy_file (old_name, new_name);
 
+               old_name = Glib::build_filename (old_dir, X_("sfdb"));
+               new_name = Glib::build_filename (new_dir, X_("sfdb"));
+
+               copy_file (old_name, new_name);
+
                /* can only copy ardour.rc - UI config is not compatible */
 
                old_name = Glib::build_filename (old_dir, X_("ardour.rc"));
@@ -314,31 +321,43 @@ copy_configuration_files (string const & old_dir, string const & new_dir, int ol
        return 0;
 }
 
-int
-ARDOUR::check_for_old_configuration_files (boost::function<bool (std::string const&, std::string const&, int)> ui_handler)
+void
+ARDOUR::check_for_old_configuration_files ()
 {
        int current_version = atoi (X_(PROGRAM_VERSION));
        
        if (current_version <= 1) {
-               return 0;
+               return;
        }
 
        int old_version = current_version - 1;
 
        string old_config_dir = user_config_directory (old_version);
        /* pass in the current version explicitly to avoid creation */
-       string current_config_dir = user_config_directory (current_version); 
+       string current_config_dir = user_config_directory (current_version);
 
        if (!Glib::file_test (current_config_dir, Glib::FILE_TEST_IS_DIR)) {
                if (Glib::file_test (old_config_dir, Glib::FILE_TEST_IS_DIR)) {
-                       
-                       if (ui_handler (old_config_dir, current_config_dir, old_version)) {
-                               copy_configuration_files (old_config_dir, current_config_dir, old_version);
-                               return 1;
-                       }
+                       have_old_configuration_files = true;
                }
        }
+}
 
+int
+ARDOUR::handle_old_configuration_files (boost::function<bool (std::string const&, std::string const&, int)> ui_handler)
+{
+       if (have_old_configuration_files) {
+               int current_version = atoi (X_(PROGRAM_VERSION));
+               assert (current_version > 1); // established in check_for_old_configuration_files ()
+               int old_version = current_version - 1;
+               string old_config_dir = user_config_directory (old_version);
+               string current_config_dir = user_config_directory (current_version);
+
+               if (ui_handler (old_config_dir, current_config_dir, old_version)) {
+                       copy_configuration_files (old_config_dir, current_config_dir, old_version);
+                       return 1;
+               }
+       }
        return 0;
 }