forked from diasurgical/devilutionX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.cpp
151 lines (127 loc) · 2.79 KB
/
paths.cpp
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
#include "utils/paths.h"
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
#ifndef TTF_FONT_DIR
#define TTF_FONT_DIR ""
#endif
#ifndef TTF_FONT_NAME
#define TTF_FONT_NAME "CharisSILB.ttf"
#endif
#ifndef MO_LANG_DIR
#define MO_LANG_DIR ""
#endif
namespace devilution {
namespace {
std::string *basePath = NULL;
std::string *prefPath = NULL;
std::string *configPath = NULL;
std::string *langPath = NULL;
std::string *ttfPath = NULL;
std::string *ttfName = NULL;
void AddTrailingSlash(std::string *path)
{
#ifdef _WIN32
if (!path->empty() && path->back() != '\\')
*path += '\\';
#else
if (!path->empty() && path->back() != '/')
*path += '/';
#endif
}
std::string *FromSDL(char *s)
{
std::string *result = new std::string(s != NULL ? s : "");
if (s != NULL) {
SDL_free(s);
} else {
SDL_Log("%s", SDL_GetError());
SDL_ClearError();
}
return result;
}
} // namespace
const std::string &GetBasePath()
{
#ifdef __vita__
if (basePath == NULL)
basePath = new std::string(GetPrefPath());
#else
if (basePath == NULL)
basePath = FromSDL(SDL_GetBasePath());
#endif
return *basePath;
}
const std::string &GetPrefPath()
{
if (prefPath == NULL)
prefPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
return *prefPath;
}
const std::string &GetConfigPath()
{
if (configPath == NULL)
configPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
return *configPath;
}
const std::string &GetTtfPath()
{
if (ttfPath == NULL)
ttfPath = new std::string(TTF_FONT_DIR);
return *ttfPath;
}
const std::string &GetLangPath()
{
if (langPath == NULL)
langPath = new std::string(MO_LANG_DIR);
return *langPath;
}
const std::string &GetTtfName()
{
if (ttfName == NULL)
ttfName = new std::string(TTF_FONT_NAME);
return *ttfName;
}
void SetBasePath(const char *path)
{
if (basePath == NULL)
basePath = new std::string;
*basePath = path;
AddTrailingSlash(basePath);
}
void SetPrefPath(const char *path)
{
if (prefPath == NULL)
prefPath = new std::string;
*prefPath = path;
AddTrailingSlash(prefPath);
}
void SetConfigPath(const char *path)
{
if (configPath == NULL)
configPath = new std::string;
*configPath = path;
AddTrailingSlash(configPath);
}
void SetLangPath(const char *path)
{
if (langPath == NULL)
langPath = new std::string;
*langPath = path;
AddTrailingSlash(langPath);
}
void SetTtfPath(const char *path)
{
if (ttfPath == NULL)
ttfPath = new std::string;
*ttfPath = path;
AddTrailingSlash(ttfPath);
}
void SetTtfName(const char *path)
{
if (ttfName == NULL)
ttfName = new std::string;
*ttfName = path;
}
} // namespace devilution