mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
allow to use config_retrieve on whole directory
This commit is contained in:
parent
6bd0348bff
commit
3835395591
|
@ -1,6 +1,49 @@
|
|||
#include <base/system.h>
|
||||
#include <engine/storage.h>
|
||||
|
||||
struct ListDirectoryContext
|
||||
{
|
||||
const char *pPath;
|
||||
IStorage *pStorage;
|
||||
};
|
||||
|
||||
void ProcessItem(const char *pItemName, IStorage *pStorage)
|
||||
{
|
||||
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;
|
||||
str_append(aConfig, ".cfg", sizeof(aConfig));
|
||||
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)
|
||||
{
|
||||
ListDirectoryContext Context = *((ListDirectoryContext *)pUser);
|
||||
char aName[2048];
|
||||
str_format(aName, sizeof(aName), "%s\\%s", Context.pPath, pItemName);
|
||||
ProcessItem(aName, Context.pStorage);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
dbg_logger_stdout();
|
||||
|
@ -10,28 +53,15 @@ int main(int argc, const char **argv)
|
|||
dbg_msg("usage", "%s FILE1 [ FILE2... ]", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
else if(argc == 2 && fs_is_dir(argv[1]))
|
||||
{
|
||||
ListDirectoryContext Context = {argv[1], pStorage};
|
||||
pStorage->ListDirectory(IStorage::TYPE_ALL, argv[1], ListdirCallback, &Context);
|
||||
}
|
||||
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
char aConfig[2048];
|
||||
|
||||
size_t Len = str_length(argv[i]) + 1; // including '\0'
|
||||
if(Len > sizeof(aConfig))
|
||||
{
|
||||
dbg_msg("config_common", "can't process overlong filename '%s'", argv[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!str_endswith(argv[i], ".map"))
|
||||
{
|
||||
dbg_msg("config_common", "can't process non-map file '%s'", argv[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
str_copy(aConfig, argv[i], sizeof(aConfig));
|
||||
aConfig[Len - sizeof(".map")] = 0;
|
||||
str_append(aConfig, ".cfg", sizeof(aConfig));
|
||||
dbg_msg("config_common", "processing '%s'", argv[i]);
|
||||
Process(pStorage, argv[i], aConfig);
|
||||
ProcessItem(argv[i], pStorage);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue