Handle export presets from config dirs properly. Removed some debug output.
[ardour.git] / libs / ardour / export_profile_manager.cc
index 86b586d8e0ce5a964e02af7bb0010eb0f9c3704f..600ce9e3ea9654bc636d37a2e30959ebf7c7b232 100644 (file)
@@ -60,19 +60,12 @@ ExportProfileManager::ExportProfileManager (Session & s) :
 
        /* Initialize path variables */
 
-       sys::path path;
-
        export_config_dir = user_config_directory();
        export_config_dir /= "export";
        search_path += export_config_dir;
        
-       path = ardour_search_path().to_string();
-       path /= "export";
-       search_path += path;
-       
-       path = system_config_search_path().to_string();
-       path /= "export";
-       search_path += path;
+       search_path += ardour_search_path().add_subdirectory_to_paths("export");
+       search_path += system_config_search_path().add_subdirectory_to_paths("export");;
        
        /* create export config directory if necessary */
 
@@ -94,6 +87,8 @@ ExportProfileManager::ExportProfileManager (Session & s) :
 
 ExportProfileManager::~ExportProfileManager ()
 {
+       if (single_range_mode) { return; }
+       
        XMLNode * instant_xml (new XMLNode ("ExportProfile"));
        serialize_profile (*instant_xml);
        session.add_instant_xml (*instant_xml, false);
@@ -166,8 +161,9 @@ ExportProfileManager::load_presets ()
 ExportProfileManager::PresetPtr
 ExportProfileManager::save_preset (string const & name)
 {
+       string filename = export_config_dir.to_string() + "/" + name + export_preset_suffix;
+
        if (!current_preset) {
-               string filename = export_config_dir.to_string() + "/" + name + export_preset_suffix;
                current_preset.reset (new ExportPreset (filename, session));
                preset_list.push_back (current_preset);
        }
@@ -182,7 +178,7 @@ ExportProfileManager::save_preset (string const & name)
        current_preset->set_global_state (*global_preset);
        current_preset->set_local_state (*local_preset);
        
-       current_preset->save();
+       current_preset->save (filename);
        
        return current_preset;
 }
@@ -213,12 +209,13 @@ void
 ExportProfileManager::load_preset_from_disk (PBD::sys::path const & path)
 {
        PresetPtr preset (new ExportPreset (path.to_string(), session));
-       preset_list.push_back (preset);
        
-       /* Handle id to filename mapping */
+       /* Handle id to filename mapping and don't add duplicates to list */
        
        FilePair pair (preset->id(), path);
-       preset_file_map.insert (pair);
+       if (preset_file_map.insert (pair).second) {
+               preset_list.push_back (preset);
+       }
 }
 
 bool
@@ -478,19 +475,31 @@ ExportProfileManager::save_format_to_disk (FormatPtr format)
        /* Check if format is on disk already */
        FileMap::iterator it;
        if ((it = format_file_map.find (format->id())) != format_file_map.end()) {
-               /* Update data */
-               {
-                       XMLTree tree (it->second.to_string());
+               
+               /* Check if config is not in user config dir */
+               if (it->second.branch_path().to_string().compare (export_config_dir.to_string())) {
+               
+                       /* Write new file */
+               
+                       XMLTree tree (new_path.to_string());
                        tree.set_root (&format->get_state());
                        tree.write();
-               }
                
-               /* Rename if necessary */
+               } else {
                
-               if (new_name.compare (it->second.leaf())) {
-                       sys::rename (it->second, new_path);
+                       /* Update file and rename if necessary */
+               
+                       XMLTree tree (it->second.to_string());
+                       tree.set_root (&format->get_state());
+                       tree.write();
+                       
+                       if (new_name.compare (it->second.leaf())) {
+                               sys::rename (it->second, new_path);
+                       }
                }
                
+               it->second = new_path;
+               
        } else {
                /* Write new file */
                
@@ -610,12 +619,13 @@ ExportProfileManager::load_format_from_disk (PBD::sys::path const & path)
 {
        XMLTree const tree (path.to_string());
        FormatPtr format = handler->add_format (*tree.root());
-       format_list->push_back (format);
        
-       /* Handle id to filename mapping */
+       /* Handle id to filename mapping and don't add duplicates to list */
        
        FilePair pair (format->id(), path);
-       format_file_map.insert (pair);
+       if (format_file_map.insert (pair).second) {
+               format_list->push_back (format);
+       }
        
        FormatListChanged ();
 }