forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explorist_ini.cc
74 lines (65 loc) · 1.56 KB
/
explorist_ini.cc
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
#include "defs.h"
#include "explorist_ini.h"
#include "inifile.h"
static inifile_t* inifile;
static const char myname[] = "explorist";
#ifdef DEAD_CODE_IS_REBORN
static const char*
explorist_read_value(const char* section, const char* key)
{
return inifile_readstr(inifile, section, key);
}
#endif
static mag_info*
explorist_ini_try(const char* path)
{
char* inipath;
xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini");
inifile = inifile_init(QString::fromUtf8(inipath), myname);
if (!inifile) {
xfree(inipath);
return nullptr;
}
auto* info = (mag_info*) xmalloc(sizeof(mag_info));
info->geo_path = nullptr;
info->track_path = nullptr;
info->waypoint_path = nullptr;
QString s = inifile_readstr(inifile, "UGDS", "WpFolder");
if (!s.isNull()) {
s.replace('\\', '/');
xasprintf(&info->waypoint_path, "%s/%s", path, CSTR(s));
}
s = inifile_readstr(inifile, "UGDS", "GcFolder");
if (!s.isNull()) {
s.replace('\\', '/');
xasprintf(&info->geo_path, "%s/%s", path, CSTR(s));
}
s = inifile_readstr(inifile, "UGDS", "TrkFolder");
if (!s.isNull()) {
s.replace('\\', '/');
xasprintf(&info->track_path, "%s/%s", path, CSTR(s));
}
inifile_done(inifile);
xfree(inipath);
return info;
}
mag_info*
explorist_ini_get(const char** dirlist)
{
mag_info* r = nullptr;
while (dirlist && *dirlist) {
r = explorist_ini_try(*dirlist);
if (r) {
return r;
}
}
return r;
}
void
explorist_ini_done(mag_info* info)
{
xfree(info->geo_path);
xfree(info->track_path);
xfree(info->waypoint_path);
xfree(info);
}