2 Copyright (C) 2001-2012 Paul Davis
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.
21 #include "bundle_env.h"
25 #include <fontconfig/fontconfig.h>
26 #include <pango/pangoft2.h>
27 #include <pango/pangocairo.h>
31 #include <shlobj.h> // CSIDL_*
33 #include "ardour/ardour.h"
34 #include "ardour/search_paths.h"
35 #include "ardour/filesystem_paths.h"
37 #include "pbd/file_utils.h"
39 #include "pbd/windows_special_dirs.h"
43 using namespace ARDOUR;
46 /* query top-level Ardour installation path.
47 * Typically, this will be somehwere like
48 * "C:\Program Files (x86)\Ardour"
53 const gchar* pExeRoot = g_win32_get_package_installation_directory_of_module (0);
57 DWORD size = PATH_MAX;
61 (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Ardour\\ardour3\\w64", 0, KEY_READ, &key))
63 (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Ardour\\ardour3\\w32", 0, KEY_READ, &key))
65 &&(ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
68 pExeRoot = Glib::locale_to_utf8(tmp).c_str();
73 const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
75 pExeRoot = g_build_filename(program_files, PROGRAM_NAME, NULL);
79 if (pExeRoot && Glib::file_test(pExeRoot, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_DIR)) {
80 return std::string (pExeRoot);
87 fixup_bundle_environment (int, char* [], const char** localedir)
89 EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
91 // we should at least set ARDOUR_DATA_PATH to prevent the warning message.
92 // setting a FONTCONFIG_FILE won't hurt either see bundle_env_msvc.cc
93 // (pangocairo prefers the windows gdi backend unless PANGOCAIRO_BACKEND=fc is set)
95 // Unset GTK_RC_FILES so that only ardour specific files are loaded
96 Glib::unsetenv ("GTK_RC_FILES");
101 cstr = getenv ("VAMP_PATH");
104 path += G_SEARCHPATH_SEPARATOR;
108 path += Glib::build_filename(get_install_path(), "lib", "ardour3", "vamp", NULL);
109 path += G_SEARCHPATH_SEPARATOR;
110 path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
111 path += G_SEARCHPATH_SEPARATOR;
112 path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
113 Glib::setenv ("VAMP_PATH", path, true);
117 unload_custom_fonts()
119 std::string ardour_mono_file;
120 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
123 RemoveFontResource(ardour_mono_file.c_str());
129 std::string ardour_mono_file;
131 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
132 cerr << _("Cannot find ArdourMono TrueType font") << endl;
136 if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
137 FcConfig *config = FcInitLoadConfigAndFonts();
138 FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
140 if (ret == FcFalse) {
141 cerr << _("Cannot load ArdourMono TrueType font.") << endl;
144 ret = FcConfigSetCurrent(config);
146 if (ret == FcFalse) {
147 cerr << _("Failed to set fontconfig configuration.") << endl;
150 // pango with win32 backend
151 if (0 == AddFontResource(ardour_mono_file.c_str())) {
152 cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
154 atexit (&unload_custom_fonts);