X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Ffilesystem_paths.cc;h=fcdf42cbbef8db57425bee1170a0cc83e99be407;hb=dac57703ccd7205ac94c14b407b802a69f4187f1;hp=ded481c54d90cebaf02f60158e37db37c0882c4d;hpb=5584f46003e6ac49432ab772b9ee1ad1dc9c797f;p=ardour.git diff --git a/libs/ardour/filesystem_paths.cc b/libs/ardour/filesystem_paths.cc index ded481c54d..fcdf42cbbe 100644 --- a/libs/ardour/filesystem_paths.cc +++ b/libs/ardour/filesystem_paths.cc @@ -19,8 +19,9 @@ #include #include -#include "pbd/error.h" #include "pbd/compose.h" +#include "pbd/convert.h" +#include "pbd/error.h" #include #include @@ -41,12 +42,41 @@ namespace ARDOUR { using std::string; -std::string -user_config_directory () +static std::string +user_config_directory_name (int version = -1) { - static std::string p; + if (version < 0) { + version = atoi (X_(PROGRAM_VERSION)); + } - if (!p.empty()) return p; + /* 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) +{ + std::string p; #ifdef __APPLE__ @@ -79,18 +109,23 @@ user_config_directory () } #endif // end not __APPLE__ - p = Glib::build_filename (p, user_config_dir_name); + p = Glib::build_filename (p, user_config_directory_name (version)); - if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) { - if (g_mkdir_with_parents (p.c_str(), 0755)) { - error << string_compose (_("Cannot create Configuration directory %1 - cannot run"), - p) << endmsg; - exit (1); + if (version < 0) { + /* Only create the user config dir if the version was negative, + meaning "for the current version. + */ + if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) { + if (g_mkdir_with_parents (p.c_str(), 0755)) { + error << string_compose (_("Cannot create Configuration directory %1 - cannot run"), + p) << endmsg; + exit (1); + } + } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) { + fatal << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"), + p) << endmsg; + abort(); /*NOTREACHED*/ } - } 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"), - p) << endmsg; - exit (1); } return p; @@ -134,7 +169,7 @@ user_cache_directory () } #endif // end not __APPLE__ - p = Glib::build_filename (p, user_config_dir_name); + p = Glib::build_filename (p, user_config_directory_name ()); #ifdef PLATFORM_WINDOWS /* On Windows Glib::get_user_data_dir is the folder to use for local @@ -153,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; @@ -165,15 +200,15 @@ 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, "ardour3"); + return Glib::build_filename (dll_dir_path, LIBARDOUR); #else std::string s = Glib::getenv("ARDOUR_DLL_PATH"); if (s.empty()) { std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n"); ::exit (1); - } + } return s; #endif } @@ -182,9 +217,26 @@ 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, "ardour3"); + 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 @@ -252,4 +304,15 @@ ardour_data_search_path () return search_path; } +string +been_here_before_path (int version) +{ + if (version < 0) { + version = atoi (PROGRAM_VERSION); + } + + return Glib::build_filename (user_config_directory (version), string (".a") + to_string (version, std::dec)); +} + + } // namespace ARDOUR