Updated Spanish translation
[evolution.git] / e-util / e-win32-reloc.c
blob2c559cffb47bf0f34be6955b3d7e1f1e54b1679e
1 /*
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10 * for more details.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Authors:
17 * Tor Lillqvist <tml@novell.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <windows.h>
28 #include <string.h>
30 #include <glib.h>
32 /* localedir uses system codepage as it is passed to the non-UTF8ified
33 * gettext library
35 static const gchar *localedir = NULL;
37 /* The others are in UTF-8 */
38 static const gchar *bindir;
39 static const gchar *datadir;
40 static const gchar *ecpsdir;
41 static const gchar *etspecdir;
42 static const gchar *galviewsdir;
43 static const gchar *helpdir;
44 static const gchar *icondir;
45 static const gchar *imagesdir;
46 static const gchar *libdir;
47 static const gchar *libexecdir;
48 static const gchar *moduledir;
49 static const gchar *plugindir;
50 static const gchar *prefix;
51 static const gchar *privdatadir;
52 static const gchar *ruledir;
53 static const gchar *sounddir;
54 static const gchar *sysconfdir;
55 static const gchar *toolsdir;
56 static const gchar *uidir;
58 static HMODULE hmodule;
59 G_LOCK_DEFINE_STATIC (mutex);
61 /* Silence gcc with a prototype. Yes, this is silly. */
62 BOOL WINAPI DllMain (HINSTANCE hinstDLL,
63 DWORD fdwReason,
64 LPVOID lpvReserved);
66 /* Minimal DllMain that just tucks away the DLL's HMODULE */
67 BOOL WINAPI
68 DllMain (HINSTANCE hinstDLL,
69 DWORD fdwReason,
70 LPVOID lpvReserved)
72 switch (fdwReason) {
73 case DLL_PROCESS_ATTACH:
74 hmodule = hinstDLL;
75 break;
77 return TRUE;
80 static gchar *
81 replace_prefix (const gchar *runtime_prefix,
82 const gchar *configure_time_path)
84 if (runtime_prefix &&
85 strncmp (configure_time_path, EVOLUTION_PREFIX "/",
86 strlen (EVOLUTION_PREFIX) + 1) == 0) {
87 return g_strconcat (runtime_prefix,
88 configure_time_path + strlen (EVOLUTION_PREFIX),
89 NULL);
90 } else
91 return g_strdup (configure_time_path);
94 static void
95 setup (void)
97 gchar *full_prefix;
98 gchar *cp_prefix;
100 G_LOCK (mutex);
101 if (localedir != NULL) {
102 G_UNLOCK (mutex);
103 return;
106 /* This requires that the libeutil DLL is installed in $bindir */
107 full_prefix = g_win32_get_package_installation_directory_of_module(hmodule);
108 cp_prefix = g_win32_locale_filename_from_utf8(full_prefix);
110 localedir = replace_prefix (cp_prefix, EVOLUTION_LOCALEDIR);
112 g_free (cp_prefix);
114 prefix = g_strdup (full_prefix);
116 /* It makes sense to have some of the paths overridable with
117 * environment variables.
119 bindir = replace_prefix (full_prefix, EVOLUTION_BINDIR);
120 datadir = replace_prefix (full_prefix, EVOLUTION_DATADIR);
121 ecpsdir = replace_prefix (full_prefix, EVOLUTION_ECPSDIR);
122 etspecdir = replace_prefix (full_prefix, EVOLUTION_ETSPECDIR);
123 galviewsdir = replace_prefix (full_prefix, EVOLUTION_GALVIEWSDIR);
124 helpdir = replace_prefix (full_prefix, EVOLUTION_HELPDIR);
125 if (g_getenv ("EVOLUTION_ICONDIR") &&
126 g_file_test (g_getenv ("EVOLUTION_ICONDIR"), G_FILE_TEST_IS_DIR))
127 icondir = g_getenv ("EVOLUTION_ICONDIR");
128 else
129 icondir = replace_prefix (full_prefix, EVOLUTION_ICONDIR);
130 if (g_getenv ("EVOLUTION_IMAGESDIR") &&
131 g_file_test (g_getenv ("EVOLUTION_IMAGESDIR"), G_FILE_TEST_IS_DIR))
132 imagesdir = g_getenv ("EVOLUTION_IMAGESDIR");
133 else
134 imagesdir = replace_prefix (full_prefix, EVOLUTION_IMAGESDIR);
135 libdir = replace_prefix (full_prefix, EVOLUTION_LIBDIR);
136 libexecdir = replace_prefix (full_prefix, EVOLUTION_LIBEXECDIR);
137 moduledir = replace_prefix (full_prefix, EVOLUTION_MODULEDIR);
138 plugindir = replace_prefix (full_prefix, EVOLUTION_PLUGINDIR);
139 privdatadir = replace_prefix (full_prefix, EVOLUTION_PRIVDATADIR);
140 ruledir = replace_prefix (full_prefix, EVOLUTION_RULEDIR);
141 sounddir = replace_prefix (full_prefix, EVOLUTION_SOUNDDIR);
142 sysconfdir = replace_prefix (full_prefix, EVOLUTION_SYSCONFDIR);
143 toolsdir = replace_prefix (full_prefix, EVOLUTION_TOOLSDIR);
144 uidir = replace_prefix (full_prefix, EVOLUTION_UIDIR);
146 g_free (full_prefix);
148 G_UNLOCK (mutex);
151 #include "e-util-private.h" /* For prototypes */
153 #define GETTER(varbl) \
154 const gchar * \
155 _e_get_##varbl (void) \
157 setup (); \
158 return varbl; \
161 GETTER(bindir)
162 GETTER(datadir)
163 GETTER(ecpsdir)
164 GETTER(etspecdir)
165 GETTER(galviewsdir)
166 GETTER(helpdir)
167 GETTER(icondir)
168 GETTER(imagesdir)
169 GETTER(libdir)
170 GETTER(libexecdir)
171 GETTER(localedir)
172 GETTER(moduledir)
173 GETTER(plugindir)
174 GETTER(prefix)
175 GETTER(privdatadir)
176 GETTER(ruledir)
177 GETTER(sounddir)
178 GETTER(sysconfdir)
179 GETTER(toolsdir)
180 GETTER(uidir)
182 gpointer _e_get_dll_hmodule (void)
184 return hmodule;