1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * bean-dirs.c
 * This file is part of libbean
 *
 * Copyright (C) 2008 Ignacio Casal Quinteiro
 *
 * libbean is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libbean is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "bean-dirs.h"

#ifdef OS_OSX
#include "bean-utils-osx.h"
#endif

#ifdef G_OS_WIN32
// inspired by gobject-introspection...

#include <libloaderapi.h>

static HMODULE libbean_dll = NULL;

#ifdef DLL_EXPORT

BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);

BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  if (fdwReason == DLL_PROCESS_ATTACH)
    libbean_dll = hinstDLL;
  return TRUE;
}

#endif
#endif

gchar *
bean_dirs_get_data_dir (void)
{
  gchar *data_dir;

#ifdef G_OS_WIN32
  gchar *win32_dir;

  win32_dir = g_win32_get_package_installation_directory_of_module (libbean_dll);

  data_dir = g_build_filename (win32_dir, "share", "libbean-1.0", NULL);
  g_free (win32_dir);
#elif defined (OS_OSX)
  data_dir = bean_dirs_os_x_get_data_dir ();
#else
  data_dir = g_build_filename (DATADIR, "libbean-1.0", NULL);
#endif

  return data_dir;
}

gchar *
bean_dirs_get_lib_dir (void)<--- The function 'bean_dirs_get_lib_dir' should have static linkage since it is not used outside of its translation unit.
{
  gchar *lib_dir;

#ifdef G_OS_WIN32
  gchar *win32_dir;

  win32_dir = g_win32_get_package_installation_directory_of_module (libbean_dll);

  lib_dir = g_build_filename (win32_dir, "lib", "libbean-1.0", NULL);
  g_free (win32_dir);
#elif defined (OS_OSX)
  lib_dir = bean_dirs_os_x_get_lib_dir ();
#else
  lib_dir = g_build_filename (LIBDIR, "libbean-1.0", NULL);
#endif

  return lib_dir;
}

gchar *
bean_dirs_get_plugin_loader_dir (const gchar *loader_name)
{
  const gchar *env_var;
  gchar *lib_dir;
  gchar *loader_dir;

  env_var = g_getenv ("BEAN_PLUGIN_LOADERS_DIR");
  if (env_var != NULL)
    return g_build_filename (env_var, loader_name, NULL);

  lib_dir = bean_dirs_get_lib_dir ();
  loader_dir = g_build_filename (lib_dir, "loaders", NULL);

  g_free (lib_dir);

  return loader_dir;
}

gchar *
bean_dirs_get_locale_dir (void)
{
  gchar *locale_dir;

#ifdef G_OS_WIN32
  gchar *win32_dir;

  win32_dir = g_win32_get_package_installation_directory_of_module (libbean_dll);

  locale_dir = g_build_filename (win32_dir, "share", "locale", NULL);

  g_free (win32_dir);
#elif defined (OS_OSX)
  locale_dir = bean_dirs_os_x_get_locale_dir ();
#else
  locale_dir = g_build_filename (DATADIR, "locale", NULL);
#endif

  return locale_dir;
}