1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* TiLP - Tilp Is a Linking Program
5 * Copyright (C) 1999-2006 Romain Lievin
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 Initialization of portable paths
24 */
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <unistd.h>
29 #ifdef __WIN32__
30 #include <windows.h>
31 #endif
32
33 #include <glib.h>
34 #include <glib/gstdio.h>
35
36 #include "tilp_core.h"
37
38 TilpInstPaths inst_paths =
39 {
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL
49 };
50
51 /*
52 Called by TiLP at startup for initializing platform dependant paths.
53 */
54 #if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__)
init_linux_paths(void)55 static void init_linux_paths(void)
56 {
57 inst_paths.base_dir =
58 g_strconcat(SHARE_DIR, G_DIR_SEPARATOR_S, NULL);
59 inst_paths.pixmap_dir =
60 g_strconcat(inst_paths.base_dir, "pixmaps/", NULL);
61 inst_paths.icon_dir =
62 g_strconcat(inst_paths.base_dir, "icons/", NULL);
63 inst_paths.help_dir =
64 g_strconcat(inst_paths.base_dir, "help/", NULL);
65 inst_paths.manpage_dir =
66 g_strconcat(inst_paths.base_dir, "", NULL);
67 inst_paths.glade_dir =
68 g_strconcat(inst_paths.base_dir, "glade/", NULL);
69 inst_paths.builder_dir =
70 g_strconcat(inst_paths.base_dir, "builder/", NULL);
71 inst_paths.home_dir =
72 g_strdup(g_get_home_dir());
73
74 #ifdef ENABLE_NLS
75 inst_paths.locale_dir = g_strconcat(LOCALEDIR, "/", NULL);
76 #endif /* */
77 }
78 #endif /* */
79
80 #ifdef __WIN32__
init_win32_paths(void)81 static void init_win32_paths(void)
82 {
83 char *home_dir = NULL;
84 HMODULE hModule;
85 DWORD dWord;
86 char *dirname;
87 char *sBuffer;
88
89 // Init the path for the Windows version by getting the
90 // executable location.
91 hModule = GetModuleHandle("tilp.exe");
92 sBuffer = (char *) malloc(4096 * sizeof(char));
93 dWord = GetModuleFileName(hModule, sBuffer, 4096);
94 dirname = g_dirname(sBuffer);
95
96 // MinGW Option, allows Windows Users to run on a Linux File Hierarhcy
97 /*#ifdef __MINGW32__
98 #define MINGW_REL "share\\tilp2"
99
100 char *basename;
101 basename = g_path_get_basename(dirname);
102
103 // Will replace /target/bin with /target/share/tilp2 in MinGW/MSYS
104 if ((strlen(basename) == 3) && !g_ascii_strcasecmp(basename, "bin"))
105 {
106 gchar *token;
107 dirname = g_realloc(dirname, strlen(dirname) + strlen(MINGW_REL) + 1);
108 token = dirname + strlen(dirname) - 3;
109 strcpy(token, MINGW_REL);
110 }
111 #endif*/
112
113 inst_paths.base_dir = g_strconcat(dirname, "\\", NULL);
114 g_free(dirname);
115 free(sBuffer);
116
117 inst_paths.pixmap_dir =
118 g_strconcat(inst_paths.base_dir, "pixmaps\\", NULL);
119 inst_paths.icon_dir =
120 g_strconcat(inst_paths.base_dir, "icons\\", NULL);
121 inst_paths.help_dir =
122 g_strconcat(inst_paths.base_dir, "help\\", NULL);
123 inst_paths.manpage_dir =
124 g_strconcat(inst_paths.base_dir, "", NULL);
125 inst_paths.glade_dir =
126 g_strconcat(inst_paths.base_dir, "glade\\", NULL);
127 inst_paths.builder_dir =
128 g_strconcat(inst_paths.base_dir, "builder\\", NULL);
129
130 inst_paths.home_dir = g_strconcat(g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS), G_DIR_SEPARATOR_S, _("My TI Files"), NULL);
131 g_mkdir_with_parents(inst_paths.home_dir, 0755);
132
133
134 #ifdef ENABLE_NLS
135 inst_paths.locale_dir =
136 g_strconcat(inst_paths.base_dir, "locale\\", NULL);
137 #endif /* */
138 }
139 #endif /* */
140
tilp_paths_init(void)141 int tilp_paths_init(void)
142 {
143
144 #if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__)
145 init_linux_paths();
146
147 #elif defined(__WIN32__)
148 init_win32_paths();
149
150 #endif /* */
151 return 0;
152 }
153
tilp_paths_build_glade(const char * name)154 const char *tilp_paths_build_glade(const char *name)
155 {
156 static char *path = NULL;
157
158 g_free(path);
159 path = g_strconcat(inst_paths.glade_dir, name, NULL);
160
161 return path;
162 }
163
tilp_paths_build_builder(const char * name)164 const char *tilp_paths_build_builder(const char *name)
165 {
166 static char *path = NULL;
167
168 g_free(path);
169 path = g_strconcat(inst_paths.builder_dir, name, NULL);
170
171 return path;
172 }
173