2008-06-02 21:41:35 +00:00
|
|
|
/*
|
2019-08-03 04:01:25 +02:00
|
|
|
* Copyright (C) 2007-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
|
* Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
|
|
|
|
|
* Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
|
* Copyright (C) 2013-2014 John Emmas <john@creativepost.co.uk>
|
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
2009-11-08 16:28:21 +00:00
|
|
|
#include <cstdlib>
|
2012-05-18 17:24:06 +00:00
|
|
|
#include <iostream>
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2012-01-09 19:35:01 +00:00
|
|
|
#include "pbd/compose.h"
|
2015-03-11 10:30:42 -05:00
|
|
|
#include "pbd/error.h"
|
2016-09-21 12:17:19 +10:00
|
|
|
#include "pbd/string_convert.h"
|
2008-06-02 21:41:35 +00:00
|
|
|
|
|
|
|
|
#include <glibmm/miscutils.h>
|
2012-01-09 19:35:01 +00:00
|
|
|
#include <glibmm/fileutils.h>
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2009-02-25 18:26:51 +00:00
|
|
|
#include "ardour/directory_names.h"
|
2022-11-18 13:56:17 -07:00
|
|
|
#include "ardour/filename_extensions.h"
|
2009-02-25 18:26:51 +00:00
|
|
|
#include "ardour/filesystem_paths.h"
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2012-01-09 19:35:01 +00:00
|
|
|
|
2014-03-10 16:05:40 +00:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
|
#include "shlobj.h"
|
|
|
|
|
#include "pbd/windows_special_dirs.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-05-12 17:03:42 +00:00
|
|
|
using namespace PBD;
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
namespace ARDOUR {
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2015-03-11 10:30:42 -05:00
|
|
|
static std::string
|
|
|
|
|
user_config_directory_name (int version = -1)
|
|
|
|
|
{
|
|
|
|
|
if (version < 0) {
|
2016-09-21 12:17:19 +10:00
|
|
|
version = string_to<int32_t>(X_(PROGRAM_VERSION));
|
2015-03-11 10:30:42 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-09 19:33:26 -04:00
|
|
|
/* ARDOUR::Profile may not be available when this is
|
2015-10-04 14:51:05 -04:00
|
|
|
called, so rely on build-time detection of the
|
2015-05-09 19:33:26 -04:00
|
|
|
product name etc.
|
|
|
|
|
*/
|
2015-10-05 16:17:49 +02:00
|
|
|
|
2015-03-11 10:30:42 -05:00
|
|
|
const string config_dir_name = string_compose ("%1%2", X_(PROGRAM_NAME), version);
|
2015-03-11 13:24:11 -05:00
|
|
|
|
2015-03-11 10:30:42 -05:00
|
|
|
#if defined (__APPLE__) || defined (PLATFORM_WINDOWS)
|
2015-05-09 19:33:26 -04:00
|
|
|
/* Use mixed-case folder name on OS X and Windows */
|
2015-03-11 10:30:42 -05:00
|
|
|
return config_dir_name;
|
|
|
|
|
#else
|
2015-05-09 19:33:26 -04:00
|
|
|
/* use lower case folder name on Linux */
|
2015-03-11 10:30:42 -05:00
|
|
|
return downcase (config_dir_name);
|
|
|
|
|
#endif
|
2015-10-05 16:17:49 +02:00
|
|
|
}
|
2015-03-11 10:30:42 -05:00
|
|
|
|
2012-06-23 05:06:54 +00:00
|
|
|
std::string
|
2015-03-11 10:30:42 -05:00
|
|
|
user_config_directory (int version)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2015-03-11 13:24:11 -05:00
|
|
|
std::string p;
|
2009-11-08 16:28:21 +00:00
|
|
|
|
2012-01-09 19:35:01 +00:00
|
|
|
#ifdef __APPLE__
|
2014-12-23 23:04:38 +01:00
|
|
|
|
2012-06-23 05:07:14 +00:00
|
|
|
p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
|
2012-01-09 19:35:01 +00:00
|
|
|
|
2014-12-23 23:04:38 +01:00
|
|
|
#else
|
2009-11-08 16:28:21 +00:00
|
|
|
|
2014-12-23 23:04:38 +01:00
|
|
|
const char* c = 0;
|
|
|
|
|
/* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
|
2009-11-08 16:28:21 +00:00
|
|
|
if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
|
|
|
|
|
p = c;
|
|
|
|
|
} else {
|
2014-12-23 23:04:38 +01:00
|
|
|
|
2014-03-10 16:05:40 +00:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-03-19 14:38:41 +00:00
|
|
|
// Not technically the home dir (since it needs to be a writable folder)
|
2014-12-23 23:04:38 +01:00
|
|
|
const string home_dir = Glib::get_user_config_dir();
|
2014-03-10 16:05:40 +00:00
|
|
|
#else
|
|
|
|
|
const string home_dir = Glib::get_home_dir();
|
|
|
|
|
#endif
|
2009-11-08 16:28:21 +00:00
|
|
|
if (home_dir.empty ()) {
|
2012-06-23 05:07:14 +00:00
|
|
|
error << "Unable to determine home directory" << endmsg;
|
2019-07-04 22:21:35 +02:00
|
|
|
exit (EXIT_FAILURE);
|
2009-11-08 16:28:21 +00:00
|
|
|
}
|
2014-12-23 23:04:38 +01:00
|
|
|
p = home_dir;
|
2009-11-08 16:28:21 +00:00
|
|
|
|
2014-12-22 23:04:23 +01:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2012-06-23 05:07:14 +00:00
|
|
|
p = Glib::build_filename (p, ".config");
|
2014-12-22 23:04:23 +01:00
|
|
|
#endif
|
2014-12-23 23:04:38 +01:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2014-12-23 23:04:38 +01:00
|
|
|
#endif // end not __APPLE__
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2015-03-11 10:30:42 -05:00
|
|
|
p = Glib::build_filename (p, user_config_directory_name (version));
|
2012-01-09 19:35:01 +00:00
|
|
|
|
2015-03-11 12:12:08 -05:00
|
|
|
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;
|
2019-07-04 22:21:35 +02:00
|
|
|
exit (EXIT_FAILURE);
|
2015-03-11 12:12:08 -05:00
|
|
|
}
|
|
|
|
|
} else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
|
2015-08-19 04:09:22 +02:00
|
|
|
fatal << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
|
2015-03-11 12:12:08 -05:00
|
|
|
p) << endmsg;
|
2015-08-19 04:07:39 +02:00
|
|
|
abort(); /*NOTREACHED*/
|
2012-01-09 19:35:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-23 05:07:14 +00:00
|
|
|
return p;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-24 21:11:22 +01:00
|
|
|
std::string
|
2016-09-28 13:11:16 +02:00
|
|
|
user_cache_directory (std::string cachename)
|
2014-02-24 21:11:22 +01:00
|
|
|
{
|
2016-09-28 13:11:16 +02:00
|
|
|
std::string p;
|
2014-02-24 21:11:22 +01:00
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
|
|
|
|
|
#else
|
|
|
|
|
const char* c = 0;
|
|
|
|
|
|
2014-02-26 20:43:43 +01:00
|
|
|
/* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
|
|
|
|
|
* defaulting to or ~/.config
|
2014-02-24 21:11:22 +01:00
|
|
|
*/
|
|
|
|
|
if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
|
|
|
|
|
p = c;
|
|
|
|
|
} else {
|
2015-01-05 18:29:33 +01:00
|
|
|
|
2014-03-10 16:05:40 +00:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-03-19 14:38:41 +00:00
|
|
|
// Not technically the home dir (since it needs to be a writable folder)
|
2015-01-05 18:29:33 +01:00
|
|
|
const string home_dir = Glib::get_user_data_dir();
|
2014-03-10 16:05:40 +00:00
|
|
|
#else
|
2014-02-24 21:11:22 +01:00
|
|
|
const string home_dir = Glib::get_home_dir();
|
2014-03-10 16:05:40 +00:00
|
|
|
#endif
|
2014-02-24 21:11:22 +01:00
|
|
|
if (home_dir.empty ()) {
|
|
|
|
|
error << "Unable to determine home directory" << endmsg;
|
2019-07-04 22:21:35 +02:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 21:11:22 +01:00
|
|
|
}
|
|
|
|
|
p = home_dir;
|
2015-01-05 18:29:33 +01:00
|
|
|
|
|
|
|
|
#ifndef PLATFORM_WINDOWS
|
2014-02-24 21:11:22 +01:00
|
|
|
p = Glib::build_filename (p, ".cache");
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-01-05 18:29:33 +01:00
|
|
|
}
|
|
|
|
|
#endif // end not __APPLE__
|
|
|
|
|
|
2016-09-28 13:11:16 +02:00
|
|
|
if (cachename.empty ()) {
|
|
|
|
|
p = Glib::build_filename (p, user_config_directory_name ());
|
|
|
|
|
} else {
|
|
|
|
|
p = Glib::build_filename (p, cachename);
|
|
|
|
|
}
|
2015-01-05 18:29:33 +01:00
|
|
|
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
|
/* On Windows Glib::get_user_data_dir is the folder to use for local
|
|
|
|
|
* (as opposed to roaming) application data.
|
|
|
|
|
* See documentation for CSIDL_LOCAL_APPDATA.
|
|
|
|
|
* Glib::get_user_data_dir() == GLib::get_user_config_dir()
|
|
|
|
|
* so we add an extra subdir *below* the config dir.
|
|
|
|
|
*/
|
|
|
|
|
p = Glib::build_filename (p, "cache");
|
2014-03-19 14:38:41 +00:00
|
|
|
#endif
|
2014-02-24 21:11:22 +01:00
|
|
|
|
|
|
|
|
if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
|
|
|
|
|
if (g_mkdir_with_parents (p.c_str(), 0755)) {
|
|
|
|
|
error << string_compose (_("Cannot create cache directory %1 - cannot run"),
|
|
|
|
|
p) << endmsg;
|
2019-07-04 22:21:35 +02:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 21:11:22 +01:00
|
|
|
}
|
|
|
|
|
} else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
|
2015-08-03 00:25:19 +02:00
|
|
|
fatal << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
|
2014-02-24 21:11:22 +01:00
|
|
|
p) << endmsg;
|
2015-08-19 04:07:39 +02:00
|
|
|
abort(); /*NOTREACHED*/
|
2014-02-24 21:11:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-23 05:06:54 +00:00
|
|
|
std::string
|
2012-05-18 17:24:06 +00:00
|
|
|
ardour_dll_directory ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-08-04 19:03:32 +01:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2015-08-18 14:04:21 +10:00
|
|
|
std::string dll_dir_path(windows_package_directory_path());
|
2013-07-13 16:56:12 -04:00
|
|
|
dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
|
2015-01-05 19:07:24 +01:00
|
|
|
return Glib::build_filename (dll_dir_path, LIBARDOUR);
|
2013-07-13 16:56:12 -04:00
|
|
|
#else
|
2012-05-18 17:24:06 +00:00
|
|
|
std::string s = Glib::getenv("ARDOUR_DLL_PATH");
|
|
|
|
|
if (s.empty()) {
|
2012-05-19 14:46:44 +00:00
|
|
|
std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
|
2019-07-04 22:21:35 +02:00
|
|
|
::exit (EXIT_FAILURE);
|
2015-10-05 16:17:49 +02:00
|
|
|
}
|
2012-06-23 05:06:54 +00:00
|
|
|
return s;
|
2013-07-13 16:56:12 -04:00
|
|
|
#endif
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-04 19:03:32 +01:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2013-08-15 20:04:08 +10:00
|
|
|
Searchpath
|
2013-07-13 16:56:12 -04:00
|
|
|
windows_search_path ()
|
|
|
|
|
{
|
2015-08-18 14:04:21 +10:00
|
|
|
std::string dll_dir_path(windows_package_directory_path());
|
2013-07-13 16:56:12 -04:00
|
|
|
dll_dir_path = Glib::build_filename (dll_dir_path, "share");
|
2015-01-05 19:07:24 +01:00
|
|
|
return Glib::build_filename (dll_dir_path, LIBARDOUR);
|
2013-07-13 16:56:12 -04:00
|
|
|
}
|
2015-08-18 14:04:21 +10:00
|
|
|
|
|
|
|
|
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;
|
2015-08-19 04:07:39 +02:00
|
|
|
abort(); /*NOTREACHED*/
|
2015-08-18 14:04:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string package_dir_path(package_dir);
|
|
|
|
|
g_free(package_dir);
|
|
|
|
|
return package_dir_path;
|
|
|
|
|
}
|
2013-07-13 16:56:12 -04:00
|
|
|
#endif
|
|
|
|
|
|
2013-08-15 20:04:08 +10:00
|
|
|
Searchpath
|
2012-05-18 17:24:06 +00:00
|
|
|
ardour_config_search_path ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-08-15 20:04:08 +10:00
|
|
|
static Searchpath search_path;
|
2012-05-18 17:24:06 +00:00
|
|
|
|
2012-06-23 05:07:12 +00:00
|
|
|
if (search_path.empty()) {
|
2014-08-28 08:08:43 +01:00
|
|
|
// Start by adding the user's personal config folder
|
2012-06-23 05:07:12 +00:00
|
|
|
search_path += user_config_directory();
|
2013-08-04 19:03:32 +01:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-08-28 08:08:43 +01:00
|
|
|
// On Windows, add am intermediate configuration folder
|
|
|
|
|
// (one that's guaranteed to be writable by all users).
|
|
|
|
|
const gchar* const *all_users_folder = g_get_system_config_dirs();
|
|
|
|
|
// Despite its slightly odd name, the above returns a single entry which
|
|
|
|
|
// corresponds to 'All Users' on Windows (according to the documentation)
|
|
|
|
|
|
|
|
|
|
if (all_users_folder) {
|
|
|
|
|
std::string writable_all_users_path = all_users_folder[0];
|
|
|
|
|
writable_all_users_path += "\\";
|
|
|
|
|
writable_all_users_path += PROGRAM_NAME;
|
|
|
|
|
writable_all_users_path += "\\.config";
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
|
writable_all_users_path += "\\win64";
|
|
|
|
|
#else
|
|
|
|
|
writable_all_users_path += "\\win32";
|
|
|
|
|
#endif
|
|
|
|
|
search_path += writable_all_users_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now add a suitable config path from the bundle
|
2013-07-13 16:56:12 -04:00
|
|
|
search_path += windows_search_path ();
|
2014-03-19 13:42:58 +00:00
|
|
|
#endif
|
2014-08-28 08:08:43 +01:00
|
|
|
// finally, add any paths from ARDOUR_CONFIG_PATH if it exists
|
2012-05-18 17:24:06 +00:00
|
|
|
std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
|
|
|
|
|
if (s.empty()) {
|
2014-03-19 13:42:58 +00:00
|
|
|
std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
|
|
|
|
|
} else {
|
|
|
|
|
search_path += Searchpath (s);
|
2012-05-18 17:24:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2012-05-18 17:24:06 +00:00
|
|
|
return search_path;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 20:04:08 +10:00
|
|
|
Searchpath
|
2012-05-18 17:24:06 +00:00
|
|
|
ardour_data_search_path ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-08-15 20:04:08 +10:00
|
|
|
static Searchpath search_path;
|
2012-05-18 17:24:06 +00:00
|
|
|
|
2012-06-23 05:07:12 +00:00
|
|
|
if (search_path.empty()) {
|
|
|
|
|
search_path += user_config_directory();
|
2013-08-04 19:03:32 +01:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2013-07-13 16:56:12 -04:00
|
|
|
search_path += windows_search_path ();
|
2022-04-28 14:32:50 -06:00
|
|
|
#endif
|
2012-05-18 17:24:06 +00:00
|
|
|
std::string s = Glib::getenv("ARDOUR_DATA_PATH");
|
|
|
|
|
if (s.empty()) {
|
2014-03-19 13:42:58 +00:00
|
|
|
std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
|
|
|
|
|
} else {
|
|
|
|
|
search_path += Searchpath (s);
|
2012-05-18 17:24:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2012-05-18 17:24:06 +00:00
|
|
|
return search_path;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-31 11:27:30 -04:00
|
|
|
string
|
|
|
|
|
been_here_before_path (int version)
|
|
|
|
|
{
|
|
|
|
|
if (version < 0) {
|
|
|
|
|
version = atoi (PROGRAM_VERSION);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 12:17:19 +10:00
|
|
|
return Glib::build_filename (user_config_directory (version), string (".a") + to_string (version));
|
2015-03-31 11:27:30 -04:00
|
|
|
}
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
} // namespace ARDOUR
|