aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-win32-reloc.c
blob: bf03256ae1310cf7c88d5213f98349eb0ae0029a (plain) (blame)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 *
 * This program 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.
 *
 * This program 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 General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Authors:
 *      Tor Lillqvist <tml@novell.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

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

#include <windows.h>
#include <string.h>

#include <glib.h>

/* localedir uses system codepage as it is passed to the non-UTF8ified
 * gettext library
 */
static const gchar *localedir = NULL;

/* The others are in UTF-8 */
static const gchar *bindir;
static const gchar *datadir;
static const gchar *ecpsdir;
static const gchar *etspecdir;
static const gchar *galviewsdir;
static const gchar *helpdir;
static const gchar *icondir;
static const gchar *imagesdir;
static const gchar *libdir;
static const gchar *libexecdir;
static const gchar *moduledir;
static const gchar *plugindir;
static const gchar *prefix;
static const gchar *privdatadir;
static const gchar *ruledir;
static const gchar *sounddir;
static const gchar *sysconfdir;
static const gchar *toolsdir;
static const gchar *uidir;

static HMODULE hmodule;
G_LOCK_DEFINE_STATIC (mutex);

/* Silence gcc with a prototype. Yes, this is silly. */
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
             DWORD     fdwReason,
             LPVOID    lpvReserved);

/* Minimal DllMain that just tucks away the DLL's HMODULE */
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
     DWORD     fdwReason,
     LPVOID    lpvReserved)
{
        switch (fdwReason) {
        case DLL_PROCESS_ATTACH:
                hmodule = hinstDLL;
                break;
        }
        return TRUE;
}

static gchar *
replace_prefix (const gchar *runtime_prefix,
                const gchar *configure_time_path)
{
        if (runtime_prefix &&
            strncmp (configure_time_path, EVOLUTION_PREFIX "/",
                     strlen (EVOLUTION_PREFIX) + 1) == 0) {
                return g_strconcat (runtime_prefix,
                                    configure_time_path + strlen (EVOLUTION_PREFIX),
                                    NULL);
        } else
                return g_strdup (configure_time_path);
}

static void
setup (void)
{
    gchar *full_prefix;
    gchar *cp_prefix;

        G_LOCK (mutex);
        if (localedir != NULL) {
                G_UNLOCK (mutex);
                return;
        }

    /* This requires that the libeutil DLL is installed in $bindir */
        full_prefix = g_win32_get_package_installation_directory_of_module(hmodule);
        cp_prefix = g_win32_locale_filename_from_utf8(full_prefix);

        localedir = replace_prefix (cp_prefix, EVOLUTION_LOCALEDIR);

        g_free (cp_prefix);

    prefix = g_strdup (full_prefix);

    /* It makes sense to have some of the paths overridable with
     * environment variables.
     */
    bindir = replace_prefix (full_prefix, EVOLUTION_BINDIR);
    datadir = replace_prefix (full_prefix, EVOLUTION_DATADIR);
    ecpsdir = replace_prefix (full_prefix, EVOLUTION_ECPSDIR);
    etspecdir = replace_prefix (full_prefix, EVOLUTION_ETSPECDIR);
    galviewsdir = replace_prefix (full_prefix, EVOLUTION_GALVIEWSDIR);
    helpdir = replace_prefix (full_prefix, EVOLUTION_HELPDIR);
    if (g_getenv ("EVOLUTION_ICONDIR") &&
        g_file_test (g_getenv ("EVOLUTION_ICONDIR"), G_FILE_TEST_IS_DIR))
        icondir = g_getenv ("EVOLUTION_ICONDIR");
    else
        icondir = replace_prefix (full_prefix, EVOLUTION_ICONDIR);
    if (g_getenv ("EVOLUTION_IMAGESDIR") &&
        g_file_test (g_getenv ("EVOLUTION_IMAGESDIR"), G_FILE_TEST_IS_DIR))
        imagesdir = g_getenv ("EVOLUTION_IMAGESDIR");
    else
        imagesdir = replace_prefix (full_prefix, EVOLUTION_IMAGESDIR);
    libdir = replace_prefix (full_prefix, EVOLUTION_LIBDIR);
    libexecdir = replace_prefix (full_prefix, EVOLUTION_LIBEXECDIR);
    moduledir = replace_prefix (full_prefix, EVOLUTION_MODULEDIR);
    plugindir = replace_prefix (full_prefix, EVOLUTION_PLUGINDIR);
    privdatadir = replace_prefix (full_prefix, EVOLUTION_PRIVDATADIR);
    ruledir = replace_prefix (full_prefix, EVOLUTION_RULEDIR);
    sounddir = replace_prefix (full_prefix, EVOLUTION_SOUNDDIR);
    sysconfdir = replace_prefix (full_prefix, EVOLUTION_SYSCONFDIR);
    toolsdir = replace_prefix (full_prefix, EVOLUTION_TOOLSDIR);
    uidir = replace_prefix (full_prefix, EVOLUTION_UIDIR);

        g_free (full_prefix);

    G_UNLOCK (mutex);
}

#include "e-util-private.h" /* For prototypes */

#define GETTER(varbl)               \
const gchar *                   \
_e_get_##varbl (void)               \
{                       \
        setup ();               \
        return varbl;               \
}

GETTER(bindir)
GETTER(datadir)
GETTER(ecpsdir)
GETTER(etspecdir)
GETTER(galviewsdir)
GETTER(helpdir)
GETTER(icondir)
GETTER(imagesdir)
GETTER(libdir)
GETTER(libexecdir)
GETTER(localedir)
GETTER(moduledir)
GETTER(plugindir)
GETTER(prefix)
GETTER(privdatadir)
GETTER(ruledir)
GETTER(sounddir)
GETTER(sysconfdir)
GETTER(toolsdir)
GETTER(uidir)