Reimplement the portable binaries stuff.

The big problem with the old implementation was that stdout.txt and
stderr.txt on Windows became available when nearly all the low level
initialization was already done. Regardless if the client was in
normal or in portable mode.

Solve this by scanning the command line for the string '-portable'. If
it's not found, stdout and stderr are redirected as early as possible.
If found the global variable (*sigh*) is_portable is set to true. It's
evaluated later on to set the cvar 'portable', which in turn is used
be the filesystem to decide if the home directory should be added to
the search path.

Maybe we should remove the cvar and stick to the global variable.

While at it change the maximum path length for qconsole.log from
MAX_QPATH to MAX_OSPATH. At least on my Linux laptop MAX_QPATH is
too short.

This commit is still untested on Windows!
This commit is contained in:
Yamagi Burmeister 2017-07-24 11:15:00 +02:00
parent 97f7625e49
commit 7d08906bca
6 changed files with 47 additions and 20 deletions

View File

@ -33,6 +33,8 @@
#include "../../common/header/common.h"
#include "header/unix.h"
qboolean is_portable;
int
main(int argc, char **argv)
{
@ -47,6 +49,13 @@ main(int argc, char **argv)
/* register signal handler */
registerHandler();
/* Are we portable? */
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "-portable") == 0) {
is_portable = true;
}
}
/* Prevent running Quake II as root. Only very mad
minded or stupid people even think about it. :) */
if (getuid() == 0)

View File

@ -65,6 +65,8 @@ int findhandle;
int argc;
char *argv[MAX_NUM_ARGVS];
qboolean is_portable;
/* ================================================================ */
void
@ -652,11 +654,6 @@ Sys_RedirectStdout(void)
char path_stdout[MAX_OSPATH];
char path_stderr[MAX_OSPATH];
if (portable->value)
{
return;
}
home = Sys_GetHomeDir();
if (home == NULL)
@ -755,7 +752,23 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
/* Force DPI awareness */
Sys_SetHighDPIMode();
/* FIXME: No one can see this! */
/* Parse the command line arguments */
ParseCommandLine(lpCmdLine);
/* Are we portable? */
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "-portable") == 0) {
portable = true;
}
}
/* Need to redirect stdout before anything happens. */
#ifndef DEDICATED_ONLY
if (!is_portable) {
Sys_RedirectStdout;
}
#endif
printf("Yamagi Quake II v%s\n", YQ2VERSION);
printf("=====================\n\n");
@ -791,12 +804,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
printf("Platform: %s\n", YQ2OSTYPE);
printf("Architecture: %s\n", YQ2ARCH);
/* Seed PRNG */
randk_seed();
/* Parse the command line arguments */
ParseCommandLine(lpCmdLine);
/* Call the initialization code */
Qcommon_Init(argc, argv);

View File

@ -136,7 +136,7 @@ Com_VPrintf(int print_level, const char *fmt, va_list argptr)
/* logfile */
if (logfile_active && logfile_active->value)
{
char name[MAX_QPATH];
char name[MAX_OSPATH];
if (!logfile)
{

View File

@ -1533,10 +1533,12 @@ void FS_AddDirToRawPath (const char *dir, qboolean create, qboolean screenshot)
void FS_BuildRawPath(void) {
// Add $HOME/.yq2/baseq2
// (MUST be the last dir!)
const char *homedir = Sys_GetHomeDir();
if (!portable->value) {
const char *homedir = Sys_GetHomeDir();
if (homedir != NULL) {
FS_AddDirToRawPath(homedir, true, true);
if (homedir != NULL) {
FS_AddDirToRawPath(homedir, true, true);
}
}
// Add $binarydir/baseq2

View File

@ -728,6 +728,9 @@ extern cvar_t *host_speeds;
extern cvar_t *log_stats;
extern cvar_t *portable;
/* Hack for portable client */
extern qboolean is_portable;
extern FILE *log_stats_file;
/* host_speeds times */

View File

@ -213,13 +213,15 @@ Qcommon_Init(int argc, char **argv)
Cbuf_AddEarlyCommands(false);
Cbuf_Execute();
/* Be portable, don't add HOME to the search path
* This is needed by Sys_RedirectStdout() on Windows*/
portable = Cvar_Get("portable", "0", 0);
#ifndef DEDICATED_ONLY
Sys_RedirectStdout();
#endif
/* Be portable, don't add HOME to the search path.
Doing it here is a hack. We need a working cvar
subsystem to create the cvar. But it must be
created before the file system is initialized. */
if (is_portable) {
portable = Cvar_Get("portable", "1", CVAR_NOSET);
} else {
portable = Cvar_Get("portable", "0", CVAR_NOSET);
}
FS_InitFilesystem();