fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / filesystem_paths.cc
index 231bc84a3c2e2dee1e8bbcf85688550ae8a85b20..47b9994cc6c9229e6090e0f5128d98d50872e455 100644 (file)
@@ -29,7 +29,7 @@
 #include "ardour/directory_names.h"
 #include "ardour/filesystem_paths.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 #ifdef PLATFORM_WINDOWS
 #include "shlobj.h"
@@ -49,14 +49,29 @@ user_config_directory_name (int version = -1)
                version = atoi (X_(PROGRAM_VERSION));
        }
 
+       /* ARDOUR::Profile may not be available when this is
+          called, so rely on build-time detection of the
+          product name etc.
+       */
+
+#ifdef USE_TRACKS_CODE_FEATURES
+       /* Tracks does not use versioned configuration folders, which may or
+          may not be problematic in the future.
+       */
+       return X_(PROGRAM_NAME);
+
+#else
        const string config_dir_name = string_compose ("%1%2", X_(PROGRAM_NAME), version);
 
 #if defined (__APPLE__) || defined (PLATFORM_WINDOWS)
+       /* Use mixed-case folder name on OS X and Windows */
        return config_dir_name;
 #else
+       /* use lower case folder name on Linux */
        return downcase (config_dir_name);
 #endif
-}      
+#endif
+}
 
 std::string
 user_config_directory (int version)
@@ -107,9 +122,9 @@ user_config_directory (int version)
                                exit (1);
                        }
                        } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
-                       error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
+                       fatal << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
                                                 p) << endmsg;
-                       exit (1);
+                       abort(); /*NOTREACHED*/
                }
        }
 
@@ -173,9 +188,9 @@ user_cache_directory ()
                        exit (1);
                }
        } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
-               error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
+               fatal << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
                                           p) << endmsg;
-               exit (1);
+               abort(); /*NOTREACHED*/
        }
 
        return p;
@@ -185,7 +200,7 @@ std::string
 ardour_dll_directory ()
 {
 #ifdef PLATFORM_WINDOWS
-       std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
+       std::string dll_dir_path(windows_package_directory_path());
        dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
        return Glib::build_filename (dll_dir_path, LIBARDOUR);
 #else
@@ -193,7 +208,7 @@ ardour_dll_directory ()
        if (s.empty()) {
                std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
                ::exit (1);
-       }       
+       }
        return s;
 #endif
 }
@@ -202,10 +217,27 @@ ardour_dll_directory ()
 Searchpath
 windows_search_path ()
 {
-       std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
+       std::string dll_dir_path(windows_package_directory_path());
        dll_dir_path = Glib::build_filename (dll_dir_path, "share");
        return Glib::build_filename (dll_dir_path, LIBARDOUR);
 }
+
+std::string
+windows_package_directory_path ()
+{
+       char* package_dir =
+           g_win32_get_package_installation_directory_of_module (NULL);
+
+       if (package_dir == NULL) {
+               fatal << string_compose (_("Cannot determine %1 package directory"),
+                                          PROGRAM_NAME) << endmsg;
+               abort(); /*NOTREACHED*/
+       }
+
+       std::string package_dir_path(package_dir);
+       g_free(package_dir);
+       return package_dir_path;
+}
 #endif
 
 Searchpath