aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-win32-reloc.c
blob: c85d695fa66aa12bcec789ee9fa07eaba253c827 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-win32-reloc.c: Support relocatable installation on Win32
 * Copyright 2005, Novell, Inc.
 *
 * Authors:
 *   Tor Lillqvist <tml@novell.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License, version 2, as published by the Free Software Foundation.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#include <config.h>

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

#include <glib.h>
#include <libgnome/gnome-init.h>

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

/* The others are in UTF-8 */
static const char *gladedir;
static const char *helpdir;
static const char *etspecdir;
static const char *images;
static const char *iconsdir;
static const char *category_icons;
static const char *plugindir;
static const char *privdatadir;

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 char *
replace_prefix (const char *runtime_prefix,
                const char *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)
{
    char *full_prefix;  
    char *cp_prefix; 

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

        gnome_win32_get_prefixes (hmodule, &full_prefix, &cp_prefix);

        localedir = replace_prefix (cp_prefix, EVOLUTION_LOCALEDIR);
        g_free (cp_prefix);

        gladedir = replace_prefix (full_prefix, EVOLUTION_GLADEDIR);
        helpdir = replace_prefix (full_prefix, EVOLUTION_HELPDIR);
        etspecdir = replace_prefix (full_prefix, EVOLUTION_ETSPECDIR);
        images = replace_prefix (full_prefix, EVOLUTION_IMAGES);
    category_icons = replace_prefix (full_prefix, EVOLUTION_CATEGORY_ICONS);
    plugindir = replace_prefix (full_prefix, EVOLUTION_PLUGINDIR);
    privdatadir = replace_prefix (full_prefix, EVOLUTION_PRIVDATADIR);
        g_free (full_prefix);

    G_UNLOCK (mutex);
}

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

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

GETTER(localedir)
GETTER(gladedir)
GETTER(helpdir)
GETTER(etspecdir)
GETTER(images)
GETTER(iconsdir)
GETTER(category_icons)
GETTER(plugindir)
GETTER(privdatadir)