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");
98 if (ARDOUR::translations_are_enabled ()) {
99 path = windows_search_path().to_string();
101 Glib::setenv ("GTK_LOCALEDIR", path, true);
103 // and return the same path to our caller
104 (*localedir) = strdup (path.c_str());
109 cstr = getenv ("VAMP_PATH");
112 path += G_SEARCHPATH_SEPARATOR;
116 path += Glib::build_filename(ardour_dll_directory(), "vamp");
117 path += G_SEARCHPATH_SEPARATOR;
118 path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
119 path += G_SEARCHPATH_SEPARATOR;
120 path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
121 Glib::setenv ("VAMP_PATH", path, true);
123 Glib::setenv ("SUIL_MODULE_DIR", Glib::build_filename(ardour_dll_directory(), "suil"), true);
127 unload_custom_fonts()
129 std::string ardour_mono_file;
130 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
133 RemoveFontResource(ardour_mono_file.c_str());
139 std::string ardour_mono_file;
141 if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
142 cerr << _("Cannot find ArdourMono TrueType font") << endl;
146 if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
147 FcConfig *config = FcInitLoadConfigAndFonts();
148 FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
150 if (ret == FcFalse) {
151 cerr << _("Cannot load ArdourMono TrueType font.") << endl;
154 ret = FcConfigSetCurrent(config);
156 if (ret == FcFalse) {
157 cerr << _("Failed to set fontconfig configuration.") << endl;
160 // pango with win32 backend
161 if (0 == AddFontResource(ardour_mono_file.c_str())) {
162 cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
164 atexit (&unload_custom_fonts);