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 /* ARDOUR::Profile may not be available when this is
53 called, so rely on build-time detection of the
57 #ifdef USE_TRACKS_CODE_FEATURES
58 /* Tracks does not use versioned configuration folders, which may or
59 may not be problematic in the future.
61 return X_(PROGRAM_NAME);
64 const string config_dir_name = string_compose ("%1%2", X_(PROGRAM_NAME), version);
66 #if defined (__APPLE__) || defined (PLATFORM_WINDOWS)
67 /* Use mixed-case folder name on OS X and Windows */
68 return config_dir_name;
70 /* use lower case folder name on Linux */
71 return downcase (config_dir_name);
77 user_config_directory (int version)
83 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
88 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
89 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
93 #ifdef PLATFORM_WINDOWS
94 // Not technically the home dir (since it needs to be a writable folder)
95 const string home_dir = Glib::get_user_config_dir();
97 const string home_dir = Glib::get_home_dir();
99 if (home_dir.empty ()) {
100 error << "Unable to determine home directory" << endmsg;
105 #ifndef PLATFORM_WINDOWS
106 p = Glib::build_filename (p, ".config");
110 #endif // end not __APPLE__
112 p = Glib::build_filename (p, user_config_directory_name (version));
115 /* Only create the user config dir if the version was negative,
116 meaning "for the current version.
118 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
119 if (g_mkdir_with_parents (p.c_str(), 0755)) {
120 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
124 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
125 fatal << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
127 abort(); /*NOTREACHED*/
135 user_cache_directory ()
137 static std::string p;
139 if (!p.empty()) return p;
142 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
146 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
147 * defaulting to or ~/.config
149 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
153 #ifdef PLATFORM_WINDOWS
154 // Not technically the home dir (since it needs to be a writable folder)
155 const string home_dir = Glib::get_user_data_dir();
157 const string home_dir = Glib::get_home_dir();
159 if (home_dir.empty ()) {
160 error << "Unable to determine home directory" << endmsg;
165 #ifndef PLATFORM_WINDOWS
166 p = Glib::build_filename (p, ".cache");
170 #endif // end not __APPLE__
172 p = Glib::build_filename (p, user_config_directory_name ());
174 #ifdef PLATFORM_WINDOWS
175 /* On Windows Glib::get_user_data_dir is the folder to use for local
176 * (as opposed to roaming) application data.
177 * See documentation for CSIDL_LOCAL_APPDATA.
178 * Glib::get_user_data_dir() == GLib::get_user_config_dir()
179 * so we add an extra subdir *below* the config dir.
181 p = Glib::build_filename (p, "cache");
184 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
185 if (g_mkdir_with_parents (p.c_str(), 0755)) {
186 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
190 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
191 fatal << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
193 abort(); /*NOTREACHED*/
200 ardour_dll_directory ()
202 #ifdef PLATFORM_WINDOWS
203 std::string dll_dir_path(windows_package_directory_path());
204 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
205 return Glib::build_filename (dll_dir_path, LIBARDOUR);
207 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
209 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
216 #ifdef PLATFORM_WINDOWS
218 windows_search_path ()
220 std::string dll_dir_path(windows_package_directory_path());
221 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
222 return Glib::build_filename (dll_dir_path, LIBARDOUR);
226 windows_package_directory_path ()
229 g_win32_get_package_installation_directory_of_module (NULL);
231 if (package_dir == NULL) {
232 fatal << string_compose (_("Cannot determine %1 package directory"),
233 PROGRAM_NAME) << endmsg;
234 abort(); /*NOTREACHED*/
237 std::string package_dir_path(package_dir);
239 return package_dir_path;
244 ardour_config_search_path ()
246 static Searchpath search_path;
248 if (search_path.empty()) {
249 // Start by adding the user's personal config folder
250 search_path += user_config_directory();
251 #ifdef PLATFORM_WINDOWS
252 // On Windows, add am intermediate configuration folder
253 // (one that's guaranteed to be writable by all users).
254 const gchar* const *all_users_folder = g_get_system_config_dirs();
255 // Despite its slightly odd name, the above returns a single entry which
256 // corresponds to 'All Users' on Windows (according to the documentation)
258 if (all_users_folder) {
259 std::string writable_all_users_path = all_users_folder[0];
260 writable_all_users_path += "\\";
261 writable_all_users_path += PROGRAM_NAME;
262 writable_all_users_path += "\\.config";
264 writable_all_users_path += "\\win64";
266 writable_all_users_path += "\\win32";
268 search_path += writable_all_users_path;
271 // now add a suitable config path from the bundle
272 search_path += windows_search_path ();
274 // finally, add any paths from ARDOUR_CONFIG_PATH if it exists
275 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
277 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
279 search_path += Searchpath (s);
287 ardour_data_search_path ()
289 static Searchpath search_path;
291 if (search_path.empty()) {
292 search_path += user_config_directory();
293 #ifdef PLATFORM_WINDOWS
294 search_path += windows_search_path ();
296 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
298 std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
300 search_path += Searchpath (s);
308 been_here_before_path (int version)
311 version = atoi (PROGRAM_VERSION);
314 return Glib::build_filename (user_config_directory (version), string (".a") + to_string (version, std::dec));
318 } // namespace ARDOUR