mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-01-19 16:00:56 +00:00
Implement -datadir, deprecate the basedir cvar.
To be able to pass UTF-8 encoded pathes through cvars both the cvar subsystem and the command parser would need a fair amount of UTF-8 understanding. And I'm not the poor soul that's going to implement that. Therefor pass the datadir trough a global variable.
This commit is contained in:
parent
efcaf17f69
commit
3634ed7013
4 changed files with 97 additions and 7 deletions
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../../common/header/common.h"
|
||||
|
||||
|
@ -41,11 +42,47 @@ main(int argc, char **argv)
|
|||
// Setup FPU if necessary
|
||||
Sys_SetupFPU();
|
||||
|
||||
// Are we portable?
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-portable") == 0) {
|
||||
// Implement command line options that the rather
|
||||
// crappy argument parser can't parse.
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
// Are we portable?
|
||||
if (strcmp(argv[i], "-portable") == 0)
|
||||
{
|
||||
is_portable = true;
|
||||
}
|
||||
|
||||
// Inject a custom data dir.
|
||||
if (strcmp(argv[i], "-datadir") == 0)
|
||||
{
|
||||
// Mkay, did the user give us an argument?
|
||||
if (i != (argc - 1))
|
||||
{
|
||||
// Check if it exists.
|
||||
struct stat sb;
|
||||
|
||||
if (stat(argv[i + 1], &sb) == 0)
|
||||
{
|
||||
if (!S_ISDIR(sb.st_mode))
|
||||
{
|
||||
printf("-datadir %s is not a directory\n", argv[i + 1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
realpath(argv[i + 1], datadir);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-datadir %s could not be found\n", argv[i + 1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-datadir needs an argument\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Prevent running Quake II as root. Only very mad
|
||||
|
|
|
@ -44,11 +44,49 @@ main(int argc, char **argv)
|
|||
// Force DPI awareness.
|
||||
Sys_SetHighDPIMode();
|
||||
|
||||
// Are we portable?
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-portable") == 0) {
|
||||
// crappy argument parser can't parse.
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
// Are we portable?
|
||||
if (strcmp(argv[i], "-portable") == 0)
|
||||
{
|
||||
is_portable = true;
|
||||
}
|
||||
|
||||
// Inject a custom data dir.
|
||||
if (strcmp(argv[i], "-datadir") == 0)
|
||||
{
|
||||
// Mkay, did the user give us an argument?
|
||||
if (i != (argc - 1))
|
||||
{
|
||||
DWORD attrib;
|
||||
WCHAR wpath[MAX_OSPATH];
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, argv[i + 1], -1, wpath, MAX_OSPATH);
|
||||
attrib = GetFileAttributesW(wpath);
|
||||
|
||||
if (attrib != INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
printf("-datadir %s is not a directory\n", argv[i + 1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Q_strlcpy(datadir, argv[i + 1], MAX_OSPATH);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-datadir %s could not be found\n", argv[i + 1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-datadir needs an argument\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Need to redirect stdout before anything happens.
|
||||
|
|
|
@ -113,6 +113,7 @@ fsPackTypes_t fs_packtypes[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
char datadir[MAX_OSPATH];
|
||||
char fs_gamedir[MAX_OSPATH];
|
||||
qboolean file_from_pak;
|
||||
|
||||
|
@ -1538,7 +1539,7 @@ void FS_BuildRawPath(void) {
|
|||
}
|
||||
|
||||
// Add $basedir/
|
||||
FS_AddDirToRawPath(fs_basedir->string, false);
|
||||
FS_AddDirToRawPath(datadir, false);
|
||||
|
||||
// Add SYSTEMDIR
|
||||
#ifdef SYSTEMWIDE
|
||||
|
@ -1569,6 +1570,17 @@ FS_InitFilesystem(void)
|
|||
fs_gamedirvar = Cvar_Get("game", "", CVAR_LATCH | CVAR_SERVERINFO);
|
||||
fs_debug = Cvar_Get("fs_debug", "0", 0);
|
||||
|
||||
// Deprecation warning, can be removed at a later time.
|
||||
if (strcmp(fs_basedir->string, ".") != 0)
|
||||
{
|
||||
Com_Printf("+set basedir is deprecated, use -datadir instead\n");
|
||||
strcpy(datadir, fs_basedir->string);
|
||||
}
|
||||
else if (strlen(datadir) == 0)
|
||||
{
|
||||
strcpy(datadir, ".");
|
||||
}
|
||||
|
||||
// Build search path
|
||||
FS_BuildRawPath();
|
||||
FS_BuildGenericSearchPath();
|
||||
|
|
|
@ -732,6 +732,9 @@ extern cvar_t *log_stats;
|
|||
/* Hack for portable client */
|
||||
extern qboolean is_portable;
|
||||
|
||||
/* Hack fo external datadir */
|
||||
extern char datadir[MAX_OSPATH];
|
||||
|
||||
extern FILE *log_stats_file;
|
||||
|
||||
/* host_speeds times */
|
||||
|
|
Loading…
Reference in a new issue