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/error.h"
23 #include "pbd/compose.h"
25 #include <glibmm/miscutils.h>
26 #include <glibmm/fileutils.h>
28 #include "ardour/directory_names.h"
29 #include "ardour/filesystem_paths.h"
33 #ifdef PLATFORM_WINDOWS
35 #include "pbd/windows_special_dirs.h"
45 user_config_directory ()
49 if (!p.empty()) return p;
53 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
58 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config */
59 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
63 #ifdef PLATFORM_WINDOWS
64 // Not technically the home dir (since it needs to be a writable folder)
65 const string home_dir = Glib::get_user_config_dir();
67 const string home_dir = Glib::get_home_dir();
69 if (home_dir.empty ()) {
70 error << "Unable to determine home directory" << endmsg;
75 #ifndef PLATFORM_WINDOWS
76 p = Glib::build_filename (p, ".config");
80 #endif // end not __APPLE__
82 p = Glib::build_filename (p, user_config_dir_name);
84 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
85 if (g_mkdir_with_parents (p.c_str(), 0755)) {
86 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
90 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
91 error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
100 user_cache_directory ()
102 static std::string p;
104 if (!p.empty()) return p;
107 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
111 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
112 * defaulting to or ~/.config
114 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
117 #ifdef PLATFORM_WINDOWS
118 // Not technically the home dir (since it needs to be a writable folder)
119 const string home_dir = Glib::build_filename (Glib::get_user_data_dir(), user_config_dir_name);
121 const string home_dir = Glib::get_home_dir();
123 if (home_dir.empty ()) {
124 error << "Unable to determine home directory" << endmsg;
129 p = Glib::build_filename (p, ".cache");
133 #ifndef PLATFORM_WINDOWS
134 p = Glib::build_filename (p, user_config_dir_name);
137 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
138 if (g_mkdir_with_parents (p.c_str(), 0755)) {
139 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
143 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
144 error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
153 ardour_dll_directory ()
155 #ifdef PLATFORM_WINDOWS
156 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
157 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
158 return Glib::build_filename (dll_dir_path, "ardour3");
160 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
162 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
169 #ifdef PLATFORM_WINDOWS
171 windows_search_path ()
173 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
174 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
175 return Glib::build_filename (dll_dir_path, "ardour3");
180 ardour_config_search_path ()
182 static Searchpath search_path;
184 if (search_path.empty()) {
185 // Start by adding the user's personal config folder
186 search_path += user_config_directory();
187 #ifdef PLATFORM_WINDOWS
188 // On Windows, add am intermediate configuration folder
189 // (one that's guaranteed to be writable by all users).
190 const gchar* const *all_users_folder = g_get_system_config_dirs();
191 // Despite its slightly odd name, the above returns a single entry which
192 // corresponds to 'All Users' on Windows (according to the documentation)
194 if (all_users_folder) {
195 std::string writable_all_users_path = all_users_folder[0];
196 writable_all_users_path += "\\";
197 writable_all_users_path += PROGRAM_NAME;
198 writable_all_users_path += "\\.config";
200 writable_all_users_path += "\\win64";
202 writable_all_users_path += "\\win32";
204 search_path += writable_all_users_path;
207 // now add a suitable config path from the bundle
208 search_path += windows_search_path ();
210 // finally, add any paths from ARDOUR_CONFIG_PATH if it exists
211 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
213 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment\n");
215 search_path += Searchpath (s);
223 ardour_data_search_path ()
225 static Searchpath search_path;
227 if (search_path.empty()) {
228 search_path += user_config_directory();
229 #ifdef PLATFORM_WINDOWS
230 search_path += windows_search_path ();
232 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
234 std::cerr << _("ARDOUR_DATA_PATH not set in environment\n");
236 search_path += Searchpath (s);
243 } // namespace ARDOUR