This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCConfigMgr.cpp
116 lines (87 loc) · 2.35 KB
/
CConfigMgr.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
/*
QMM - Q3 MultiMod
Copyright 2004-2024
https://github.com/thecybermind/qmm/
3-clause BSD license: https://opensource.org/license/bsd-3-clause
Created By:
Kevin Masterson < [email protected] >
*/
#include <stddef.h> //for NULL
#include "CConfigMgr.h"
#include "pdb.h"
CConfigMgr::CConfigMgr() {
this->db = NULL;
this->isloaded = 0;
}
CConfigMgr::~CConfigMgr() {
if (this->db)
pdb_unload(this->db);
if (this->isloaded)
unload_pdb_lib();
}
void CConfigMgr::LoadLib(const char* pdblib) {
if (!this->isloaded)
this->isloaded = load_pdb_lib((char*)pdblib);
}
void CConfigMgr::LoadConf(const char* file) {
if (this->isloaded && !this->db)
this->db = pdb_load((char*)file);
//set case-insensitive search mode on the config file
pdb_enable(this->db, PDB_CASE_INSENSITIVE);
}
int CConfigMgr::IsLibLoaded() {
return this->isloaded;
}
int CConfigMgr::IsConfLoaded() {
return this->db ? 1 : 0;
}
void CConfigMgr::UnloadConf() {
if (this->db)
pdb_unload(this->db);
this->db = NULL;
}
void CConfigMgr::UnloadLib() {
if (this->db)
pdb_unload(this->db);
this->db = NULL;
if (this->isloaded)
unload_pdb_lib();
this->isloaded = 0;
}
int CConfigMgr::GetInt(const char* path, int def) {
if (!this->isloaded || !this->db)
return def;
int* x = (int*)pdb_query(this->db, (char*)path);
return x ? *x : def;
}
char* CConfigMgr::GetStr(const char* path) {
if (!this->isloaded || !this->db)
return NULL;
return (char*)pdb_query(this->db, (char*)path);
}
void* CConfigMgr::GetListRootNode(const char* path) {
struct pdb_linkList* x = (struct pdb_linkList*)pdb_query(this->db, (char*)path);
if (!x)
return NULL;
return x->root;
}
void* CConfigMgr::GetListNextNode(void* listnode) {
if (!listnode)
return NULL;
return ((struct pdb_linkNode*)listnode)->next;
}
char* CConfigMgr::GetListNodeID(void* listnode) {
if (!listnode)
return NULL;
//this has to grab the pdb node inside the listnode and then grab the pdb node's id
struct pdb_node_t* x = (struct pdb_node_t*) (((struct pdb_linkNode*)listnode)->data);
if (!x)
return NULL;
return x->id;
}
CConfigMgr* CConfigMgr::GetInstance() {
if (!CConfigMgr::instance)
CConfigMgr::instance = new CConfigMgr;
return CConfigMgr::instance;
}
CConfigMgr* CConfigMgr::instance = NULL;