Hack a simple way to specify the CFGDIR at command line.

Until now CFGDIR was hardcoded to YamagiQ2 on Windows and .yq2 on
everything else. Sometimes it's desireable to have a separate dir
for some tasks, for example  whentesting things that introduce new
cvars. Add -cfgdir to override CFGDIR.
This commit is contained in:
Yamagi 2020-03-16 14:28:12 +01:00
parent fd1874ff0f
commit b2f0430c9f
5 changed files with 46 additions and 2 deletions

View File

@ -27,6 +27,7 @@
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <unistd.h>
#include <sys/stat.h>
@ -88,6 +89,22 @@ main(int argc, char **argv)
return 1;
}
}
// Inject a custom config dir.
if (strcmp(argv[i], "-cfgdir") == 0)
{
// We need an argument.
if (i != (argc - 1))
{
Q_strlcpy(cfgdir, argv[i + 1], sizeof(cfgdir));
}
else
{
printf("-cfgdir needs an argument\n");
return 1;
}
}
}
/* Prevent running Quake II as root. Only very mad

View File

@ -50,6 +50,9 @@ static void *game_library;
// Evil hack to determine if stdin is available
qboolean stdin_active = true;
// Config dir
char cfgdir[MAX_OSPATH] = CFGDIR;
// Console logfile
extern FILE *logfile;
@ -476,7 +479,7 @@ Sys_GetHomeDir(void)
return NULL;
}
snprintf(gdir, sizeof(gdir), "%s/%s/", home, CFGDIR);
snprintf(gdir, sizeof(gdir), "%s/%s/", home, cfgdir);
return gdir;
}

View File

@ -87,6 +87,25 @@ main(int argc, char **argv)
return 1;
}
}
// Inject a custom config dir.
if (strcmp(argv[i], "-cfgdir") == 0)
{
// We need an argument.
if (i != (argc - 1))
{
WCHAR wpath[MAX_OSPATH];
MultiByteToWideChar(CP_UTF8, 0, argv[i + 1], -1, wpath, MAX_OSPATH);
Q_strlcpy(cfgdir, wpath, sizeof(cfgdir));
}
else
{
printf("-cfgdir needs an argument\n");
return 1;
}
}
}
// Need to redirect stdout before anything happens.

View File

@ -195,6 +195,8 @@ static qboolean checkForHelp(int argc, char **argv)
printf("Yamagi Quake II v%s\n", YQ2VERSION);
printf("Most interesting commandline arguments:\n");
printf("-h or --help: Show this help\n");
printf("-cfgdir <path>\n");
printf(" set the name of your config directory\n");
printf("-datadir <path>\n");
printf(" set path to your Quake2 game data (the directory baseq2/ is in)\n");
printf("-portable\n");

View File

@ -746,9 +746,12 @@ extern cvar_t *sv_entfile;
/* Hack for portable client */
extern qboolean is_portable;
/* Hack fo external datadir */
/* Hack for external datadir */
extern char datadir[MAX_OSPATH];
/* Hack for external datadir */
extern char cfgdir[MAX_OSPATH];
/* Hack for working 'game' cmd */
extern char userGivenGame[MAX_QPATH];