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\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\w64", 0, KEY_READ, &key))
63 (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\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");
100 if (ARDOUR::translations_are_enabled ()) {
101 path = windows_search_path().to_string();
103 Glib::setenv ("GTK_LOCALEDIR", path, true);
105 // and return the same path to our caller
106 (*localedir) = strdup (path.c_str());
110 cstr = getenv ("VAMP_PATH");
113 path += G_SEARCHPATH_SEPARATOR;
117 path += Glib::build_filename(ardour_dll_directory(), "vamp");
118 path += G_SEARCHPATH_SEPARATOR;
119 path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
120 path += G_SEARCHPATH_SEPARATOR;
121 path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
122 Glib::setenv ("VAMP_PATH", path, true);
124 Glib::setenv ("SUIL_MODULE_DIR", Glib::build_filename(ardour_dll_directory(), "suil"), true);
128 unload_custom_fonts()
130 std::string ardour_mono_file;
131 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
134 RemoveFontResource(ardour_mono_file.c_str());
140 std::string ardour_mono_file;
142 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
143 cerr << _("Cannot find ArdourMono TrueType font") << endl;
147 if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
148 FcConfig *config = FcInitLoadConfigAndFonts();
149 FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
151 if (ret == FcFalse) {
152 cerr << _("Cannot load ArdourMono TrueType font.") << endl;
155 ret = FcConfigSetCurrent(config);
157 if (ret == FcFalse) {
158 cerr << _("Failed to set fontconfig configuration.") << endl;
161 // pango with win32 backend
162 if (0 == AddFontResource(ardour_mono_file.c_str())) {
163 cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
165 atexit (&unload_custom_fonts);