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)
66 if (!p.empty()) return p;
70 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
75 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
76 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
80 #ifdef PLATFORM_WINDOWS
81 // Not technically the home dir (since it needs to be a writable folder)
82 const string home_dir = Glib::get_user_config_dir();
84 const string home_dir = Glib::get_home_dir();
86 if (home_dir.empty ()) {
87 error << "Unable to determine home directory" << endmsg;
92 #ifndef PLATFORM_WINDOWS
93 p = Glib::build_filename (p, ".config");
97 #endif // end not __APPLE__
99 p = Glib::build_filename (p, user_config_directory_name (version));
102 /* Only create the user config dir if the version was negative,
103 meaning "for the current version.
105 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
106 if (g_mkdir_with_parents (p.c_str(), 0755)) {
107 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
111 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
112 error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
122 user_cache_directory ()
124 static std::string p;
126 if (!p.empty()) return p;
129 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
133 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
134 * defaulting to or ~/.config
136 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
140 #ifdef PLATFORM_WINDOWS
141 // Not technically the home dir (since it needs to be a writable folder)
142 const string home_dir = Glib::get_user_data_dir();
144 const string home_dir = Glib::get_home_dir();
146 if (home_dir.empty ()) {
147 error << "Unable to determine home directory" << endmsg;
152 #ifndef PLATFORM_WINDOWS
153 p = Glib::build_filename (p, ".cache");
157 #endif // end not __APPLE__
159 p = Glib::build_filename (p, user_config_directory_name ());
161 #ifdef PLATFORM_WINDOWS
162 /* On Windows Glib::get_user_data_dir is the folder to use for local
163 * (as opposed to roaming) application data.
164 * See documentation for CSIDL_LOCAL_APPDATA.
165 * Glib::get_user_data_dir() == GLib::get_user_config_dir()
166 * so we add an extra subdir *below* the config dir.
168 p = Glib::build_filename (p, "cache");
171 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
172 if (g_mkdir_with_parents (p.c_str(), 0755)) {
173 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
177 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
178 error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
187 ardour_dll_directory ()
189 #ifdef PLATFORM_WINDOWS
190 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
191 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
192 return Glib::build_filename (dll_dir_path, LIBARDOUR);
194 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
196 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
203 #ifdef PLATFORM_WINDOWS
205 windows_search_path ()
207 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
208 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
209 return Glib::build_filename (dll_dir_path, LIBARDOUR);
214 ardour_config_search_path ()
216 static Searchpath search_path;
218 if (search_path.empty()) {
219 // Start by adding the user's personal config folder
220 search_path += user_config_directory();
221 #ifdef PLATFORM_WINDOWS
222 // On Windows, add am intermediate configuration folder
223 // (one that's guaranteed to be writable by all users).
224 const gchar* const *all_users_folder = g_get_system_config_dirs();
225 // Despite its slightly odd name, the above returns a single entry which
226 // corresponds to 'All Users' on Windows (according to the documentation)
228 if (all_users_folder) {
229 std::string writable_all_users_path = all_users_folder[0];
230 writable_all_users_path += "\\";
231 writable_all_users_path += PROGRAM_NAME;
232 writable_all_users_path += "\\.config";
234 writable_all_users_path += "\\win64";
236 writable_all_users_path += "\\win32";
238 search_path += writable_all_users_path;
241 // now add a suitable config path from the bundle
242 search_path += windows_search_path ();
244 // finally, add any paths from ARDOUR_CONFIG_PATH if it exists
245 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
247 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
249 search_path += Searchpath (s);
257 ardour_data_search_path ()
259 static Searchpath search_path;
261 if (search_path.empty()) {
262 search_path += user_config_directory();
263 #ifdef PLATFORM_WINDOWS
264 search_path += windows_search_path ();
266 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
268 std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
270 search_path += Searchpath (s);
277 } // namespace ARDOUR