ardour
bundle_env_mingw.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001-2012 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <stdlib.h>
21 #include <string>
22 #include "bundle_env.h"
23 #include "i18n.h"
24 
25 #include <glibmm.h>
26 #include <fontconfig/fontconfig.h>
27 #include <pango/pangoft2.h>
28 #include <pango/pangocairo.h>
29 
30 #include <windows.h>
31 #include <wingdi.h>
32 #include <shlobj.h> // CSIDL_*
33 
34 #include "ardour/ardour.h"
35 #include "ardour/search_paths.h"
37 
38 #include "pbd/file_utils.h"
39 #include "pbd/epa.h"
41 
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45 
46 
47 /* query top-level Ardour installation path.
48  * Typically, this will be somehwere like
49  * "C:\Program Files (x86)\Ardour"
50  */
51 const std::string
53 {
54  const gchar* pExeRoot = g_win32_get_package_installation_directory_of_module (0);
55 
56  if (0 == pExeRoot) {
57  HKEY key;
58  DWORD size = PATH_MAX;
59  char tmp[PATH_MAX+1];
60  if (
61 #ifdef __MINGW64__
62  (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\w64", 0, KEY_READ, &key))
63 #else
64  (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\" PROGRAM_NAME "\\v" PROGRAM_VERSION "\\w32", 0, KEY_READ, &key))
65 #endif
66  &&(ERROR_SUCCESS == RegQueryValueExA (key, "Install_Dir", 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
67  )
68  {
69  pExeRoot = Glib::locale_to_utf8(tmp).c_str();
70  }
71  }
72 
73  if (0 == pExeRoot) {
74  const char *program_files = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
75  if (program_files) {
76  pExeRoot = g_build_filename(program_files, PROGRAM_NAME, NULL);
77  }
78  }
79 
80  if (pExeRoot && Glib::file_test(pExeRoot, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_DIR)) {
81  return std::string (pExeRoot);
82  }
83  return "";
84 }
85 
86 
87 void
88 fixup_bundle_environment (int, char* [], string & localedir)
89 {
90  EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
91  /* what to do ? */
92  // we should at least set ARDOUR_DATA_PATH to prevent the warning message.
93  // setting a FONTCONFIG_FILE won't hurt either see bundle_env_msvc.cc
94  // (pangocairo prefers the windows gdi backend unless PANGOCAIRO_BACKEND=fc is set)
95 
96  // Unset GTK_RC_FILES so that only ardour specific files are loaded
97  Glib::unsetenv ("GTK_RC_FILES");
98 
99  std::string path;
100 
102  path = windows_search_path().to_string();
103  path += "\\locale";
104  Glib::setenv ("GTK_LOCALEDIR", path, true);
105 
106  // and return the same path to our caller
107  localedir = path;
108  }
109 
110  const char *cstr;
111  cstr = getenv ("VAMP_PATH");
112  if (cstr) {
113  path = cstr;
114  path += G_SEARCHPATH_SEPARATOR;
115  } else {
116  path = "";
117  }
118  path += Glib::build_filename(ardour_dll_directory(), "vamp");
119  path += G_SEARCHPATH_SEPARATOR;
120  path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
121  path += G_SEARCHPATH_SEPARATOR;
122  path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
123  Glib::setenv ("VAMP_PATH", path, true);
124 
125  Glib::setenv ("SUIL_MODULE_DIR", Glib::build_filename(ardour_dll_directory(), "suil"), true);
126 
127  /* XXX this should really be PRODUCT_EXE see tools/x-win/package.sh
128  * ardour on windows does not have a startup wrapper script.
129  *
130  * then again, there's probably nobody using NSM on windows.
131  * because neither nsmd nor the GUI is currently available for windows.
132  * furthermore it'll be even less common for derived products.
133  */
134  Glib::setenv ("ARDOUR_SELF", Glib::build_filename(ardour_dll_directory(), "ardour.exe"), true);
135 }
136 
137 static __cdecl void
139 {
140  std::string ardour_mono_file;
141  if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
142  return;
143  }
144  RemoveFontResource(ardour_mono_file.c_str());
145 }
146 
147 void
149 {
150  std::string ardour_mono_file;
151 
152  if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
153  cerr << _("Cannot find ArdourMono TrueType font") << endl;
154  return;
155  }
156 
157  if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
158  FcConfig *config = FcInitLoadConfigAndFonts();
159  FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
160 
161  if (ret == FcFalse) {
162  cerr << _("Cannot load ArdourMono TrueType font.") << endl;
163  }
164 
165  ret = FcConfigSetCurrent(config);
166 
167  if (ret == FcFalse) {
168  cerr << _("Failed to set fontconfig configuration.") << endl;
169  }
170  } else {
171  // pango with win32 backend
172  if (0 == AddFontResource(ardour_mono_file.c_str())) {
173  cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
174  } else {
175  atexit (&unload_custom_fonts);
176  }
177  }
178 }
void fixup_bundle_environment(int, char *[], string &localedir)
LIBPBD_API char * get_win_special_folder(int csidl)
static __cdecl void unload_custom_fonts()
Definition: Beats.hpp:239
LIBARDOUR_API bool translations_are_enabled()
Definition: globals.cc:636
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
Definition: file_utils.cc:187
#define _(Text)
Definition: i18n.h:11
#define PATH_MAX
Definition: lv2_plugin.h:34
static const char * localedir
Definition: load_session.cc:12
const std::string get_install_path()
void load_custom_fonts()
Definition: amp.h:29
LIBARDOUR_API std::string ardour_dll_directory()
Definition: debug.h:30
LIBARDOUR_API PBD::Searchpath ardour_data_search_path()