fix a really nasty bug where downloads were going to the wrong place. there may be more fixes needed so qf copes with the new fs_basepath, and esp ~.

This commit is contained in:
Bill Currie 2000-04-30 10:50:24 +00:00
parent 2607f7e1ac
commit 85254360f4
5 changed files with 94 additions and 54 deletions

View file

@ -54,5 +54,7 @@ extern cvar_t *r_reportedgeout;
extern cvar_t *r_maxedges; extern cvar_t *r_maxedges;
extern cvar_t *r_numedges; extern cvar_t *r_numedges;
extern cvar_t *developer; extern cvar_t *developer;
extern cvar_t *fs_basepath;
extern cvar_t *fs_sharepath;
#endif /* _CVARS_H */ #endif /* _CVARS_H */

View file

@ -52,9 +52,6 @@
#include <dirent.h> #include <dirent.h>
#include <fnmatch.h> #include <fnmatch.h>
#ifndef _WIN32
#include <pwd.h>
#endif
#ifdef WIN32 #ifdef WIN32
#include <io.h> #include <io.h>
@ -277,6 +274,10 @@ void
COM_CreatePath ( char *path ) COM_CreatePath ( char *path )
{ {
char *ofs; char *ofs;
char e_path[PATH_MAX];
Qexpand_squiggle (path, e_path);
path = e_path;
for (ofs = path+1 ; *ofs ; ofs++) { for (ofs = path+1 ; *ofs ; ofs++) {
if (*ofs == '/') { // create the directory if (*ofs == '/') { // create the directory
@ -826,41 +827,18 @@ COM_AddDirectory (char *dir)
{ {
searchpath_t *search; searchpath_t *search;
char *p; char *p;
char e_dir[PATH_MAX];
if (strncmp (dir, "~/", 2) == 0) { Qexpand_squiggle (dir, e_dir);
char *home; dir = e_dir;
char *tmp;
#ifndef _WIN32 if ((p = strrchr(dir, '/')) != NULL) {
struct passwd *pwd_ent; strcpy (gamedirfile, ++p);
if ((pwd_ent = getpwuid (getuid()))) {
home = pwd_ent->pw_dir;
printf("%p\n",pwd_ent);
} else
#endif
home = getenv("HOME");
if (home)
{
#if !defined(_WIN32)
tmp = alloca(strlen(home)+strlen(dir));
#else
tmp = malloc(strlen(home)+strlen(dir));
#endif
strcpy (tmp, home);
strcat (tmp, dir+1); // skip leading ~
dir=tmp;
}
//if (pwd_ent)
// free (pwd_ent);
}
if ((p = strrchr(dir, '/')) != NULL)
strcpy(gamedirfile, ++p);
else
strcpy(gamedirfile, dir);
strcpy (com_gamedir, dir); strcpy (com_gamedir, dir);
} else {
strcpy (gamedirfile, dir);
strcpy (com_gamedir, va("%s/%s", fs_basepath->string, dir));
}
// //
// add the directory to the search path // add the directory to the search path
@ -962,7 +940,7 @@ void COM_Gamedir_f (void)
if (Cmd_Argc() == 1) if (Cmd_Argc() == 1)
{ {
Con_Printf ("Current gamedir: %s\n", com_gamedir); Con_Printf ("Current gamedir: %s\n", gamedirfile);
return; return;
} }

View file

@ -32,19 +32,66 @@
#ifdef HAVE_MALLOC_H #ifdef HAVE_MALLOC_H
#include <malloc.h> #include <malloc.h>
#endif #endif
#include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <quakeio.h> #include <quakeio.h>
#include <string.h>
#ifdef WIN32 #ifdef WIN32
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#else
#include <pwd.h>
#endif #endif
QFile *Qopen(const char *path, const char *mode) void
Qexpand_squiggle(const char *path, char *dest)
{
char *home;
#ifndef _WIN32
struct passwd *pwd_ent;
#endif
if (strncmp (path, "~/",2) != 0) {
strcpy (dest,path);
return;
}
#ifndef _WIN32
if ((pwd_ent = getpwuid (getuid()))) {
home = pwd_ent->pw_dir;
} else
#endif
home = getenv("HOME");
if (home) {
strcpy (dest, home);
strcat (dest, path+1); // skip leading ~
} else
strcpy (dest,path);
}
int
Qrename(const char *old, const char *new)
{
char e_old[PATH_MAX];
char e_new[PATH_MAX];
Qexpand_squiggle (old, e_old);
Qexpand_squiggle (new, e_new);
return rename (e_old, e_new);
}
QFile *
Qopen(const char *path, const char *mode)
{ {
QFile *file; QFile *file;
char m[80],*p; char m[80],*p;
int zip=0; int zip=0;
char e_path[PATH_MAX];
Qexpand_squiggle (path, e_path);
path = e_path;
for (p=m; *mode && p-m<(sizeof(m)-1); mode++) { for (p=m; *mode && p-m<(sizeof(m)-1); mode++) {
if (*mode=='z') { if (*mode=='z') {
@ -77,7 +124,8 @@ QFile *Qopen(const char *path, const char *mode)
return file; return file;
} }
QFile *Qdopen(int fd, const char *mode) QFile *
Qdopen(int fd, const char *mode)
{ {
QFile *file; QFile *file;
char m[80],*p; char m[80],*p;
@ -118,7 +166,8 @@ QFile *Qdopen(int fd, const char *mode)
return file; return file;
} }
void Qclose(QFile *file) void
Qclose(QFile *file)
{ {
if (file->file) if (file->file)
fclose(file->file); fclose(file->file);
@ -129,7 +178,8 @@ void Qclose(QFile *file)
free(file); free(file);
} }
int Qread(QFile *file, void *buf, int count) int
Qread(QFile *file, void *buf, int count)
{ {
if (file->file) if (file->file)
return fread(buf, 1, count, file->file); return fread(buf, 1, count, file->file);
@ -141,7 +191,8 @@ int Qread(QFile *file, void *buf, int count)
#endif #endif
} }
int Qwrite(QFile *file, void *buf, int count) int
Qwrite(QFile *file, void *buf, int count)
{ {
if (file->file) if (file->file)
return fwrite(buf, 1, count, file->file); return fwrite(buf, 1, count, file->file);
@ -153,7 +204,8 @@ int Qwrite(QFile *file, void *buf, int count)
#endif #endif
} }
int Qprintf(QFile *file, const char *fmt, ...) int
Qprintf(QFile *file, const char *fmt, ...)
{ {
va_list args; va_list args;
int ret=-1; int ret=-1;
@ -180,7 +232,8 @@ int Qprintf(QFile *file, const char *fmt, ...)
return ret; return ret;
} }
char *Qgets(QFile *file, char *buf, int count) char *
Qgets(QFile *file, char *buf, int count)
{ {
if (file->file) if (file->file)
return fgets(buf, count, file->file); return fgets(buf, count, file->file);
@ -192,7 +245,8 @@ char *Qgets(QFile *file, char *buf, int count)
#endif #endif
} }
int Qgetc(QFile *file) int
Qgetc(QFile *file)
{ {
if (file->file) if (file->file)
return fgetc(file->file); return fgetc(file->file);
@ -204,7 +258,8 @@ int Qgetc(QFile *file)
#endif #endif
} }
int Qputc(QFile *file, int c) int
Qputc(QFile *file, int c)
{ {
if (file->file) if (file->file)
return fputc(c, file->file); return fputc(c, file->file);
@ -216,7 +271,8 @@ int Qputc(QFile *file, int c)
#endif #endif
} }
int Qseek(QFile *file, long offset, int whence) int
Qseek(QFile *file, long offset, int whence)
{ {
if (file->file) if (file->file)
return fseek(file->file, offset, whence); return fseek(file->file, offset, whence);
@ -228,7 +284,8 @@ int Qseek(QFile *file, long offset, int whence)
#endif #endif
} }
long Qtell(QFile *file) long
Qtell(QFile *file)
{ {
if (file->file) if (file->file)
return ftell(file->file); return ftell(file->file);
@ -240,7 +297,8 @@ long Qtell(QFile *file)
#endif #endif
} }
int Qflush(QFile *file) int
Qflush(QFile *file)
{ {
if (file->file) if (file->file)
return fflush(file->file); return fflush(file->file);
@ -252,7 +310,8 @@ int Qflush(QFile *file)
#endif #endif
} }
int Qeof(QFile *file) int
Qeof(QFile *file)
{ {
if (file->file) if (file->file)
return feof(file->file); return feof(file->file);

View file

@ -46,6 +46,8 @@ typedef struct {
#endif #endif
} QFile; } QFile;
void Qexpand_squiggle(const char *path, char *dest);
int Qrename(const char *old, const char *new);
QFile *Qopen(const char *path, const char *mode); QFile *Qopen(const char *path, const char *mode);
QFile *Qdopen(int fd, const char *mode); QFile *Qdopen(int fd, const char *mode);
void Qclose(QFile *file); void Qclose(QFile *file);

View file

@ -378,10 +378,9 @@ void CL_ParseDownload (void)
if (strncmp(cls.downloadtempname,"skins/",6)) if (strncmp(cls.downloadtempname,"skins/",6))
snprintf(name, sizeof(name), "%s/%s", com_gamedir, cls.downloadtempname); snprintf(name, sizeof(name), "%s/%s", com_gamedir, cls.downloadtempname);
else else
snprintf(name, sizeof(name), "qw/%s", cls.downloadtempname); snprintf(name, sizeof(name), "%s/qw/%s", fs_basepath->string, cls.downloadtempname);
COM_CreatePath (name); COM_CreatePath (name);
cls.download = Qopen (name, "wb"); cls.download = Qopen (name, "wb");
if (!cls.download) if (!cls.download)
{ {
@ -429,10 +428,10 @@ void CL_ParseDownload (void)
snprintf(oldn, sizeof(oldn), "%s/%s", com_gamedir, cls.downloadtempname); snprintf(oldn, sizeof(oldn), "%s/%s", com_gamedir, cls.downloadtempname);
snprintf(newn, sizeof(newn), "%s/%s", com_gamedir, cls.downloadname); snprintf(newn, sizeof(newn), "%s/%s", com_gamedir, cls.downloadname);
} else { } else {
snprintf(oldn, sizeof(oldn), "qw/%s", cls.downloadtempname); snprintf(oldn, sizeof(oldn), "%s/qw/%s", fs_basepath->string, cls.downloadtempname);
snprintf(newn, sizeof(newn), "qw/%s", cls.downloadname); snprintf(newn, sizeof(newn), "%s/qw/%s", fs_basepath->string, cls.downloadname);
} }
r = rename (oldn, newn); r = Qrename (oldn, newn);
if (r) if (r)
Con_Printf ("failed to rename.\n"); Con_Printf ("failed to rename.\n");
} }