2 Copyright (C) 2007 Tim Mayberry
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/compose.h"
23 #include "pbd/convert.h"
24 #include "pbd/error.h"
26 #include <glibmm/miscutils.h>
27 #include <glibmm/fileutils.h>
29 #include "ardour/directory_names.h"
30 #include "ardour/filesystem_paths.h"
34 #ifdef PLATFORM_WINDOWS
36 #include "pbd/windows_special_dirs.h"
46 user_config_directory_name (int version = -1)
49 version = atoi (X_(PROGRAM_VERSION));
52 const string config_dir_name = string_compose ("%1%2", X_(PROGRAM_NAME), version);
54 #if defined (__APPLE__) || defined (PLATFORM_WINDOWS)
55 return config_dir_name;
57 return downcase (config_dir_name);
62 user_config_directory (int version)
68 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
73 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
74 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
78 #ifdef PLATFORM_WINDOWS
79 // Not technically the home dir (since it needs to be a writable folder)
80 const string home_dir = Glib::get_user_config_dir();
82 const string home_dir = Glib::get_home_dir();
84 if (home_dir.empty ()) {
85 error << "Unable to determine home directory" << endmsg;
90 #ifndef PLATFORM_WINDOWS
91 p = Glib::build_filename (p, ".config");
95 #endif // end not __APPLE__
97 p = Glib::build_filename (p, user_config_directory_name (version));
100 /* Only create the user config dir if the version was negative,
101 meaning "for the current version.
103 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
104 if (g_mkdir_with_parents (p.c_str(), 0755)) {
105 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
109 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
110 error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
120 user_cache_directory ()
122 static std::string p;
124 if (!p.empty()) return p;
127 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
131 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
132 * defaulting to or ~/.config
134 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
138 #ifdef PLATFORM_WINDOWS
139 // Not technically the home dir (since it needs to be a writable folder)
140 const string home_dir = Glib::get_user_data_dir();
142 const string home_dir = Glib::get_home_dir();
144 if (home_dir.empty ()) {
145 error << "Unable to determine home directory" << endmsg;
150 #ifndef PLATFORM_WINDOWS
151 p = Glib::build_filename (p, ".cache");
155 #endif // end not __APPLE__
157 p = Glib::build_filename (p, user_config_directory_name ());
159 #ifdef PLATFORM_WINDOWS
160 /* On Windows Glib::get_user_data_dir is the folder to use for local
161 * (as opposed to roaming) application data.
162 * See documentation for CSIDL_LOCAL_APPDATA.
163 * Glib::get_user_data_dir() == GLib::get_user_config_dir()
164 * so we add an extra subdir *below* the config dir.
166 p = Glib::build_filename (p, "cache");
169 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
170 if (g_mkdir_with_parents (p.c_str(), 0755)) {
171 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
175 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
176 error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
185 ardour_dll_directory ()
187 #ifdef PLATFORM_WINDOWS
188 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
189 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
190 return Glib::build_filename (dll_dir_path, LIBARDOUR);
192 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
194 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
201 #ifdef PLATFORM_WINDOWS
203 windows_search_path ()
205 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
206 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
207 return Glib::build_filename (dll_dir_path, LIBARDOUR);
212 ardour_config_search_path ()
214 static Searchpath search_path;
216 if (search_path.empty()) {
217 // Start by adding the user's personal config folder
218 search_path += user_config_directory();
219 #ifdef PLATFORM_WINDOWS
220 // On Windows, add am intermediate configuration folder
221 // (one that's guaranteed to be writable by all users).
222 const gchar* const *all_users_folder = g_get_system_config_dirs();
223 // Despite its slightly odd name, the above returns a single entry which
224 // corresponds to 'All Users' on Windows (according to the documentation)
226 if (all_users_folder) {
227 std::string writable_all_users_path = all_users_folder[0];
228 writable_all_users_path += "\\";
229 writable_all_users_path += PROGRAM_NAME;
230 writable_all_users_path += "\\.config";
232 writable_all_users_path += "\\win64";
234 writable_all_users_path += "\\win32";
236 search_path += writable_all_users_path;
239 // now add a suitable config path from the bundle
240 search_path += windows_search_path ();
242 // finally, add any paths from ARDOUR_CONFIG_PATH if it exists
243 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
245 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
247 search_path += Searchpath (s);
255 ardour_data_search_path ()
257 static Searchpath search_path;
259 if (search_path.empty()) {
260 search_path += user_config_directory();
261 #ifdef PLATFORM_WINDOWS
262 search_path += windows_search_path ();
264 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
266 std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
268 search_path += Searchpath (s);
276 been_here_before_path (int version)
279 version = atoi (PROGRAM_VERSION);
282 return Glib::build_filename (user_config_directory (version), string (".a") + to_string (version, std::dec));
286 } // namespace ARDOUR