mirror of
https://git.code.sf.net/p/quake/quakeforge-old
synced 2024-11-21 19:32:30 +00:00
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:
parent
2607f7e1ac
commit
85254360f4
5 changed files with 94 additions and 54 deletions
|
@ -54,5 +54,7 @@ extern cvar_t *r_reportedgeout;
|
|||
extern cvar_t *r_maxedges;
|
||||
extern cvar_t *r_numedges;
|
||||
extern cvar_t *developer;
|
||||
extern cvar_t *fs_basepath;
|
||||
extern cvar_t *fs_sharepath;
|
||||
|
||||
#endif /* _CVARS_H */
|
||||
|
|
|
@ -52,9 +52,6 @@
|
|||
|
||||
#include <dirent.h>
|
||||
#include <fnmatch.h>
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
|
@ -277,6 +274,10 @@ void
|
|||
COM_CreatePath ( char *path )
|
||||
{
|
||||
char *ofs;
|
||||
char e_path[PATH_MAX];
|
||||
|
||||
Qexpand_squiggle (path, e_path);
|
||||
path = e_path;
|
||||
|
||||
for (ofs = path+1 ; *ofs ; ofs++) {
|
||||
if (*ofs == '/') { // create the directory
|
||||
|
@ -826,41 +827,18 @@ COM_AddDirectory (char *dir)
|
|||
{
|
||||
searchpath_t *search;
|
||||
char *p;
|
||||
char e_dir[PATH_MAX];
|
||||
|
||||
if (strncmp (dir, "~/", 2) == 0) {
|
||||
char *home;
|
||||
char *tmp;
|
||||
Qexpand_squiggle (dir, e_dir);
|
||||
dir = e_dir;
|
||||
|
||||
#ifndef _WIN32
|
||||
struct passwd *pwd_ent;
|
||||
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)
|
||||
if ((p = strrchr(dir, '/')) != NULL) {
|
||||
strcpy (gamedirfile, ++p);
|
||||
else
|
||||
strcpy(gamedirfile, 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
|
||||
|
@ -962,7 +940,7 @@ void COM_Gamedir_f (void)
|
|||
|
||||
if (Cmd_Argc() == 1)
|
||||
{
|
||||
Con_Printf ("Current gamedir: %s\n", com_gamedir);
|
||||
Con_Printf ("Current gamedir: %s\n", gamedirfile);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,19 +32,66 @@
|
|||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <quakeio.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#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;
|
||||
char m[80],*p;
|
||||
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++) {
|
||||
if (*mode=='z') {
|
||||
|
@ -77,7 +124,8 @@ QFile *Qopen(const char *path, const char *mode)
|
|||
return file;
|
||||
}
|
||||
|
||||
QFile *Qdopen(int fd, const char *mode)
|
||||
QFile *
|
||||
Qdopen(int fd, const char *mode)
|
||||
{
|
||||
QFile *file;
|
||||
char m[80],*p;
|
||||
|
@ -118,7 +166,8 @@ QFile *Qdopen(int fd, const char *mode)
|
|||
return file;
|
||||
}
|
||||
|
||||
void Qclose(QFile *file)
|
||||
void
|
||||
Qclose(QFile *file)
|
||||
{
|
||||
if (file->file)
|
||||
fclose(file->file);
|
||||
|
@ -129,7 +178,8 @@ void Qclose(QFile *file)
|
|||
free(file);
|
||||
}
|
||||
|
||||
int Qread(QFile *file, void *buf, int count)
|
||||
int
|
||||
Qread(QFile *file, void *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fread(buf, 1, count, file->file);
|
||||
|
@ -141,7 +191,8 @@ int Qread(QFile *file, void *buf, int count)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qwrite(QFile *file, void *buf, int count)
|
||||
int
|
||||
Qwrite(QFile *file, void *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fwrite(buf, 1, count, file->file);
|
||||
|
@ -153,7 +204,8 @@ int Qwrite(QFile *file, void *buf, int count)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qprintf(QFile *file, const char *fmt, ...)
|
||||
int
|
||||
Qprintf(QFile *file, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret=-1;
|
||||
|
@ -180,7 +232,8 @@ int Qprintf(QFile *file, const char *fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
char *Qgets(QFile *file, char *buf, int count)
|
||||
char *
|
||||
Qgets(QFile *file, char *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fgets(buf, count, file->file);
|
||||
|
@ -192,7 +245,8 @@ char *Qgets(QFile *file, char *buf, int count)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qgetc(QFile *file)
|
||||
int
|
||||
Qgetc(QFile *file)
|
||||
{
|
||||
if (file->file)
|
||||
return fgetc(file->file);
|
||||
|
@ -204,7 +258,8 @@ int Qgetc(QFile *file)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qputc(QFile *file, int c)
|
||||
int
|
||||
Qputc(QFile *file, int c)
|
||||
{
|
||||
if (file->file)
|
||||
return fputc(c, file->file);
|
||||
|
@ -216,7 +271,8 @@ int Qputc(QFile *file, int c)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qseek(QFile *file, long offset, int whence)
|
||||
int
|
||||
Qseek(QFile *file, long offset, int whence)
|
||||
{
|
||||
if (file->file)
|
||||
return fseek(file->file, offset, whence);
|
||||
|
@ -228,7 +284,8 @@ int Qseek(QFile *file, long offset, int whence)
|
|||
#endif
|
||||
}
|
||||
|
||||
long Qtell(QFile *file)
|
||||
long
|
||||
Qtell(QFile *file)
|
||||
{
|
||||
if (file->file)
|
||||
return ftell(file->file);
|
||||
|
@ -240,7 +297,8 @@ long Qtell(QFile *file)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qflush(QFile *file)
|
||||
int
|
||||
Qflush(QFile *file)
|
||||
{
|
||||
if (file->file)
|
||||
return fflush(file->file);
|
||||
|
@ -252,7 +310,8 @@ int Qflush(QFile *file)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Qeof(QFile *file)
|
||||
int
|
||||
Qeof(QFile *file)
|
||||
{
|
||||
if (file->file)
|
||||
return feof(file->file);
|
||||
|
|
|
@ -46,6 +46,8 @@ typedef struct {
|
|||
#endif
|
||||
} 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 *Qdopen(int fd, const char *mode);
|
||||
void Qclose(QFile *file);
|
||||
|
|
|
@ -378,10 +378,9 @@ void CL_ParseDownload (void)
|
|||
if (strncmp(cls.downloadtempname,"skins/",6))
|
||||
snprintf(name, sizeof(name), "%s/%s", com_gamedir, cls.downloadtempname);
|
||||
else
|
||||
snprintf(name, sizeof(name), "qw/%s", cls.downloadtempname);
|
||||
snprintf(name, sizeof(name), "%s/qw/%s", fs_basepath->string, cls.downloadtempname);
|
||||
|
||||
COM_CreatePath (name);
|
||||
|
||||
cls.download = Qopen (name, "wb");
|
||||
if (!cls.download)
|
||||
{
|
||||
|
@ -429,10 +428,10 @@ void CL_ParseDownload (void)
|
|||
snprintf(oldn, sizeof(oldn), "%s/%s", com_gamedir, cls.downloadtempname);
|
||||
snprintf(newn, sizeof(newn), "%s/%s", com_gamedir, cls.downloadname);
|
||||
} else {
|
||||
snprintf(oldn, sizeof(oldn), "qw/%s", cls.downloadtempname);
|
||||
snprintf(newn, sizeof(newn), "qw/%s", cls.downloadname);
|
||||
snprintf(oldn, sizeof(oldn), "%s/qw/%s", fs_basepath->string, cls.downloadtempname);
|
||||
snprintf(newn, sizeof(newn), "%s/qw/%s", fs_basepath->string, cls.downloadname);
|
||||
}
|
||||
r = rename (oldn, newn);
|
||||
r = Qrename (oldn, newn);
|
||||
if (r)
|
||||
Con_Printf ("failed to rename.\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue