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 #ifdef USE_TRACKS_CODE_FEATURES
53 /* Tracks does not use versioned configuration folders, which may or
54 may not be problematic in the future.
56 const string config_dir_name = X_(PROGRAM_NAME);
58 const string config_dir_name = string_compose ("%1%2", X_(PROGRAM_NAME), version);
60 #if defined (__APPLE__) || defined (PLATFORM_WINDOWS)
61 return config_dir_name;
63 return downcase (config_dir_name);
69 user_config_directory (int version)
75 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
80 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
81 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
85 #ifdef PLATFORM_WINDOWS
86 // Not technically the home dir (since it needs to be a writable folder)
87 const string home_dir = Glib::get_user_config_dir();
89 const string home_dir = Glib::get_home_dir();
91 if (home_dir.empty ()) {
92 error << "Unable to determine home directory" << endmsg;
97 #ifndef PLATFORM_WINDOWS
98 p = Glib::build_filename (p, ".config");
102 #endif // end not __APPLE__
104 p = Glib::build_filename (p, user_config_directory_name (version));
107 /* Only create the user config dir if the version was negative,
108 meaning "for the current version.
110 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
111 if (g_mkdir_with_parents (p.c_str(), 0755)) {
112 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
116 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
117 error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
127 user_cache_directory ()
129 static std::string p;
131 if (!p.empty()) return p;
134 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
138 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
139 * defaulting to or ~/.config
141 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
145 #ifdef PLATFORM_WINDOWS
146 // Not technically the home dir (since it needs to be a writable folder)
147 const string home_dir = Glib::get_user_data_dir();
149 const string home_dir = Glib::get_home_dir();
151 if (home_dir.empty ()) {
152 error << "Unable to determine home directory" << endmsg;
157 #ifndef PLATFORM_WINDOWS
158 p = Glib::build_filename (p, ".cache");
162 #endif // end not __APPLE__
164 p = Glib::build_filename (p, user_config_directory_name ());
166 #ifdef PLATFORM_WINDOWS
167 /* On Windows Glib::get_user_data_dir is the folder to use for local
168 * (as opposed to roaming) application data.
169 * See documentation for CSIDL_LOCAL_APPDATA.
170 * Glib::get_user_data_dir() == GLib::get_user_config_dir()
171 * so we add an extra subdir *below* the config dir.
173 p = Glib::build_filename (p, "cache");
176 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
177 if (g_mkdir_with_parents (p.c_str(), 0755)) {
178 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
182 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
183 error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
192 ardour_dll_directory ()
194 #ifdef PLATFORM_WINDOWS
195 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
196 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
197 return Glib::build_filename (dll_dir_path, LIBARDOUR);
199 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
201 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
208 #ifdef PLATFORM_WINDOWS
210 windows_search_path ()
212 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
213 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
214 return Glib::build_filename (dll_dir_path, LIBARDOUR);
219 ardour_config_search_path ()
221 static Searchpath search_path;
223 if (search_path.empty()) {
224 // Start by adding the user's personal config folder
225 search_path += user_config_directory();
226 #ifdef PLATFORM_WINDOWS
227 // On Windows, add am intermediate configuration folder
228 // (one that's guaranteed to be writable by all users).
229 const gchar* const *all_users_folder = g_get_system_config_dirs();
230 // Despite its slightly odd name, the above returns a single entry which
231 // corresponds to 'All Users' on Windows (according to the documentation)
233 if (all_users_folder) {
234 std::string writable_all_users_path = all_users_folder[0];
235 writable_all_users_path += "\\";
236 writable_all_users_path += PROGRAM_NAME;
237 writable_all_users_path += "\\.config";
239 writable_all_users_path += "\\win64";
241 writable_all_users_path += "\\win32";
243 search_path += writable_all_users_path;
246 // now add a suitable config path from the bundle
247 search_path += windows_search_path ();
249 // finally, add any paths from ARDOUR_CONFIG_PATH if it exists
250 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
252 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
254 search_path += Searchpath (s);
262 ardour_data_search_path ()
264 static Searchpath search_path;
266 if (search_path.empty()) {
267 search_path += user_config_directory();
268 #ifdef PLATFORM_WINDOWS
269 search_path += windows_search_path ();
271 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
273 std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
275 search_path += Searchpath (s);
283 been_here_before_path (int version)
286 version = atoi (PROGRAM_VERSION);
289 return Glib::build_filename (user_config_directory (version), string (".a") + to_string (version, std::dec));
293 } // namespace ARDOUR