ddnet/src/engine/e_engine.c

72 lines
1.5 KiB
C
Raw Normal View History

2007-11-25 19:42:40 +00:00
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
2007-11-08 09:11:32 +00:00
#include <string.h>
#include <stdio.h>
2007-12-15 10:24:49 +00:00
#include <engine/e_system.h>
#include <engine/e_interface.h>
#include <engine/e_config.h>
2007-11-08 09:11:32 +00:00
static char application_save_path[512] = {0};
const char *engine_savepath(const char *filename, char *buffer, int max)
{
2007-11-18 22:06:41 +00:00
sprintf(buffer, "%s/%s", application_save_path, filename);
2007-11-08 09:11:32 +00:00
return buffer;
}
void engine_init(const char *appname, int argc, char **argv)
{
/* init the network */
net_init();
/* create storage location */
{
char path[1024] = {0};
fs_storage_path(appname, application_save_path, sizeof(application_save_path));
if(fs_makedir(application_save_path) == 0)
{
strcpy(path, application_save_path);
strcat(path, "/screenshots");
fs_makedir(path);
}
}
/* reset the config */
config_reset();
/* load the configuration */
{
int i;
int abs = 0;
2007-11-08 09:11:32 +00:00
const char *config_filename = "default.cfg";
char buf[1024];
for(i = 1; i < argc; i++)
{
if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1)
{
config_filename = argv[i+1];
abs = 1;
2007-11-08 09:11:32 +00:00
i++;
}
}
if(abs)
config_load(config_filename);
else
config_load(engine_savepath(config_filename, buf, sizeof(buf)));
2007-11-08 09:11:32 +00:00
}
/* search arguments for overrides */
{
int i;
for(i = 1; i < argc; i++)
config_set(argv[i]);
}
}
void engine_writeconfig()
{
char buf[1024];
config_save(engine_savepath("default.cfg", buf, sizeof(buf)));
}