DDNet documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
config_common.h
Go to the documentation of this file.
1
#include <
base/fs.h
>
2
#include <
base/logger.h
>
3
#include <
base/os.h
>
4
#include <
base/str.h
>
5
6
#include <
engine/storage.h
>
7
8
struct
SListDirectoryContext
9
{
10
const
char
*
m_pPath
;
11
IStorage
*
m_pStorage
;
12
};
13
14
inline
void
ProcessItem
(
const
char
*pItemName,
IStorage
*pStorage)
15
{
16
char
aConfig[2048];
17
18
size_t
Len = (size_t)
str_length
(pItemName) + 1;
// including '\0'
19
if
(Len >
sizeof
(aConfig))
20
{
21
log_error
(TOOL_NAME,
"can't process overlong filename '%s'"
, pItemName);
22
return
;
23
}
24
25
if
(!
str_endswith
(pItemName,
".map"
))
26
{
27
log_error
(TOOL_NAME,
"can't process non-map file '%s'"
, pItemName);
28
return
;
29
}
30
31
str_copy
(aConfig, pItemName);
32
aConfig[Len -
sizeof
(
".map"
)] = 0;
33
str_append
(aConfig,
".cfg"
);
34
log_info
(TOOL_NAME,
"processing '%s'"
, pItemName);
35
Process(pStorage, pItemName, aConfig);
36
}
37
38
static
int
ListdirCallback
(
const
char
*pItemName,
int
IsDir,
int
StorageType,
void
*pUser)
39
{
40
if
(!IsDir)
41
{
42
SListDirectoryContext
Context = *((
SListDirectoryContext
*)pUser);
43
char
aName[2048];
44
str_format
(aName,
sizeof
(aName),
"%s/%s"
, Context.
m_pPath
, pItemName);
45
ProcessItem
(aName, Context.
m_pStorage
);
46
}
47
48
return
0;
49
}
50
51
int
main
(
int
argc,
const
char
**argv)
// NOLINT(misc-definitions-in-headers)
52
{
53
CCmdlineFix
CmdlineFix(&argc, &argv);
54
log_set_global_logger_default
();
55
56
std::unique_ptr<IStorage> pStorage =
CreateLocalStorage
();
57
if
(!pStorage)
58
{
59
log_error
(TOOL_NAME,
"Error creating local storage"
);
60
return
-1;
61
}
62
63
if
(argc == 1)
64
{
65
log_error
(TOOL_NAME,
"Usage: %s FILE1 [ FILE2... ]"
, argc > 0 ? argv[0] : TOOL_NAME);
66
log_error
(TOOL_NAME,
"Usage: %s DIRECTORY"
, argc > 0 ? argv[0] : TOOL_NAME);
67
return
-1;
68
}
69
else
if
(argc == 2 &&
fs_is_dir
(argv[1]))
70
{
71
SListDirectoryContext
Context = {argv[1], pStorage.get()};
72
pStorage->ListDirectory(
IStorage::TYPE_ALL
, argv[1],
ListdirCallback
, &Context);
73
}
74
75
for
(
int
i = 1; i < argc; i++)
76
{
77
ProcessItem
(argv[i], pStorage.get());
78
}
79
return
0;
80
}
CCmdlineFix
Definition
os.h:43
IStorage
Definition
storage.h:21
IStorage::TYPE_ALL
@ TYPE_ALL
Definition
storage.h:27
main
int main(int argc, const char **argv)
Definition
client.cpp:4827
ProcessItem
void ProcessItem(const char *pItemName, IStorage *pStorage)
Definition
config_common.h:14
ListdirCallback
static int ListdirCallback(const char *pItemName, int IsDir, int StorageType, void *pUser)
Definition
config_common.h:38
fs.h
fs_is_dir
int fs_is_dir(const char *path)
Definition
fs.cpp:437
log_set_global_logger_default
void log_set_global_logger_default()
Definition
log.cpp:54
str_length
int str_length(const char *str)
Definition
str.cpp:52
str_append
void str_append(char *dst, const char *src, int dst_size)
Definition
str.cpp:25
str_copy
int str_copy(char *dst, const char *src, int dst_size)
Definition
str.cpp:18
log_error
#define log_error(sys,...)
Definition
log.h:23
log_info
#define log_info(sys,...)
Definition
log.h:25
logger.h
os.h
CreateLocalStorage
std::unique_ptr< IStorage > CreateLocalStorage()
Definition
storage.cpp:929
storage.h
str_format
#define str_format
Definition
str.cpp:89
str_endswith
const char * str_endswith(const char *str, const char *suffix)
Definition
str.cpp:426
str.h
SListDirectoryContext
Definition
config_common.h:9
SListDirectoryContext::m_pPath
const char * m_pPath
Definition
config_common.h:10
SListDirectoryContext::m_pStorage
IStorage * m_pStorage
Definition
config_common.h:11
src
tools
config_common.h
Generated by
1.18.0