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
|
/*
* Inkscape::IO::Resource - simple resource API
*
* Copyright 2006 MenTaLguY <mental@rydia.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See the file COPYING for details.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib.h> // g_assert()
#include "path-prefix.h"
#include "inkscape.h"
#include "io/sys.h"
#include "io/resource.h"
using Inkscape::IO::file_test;
namespace Inkscape {
namespace IO {
namespace Resource {
gchar *_get_path(Domain domain, Type type, char const *filename)
{
gchar *path=NULL;
switch (domain) {
case SYSTEM: {
gchar const* temp = 0;
switch (type) {
case APPICONS: temp = INKSCAPE_APPICONDIR; break;
case EXTENSIONS: temp = INKSCAPE_EXTENSIONDIR; break;
case GRADIENTS: temp = INKSCAPE_GRADIENTSDIR; break;
case ICONS: temp = INKSCAPE_PIXMAPDIR; break;
case KEYS: temp = INKSCAPE_KEYSDIR; break;
case MARKERS: temp = INKSCAPE_MARKERSDIR; break;
case PALETTES: temp = INKSCAPE_PALETTESDIR; break;
case PATTERNS: temp = INKSCAPE_PATTERNSDIR; break;
case SCREENS: temp = INKSCAPE_SCREENSDIR; break;
case TEMPLATES: temp = INKSCAPE_TEMPLATESDIR; break;
case TUTORIALS: temp = INKSCAPE_TUTORIALSDIR; break;
case UI: temp = INKSCAPE_UIDIR; break;
default: g_assert_not_reached();
}
path = g_strdup(temp);
} break;
case CREATE: {
gchar const* temp = 0;
switch (type) {
case GRADIENTS: temp = CREATE_GRADIENTSDIR; break;
case PALETTES: temp = CREATE_PALETTESDIR; break;
case PATTERNS: temp = CREATE_PATTERNSDIR; break;
default: g_assert_not_reached();
}
path = g_strdup(temp);
} break;
case USER: {
char const *name=NULL;
switch (type) {
case EXTENSIONS: name = "extensions"; break;
case GRADIENTS: name = "gradients"; break;
case ICONS: name = "icons"; break;
case KEYS: name = "keys"; break;
case MARKERS: name = "markers"; break;
case PALETTES: name = "palettes"; break;
case PATTERNS: name = "patterns"; break;
case TEMPLATES: name = "templates"; break;
case UI: name = "ui"; break;
default: return _get_path(SYSTEM, type, filename);
}
path = Inkscape::Application::profile_path(name);
} break;
}
if (filename) {
gchar *temp=g_build_filename(path, filename, NULL);
g_free(path);
path = temp;
}
return path;
}
Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename)
{
char *path = _get_path(domain, type, filename);
Util::ptr_shared<char> result=Util::share_string(path);
g_free(path);
return result;
}
/*
* Same as get_path, but checks for file's existance and falls back
* from USER to SYSTEM modes.
*/
Util::ptr_shared<char> get_filename(Type type, char const *filename)
{
Util::ptr_shared<char> result;
char *user_filename = _get_path(USER, type, filename);
char *sys_filename = _get_path(SYSTEM, type, filename);
if (file_test(user_filename, G_FILE_TEST_EXISTS)) {
result = Util::share_string(user_filename);
} else if(file_test(sys_filename, G_FILE_TEST_EXISTS)) {
result = Util::share_string(sys_filename);
} else {
g_warning("Failed to load resource: %s", filename);
}
g_free(user_filename);
g_free(sys_filename);
return result;
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|