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;
52 p = Glib::build_filename (Glib::get_home_dir(), "Library/Preferences");
56 /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config
59 if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
62 #ifdef PLATFORM_WINDOWS
65 if (0 != PBD::get_win_special_folder(CSIDL_LOCAL_APPDATA))
66 home_dir = PBD::get_win_special_folder(CSIDL_LOCAL_APPDATA);
68 const string home_dir = Glib::get_home_dir();
70 if (home_dir.empty ()) {
71 error << "Unable to determine home directory" << endmsg;
76 p = Glib::build_filename (p, ".config");
80 p = Glib::build_filename (p, user_config_dir_name);
82 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
83 if (g_mkdir_with_parents (p.c_str(), 0755)) {
84 error << string_compose (_("Cannot create Configuration directory %1 - cannot run"),
88 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
89 error << string_compose (_("Configuration directory %1 already exists and is not a directory/folder - cannot run"),
98 user_cache_directory ()
100 static std::string p;
102 if (!p.empty()) return p;
105 p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches");
109 /* adopt freedesktop standards, and put .ardour3 into $XDG_CACHE_HOME
110 * defaulting to or ~/.config
112 * NB this should work on windows, too, but we may want to prefer
113 * PBD::get_platform_fallback_folder (PBD::FOLDER_VST) or someplace
115 if ((c = getenv ("XDG_CACHE_HOME")) != 0) {
118 #ifdef PLATFORM_WINDOWS
119 std::string home_dir;
121 if (0 != PBD::get_win_special_folder(CSIDL_LOCAL_APPDATA))
122 home_dir = PBD::get_win_special_folder(CSIDL_LOCAL_APPDATA);
124 const string home_dir = Glib::get_home_dir();
127 if (home_dir.empty ()) {
128 error << "Unable to determine home directory" << endmsg;
133 p = Glib::build_filename (p, ".cache");
137 p = Glib::build_filename (p, user_config_dir_name);
139 if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
140 if (g_mkdir_with_parents (p.c_str(), 0755)) {
141 error << string_compose (_("Cannot create cache directory %1 - cannot run"),
145 } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
146 error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"),
155 ardour_dll_directory ()
157 #ifdef PLATFORM_WINDOWS
158 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
159 dll_dir_path = Glib::build_filename (dll_dir_path, "lib");
160 return Glib::build_filename (dll_dir_path, "ardour3");
162 std::string s = Glib::getenv("ARDOUR_DLL_PATH");
164 std::cerr << _("ARDOUR_DLL_PATH not set in environment - exiting\n");
171 #ifdef PLATFORM_WINDOWS
173 windows_search_path ()
175 std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL));
176 dll_dir_path = Glib::build_filename (dll_dir_path, "share");
177 return Glib::build_filename (dll_dir_path, "ardour3");
182 ardour_config_search_path ()
184 static Searchpath search_path;
186 if (search_path.empty()) {
187 search_path += user_config_directory();
188 #ifdef PLATFORM_WINDOWS
189 search_path += windows_search_path ();
191 std::string s = Glib::getenv("ARDOUR_CONFIG_PATH");
193 std::cerr << _("ARDOUR_CONFIG_PATH not set in environment - exiting\n");
197 search_path += Searchpath (s);
205 ardour_data_search_path ()
207 static Searchpath search_path;
209 if (search_path.empty()) {
210 search_path += user_config_directory();
211 #ifdef PLATFORM_WINDOWS
212 search_path += windows_search_path ();
214 std::string s = Glib::getenv("ARDOUR_DATA_PATH");
216 std::cerr << _("ARDOUR_DATA_PATH not set in environment - exiting\n");
220 search_path += Searchpath (s);
227 } // namespace ARDOUR