2022-04-22 23:04:48 +00:00
|
|
|
#include <base/logger.h>
|
2015-08-21 21:02:50 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
#include <engine/storage.h>
|
|
|
|
|
2022-06-04 08:28:21 +00:00
|
|
|
struct SListDirectoryContext
|
2020-09-12 20:48:01 +00:00
|
|
|
{
|
2022-06-04 08:28:21 +00:00
|
|
|
const char *m_pPath;
|
|
|
|
IStorage *m_pStorage;
|
2020-09-12 20:48:01 +00:00
|
|
|
};
|
|
|
|
|
2020-11-05 10:47:07 +00:00
|
|
|
inline void ProcessItem(const char *pItemName, IStorage *pStorage)
|
2020-09-12 20:48:01 +00:00
|
|
|
{
|
|
|
|
char aConfig[2048];
|
|
|
|
|
|
|
|
size_t Len = (size_t)str_length(pItemName) + 1; // including '\0'
|
|
|
|
if(Len > sizeof(aConfig))
|
|
|
|
{
|
|
|
|
dbg_msg("config_common", "can't process overlong filename '%s'", pItemName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!str_endswith(pItemName, ".map"))
|
|
|
|
{
|
|
|
|
dbg_msg("config_common", "can't process non-map file '%s'", pItemName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
str_copy(aConfig, pItemName, sizeof(aConfig));
|
|
|
|
aConfig[Len - sizeof(".map")] = 0;
|
2023-06-13 19:06:48 +00:00
|
|
|
str_append(aConfig, ".cfg");
|
2020-09-12 20:48:01 +00:00
|
|
|
dbg_msg("config_common", "processing '%s'", pItemName);
|
|
|
|
Process(pStorage, pItemName, aConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ListdirCallback(const char *pItemName, int IsDir, int StorageType, void *pUser)
|
|
|
|
{
|
|
|
|
if(!IsDir)
|
|
|
|
{
|
2022-06-04 08:28:21 +00:00
|
|
|
SListDirectoryContext Context = *((SListDirectoryContext *)pUser);
|
2020-09-12 20:48:01 +00:00
|
|
|
char aName[2048];
|
2022-06-04 08:28:21 +00:00
|
|
|
str_format(aName, sizeof(aName), "%s/%s", Context.m_pPath, pItemName);
|
|
|
|
ProcessItem(aName, Context.m_pStorage);
|
2020-09-12 20:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:47:07 +00:00
|
|
|
int main(int argc, const char **argv) // NOLINT(misc-definitions-in-headers)
|
2015-08-21 21:02:50 +00:00
|
|
|
{
|
2022-06-13 16:07:29 +00:00
|
|
|
CCmdlineFix CmdlineFix(&argc, &argv);
|
2022-04-22 23:04:48 +00:00
|
|
|
log_set_global_logger_default();
|
2022-06-04 08:28:21 +00:00
|
|
|
|
2015-08-21 21:02:50 +00:00
|
|
|
IStorage *pStorage = CreateLocalStorage();
|
2022-06-04 08:28:21 +00:00
|
|
|
if(!pStorage)
|
|
|
|
return -1;
|
|
|
|
|
2015-08-21 21:02:50 +00:00
|
|
|
if(argc == 1)
|
|
|
|
{
|
2016-05-02 19:35:32 +00:00
|
|
|
dbg_msg("usage", "%s FILE1 [ FILE2... ]", argv[0]);
|
2020-09-12 21:40:22 +00:00
|
|
|
dbg_msg("usage", "%s DIRECTORY", argv[0]);
|
2015-08-21 21:02:50 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-09-12 20:48:01 +00:00
|
|
|
else if(argc == 2 && fs_is_dir(argv[1]))
|
|
|
|
{
|
2022-06-04 08:28:21 +00:00
|
|
|
SListDirectoryContext Context = {argv[1], pStorage};
|
2020-09-12 20:48:01 +00:00
|
|
|
pStorage->ListDirectory(IStorage::TYPE_ALL, argv[1], ListdirCallback, &Context);
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:02:50 +00:00
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
2020-09-12 20:48:01 +00:00
|
|
|
ProcessItem(argv[i], pStorage);
|
2015-08-21 21:02:50 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|