applied the user directories support patch, disabled by default. 'make DO_USERDIRS=1' to enable it.

git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@1013 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2014-09-10 07:28:28 +00:00
parent 098164746b
commit 79162a9839
8 changed files with 89 additions and 143 deletions

View file

@ -1,15 +1,15 @@
allow plain files to override files inside a PAK file -- Sander van Dijk
might not be compatible with the homedir patch yet -- O.S.
Index: Quake/common.c
===================================================================
--- Quake/common.c (revision 1003)
--- Quake/common.c (revision 1013)
+++ Quake/common.c (working copy)
@@ -1898,13 +1898,6 @@ static void COM_AddGameDirectory (const
@@ -1898,15 +1898,7 @@ static void COM_AddGameDirectory (const
if (com_searchpaths)
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
-
_add_path:
- // add the directory to the search path
- search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
- search->path_id = path_id;
@ -20,17 +20,18 @@ Index: Quake/common.c
// add any pak files in the format pak0.pak pak1.pak, ...
for (i = 0; ; i++)
{
@@ -1934,6 +1927,13 @@ static void COM_AddGameDirectory (const
}
@@ -1938,6 +1930,13 @@ _add_path:
if (!pak) break;
}
+
+ // add the directory to the search path -- moved here from before the pakX.pak loop -- svdijk
+ search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
+ search->path_id = path_id;
+ q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
+ search->next = com_searchpaths;
+ com_searchpaths = search;
}
//==============================================================================
+
if (!been_here && host_parms->userdir != host_parms->basedir)
{
been_here = true;

View file

@ -1,116 +0,0 @@
initial support for user directories, based on uhexen2 and tyrquake.
** minimally tested. **
Index: Quake/sys_sdl_unix.c
===================================================================
--- Quake/sys_sdl_unix.c (revision 1003)
+++ Quake/sys_sdl_unix.c (working copy)
@@ -20,6 +20,8 @@
*/
+#define USE_PASSWORD_FILE 1
+
#include "quakedef.h"
#include <sys/types.h>
@@ -29,6 +31,9 @@
#include <sys/time.h>
#include <fcntl.h>
#include <time.h>
+#if USE_PASSWORD_FILE
+#include <pwd.h>
+#endif /* USE_PASSWORD_FILE */
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
@@ -147,9 +152,43 @@ int Sys_FileTime (const char *path)
return -1;
}
+#define SYS_USERDIR ".quakespasm"
+static char userdir[MAX_OSPATH];
+
+static void Sys_GetUserdir (char *dst, size_t dstsize)
+{
+ size_t n;
+ const char *home_dir = NULL;
+#if USE_PASSWORD_FILE
+ struct passwd *pwent;
+
+ pwent = getpwuid( getuid() );
+ if (pwent == NULL)
+ perror("getpwuid");
+ else
+ home_dir = pwent->pw_dir;
+#endif
+ if (home_dir == NULL)
+ home_dir = getenv("HOME");
+ if (home_dir == NULL)
+ Sys_Error ("Couldn't determine userspace directory");
+
+/* what would be a maximum path for a file in the user's directory...
+ * $HOME/SYS_USERDIR/game_dir/dirname1/dirname2/dirname3/filename.ext
+ * still fits in the MAX_OSPATH == 256 definition, but just in case :
+ */
+ n = strlen(home_dir) + strlen(SYS_USERDIR) + 50;
+ if (n >= dstsize)
+ Sys_Error ("Insufficient array size for userspace directory");
+
+ q_snprintf (dst, dstsize, "%s/%s", home_dir, SYS_USERDIR);
+}
+
void Sys_Init (void)
{
- host_parms->userdir = host_parms->basedir; /* TODO: implement properly! */
+ Sys_GetUserdir(userdir, sizeof(userdir));
+ Sys_mkdir (userdir);
+ host_parms->userdir = userdir;
}
void Sys_mkdir (const char *path)
Index: Quake/common.c
===================================================================
--- Quake/common.c (revision 1003)
+++ Quake/common.c (working copy)
@@ -1890,6 +1890,7 @@ static void COM_AddGameDirectory (const
searchpath_t *search;
pack_t *pak, *qspak;
char pakfile[MAX_OSPATH];
+ qboolean been_here = false;
q_strlcpy (com_gamedir, va("%s/%s", base, dir), sizeof(com_gamedir));
@@ -1898,6 +1899,7 @@ static void COM_AddGameDirectory (const
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
+_add_path:
// add the directory to the search path
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id;
@@ -1914,6 +1916,7 @@ static void COM_AddGameDirectory (const
qspak = NULL;
else {
qboolean old = com_modified;
+ if (been_here) base = host_parms->userdir;
q_snprintf (pakfile, sizeof(pakfile), "%s/quakespasm.pak", base);
qspak = COM_LoadPackFile (pakfile);
com_modified = old;
@@ -1934,6 +1937,14 @@ static void COM_AddGameDirectory (const
}
if (!pak) break;
}
+
+ if (!been_here && host_parms->userdir != host_parms->basedir)
+ {
+ been_here = true;
+ q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, dir), sizeof(com_gamedir));
+ Sys_mkdir(com_gamedir);
+ goto _add_path;
+ }
}
//==============================================================================

View file

@ -1,9 +1,11 @@
# GNU Makefile for QuakeSpasm unix targets, Oct. 25, 2012
# GNU Makefile for QuakeSpasm unix targets, Sep. 10, 2014
# You need the SDL library fully installed.
# "make DEBUG=1" to build a debug client.
# "make SDL_CONFIG=/path/to/sdl-config" for unusual SDL installations.
# "make SDLNET=1" to use SDL_net (NOT recommended) instead of platform
# specific code.
# "make DO_USERDIRS=1" to enable user directories support
# Enable/Disable user directories support
DO_USERDIRS=0
### Enable/Disable codecs for streaming music support
USE_CODEC_WAVE=1
@ -52,7 +54,6 @@ LDFLAGS =
DFLAGS ?=
CFLAGS ?= -Wall -Wno-trigraphs
CFLAGS += $(CPUFLAGS)
ifneq ($(DEBUG),0)
DFLAGS += -DDEBUG
CFLAGS += -g
@ -68,6 +69,10 @@ define do_strip
endef
endif
ifeq ($(DO_USERDIRS),1)
CFLAGS += -DDO_USERDIRS=1
endif
### X11BASE only gets used if its in an unusual place
X11DIRS := /usr/X11R7 /usr/local/X11R7 /usr/X11R6 /usr/local/X11R6

View file

@ -1,10 +1,12 @@
# GNU Makefile for QuakeSpasm for Mac OS X, Oct. 25, 2012.
# GNU Makefile for QuakeSpasm for Mac OS X, Sep. 10, 2014.
# Usage: "make -f Makefile.darwin"
# You need the SDL library fully installed.
# "make DEBUG=1" to build a debug client.
# "make SDL_CONFIG=/path/to/sdl-config" for unusual SDL installations.
# "make SDLNET=1" to use SDL_net (NOT recommended) instead of platform
# specific code.
# "make DO_USERDIRS=1" to enable user directories support
# Enable/Disable user directories support
DO_USERDIRS=0
### Enable/Disable codecs for streaming music support
USE_CODEC_WAVE=1
@ -78,6 +80,10 @@ define do_strip
endef
endif
ifeq ($(DO_USERDIRS),1)
CFLAGS += -DDO_USERDIRS=1
endif
# not relying on sdl-config command and assuming
# /Library/Frameworks/SDL.framework is available
SDL_CFLAGS =-D_GNU_SOURCE=1 -D_THREAD_SAFE

View file

@ -1,10 +1,8 @@
# GNU Makefile for cross-compiling quakespasm.exe (Win32: MinGW)
# using cross-toolchains on a linux host, Oct. 25, 2012
# using cross-toolchains on a linux host, Sep. 10, 2014
# "make DEBUG=1" to build a debug client.
# "make SDL_CONFIG=/path/to/sdl-config" for unusual SDL installations.
# "make WINSOCK2=1" to use WinSock2 api instead of old WinSock 1.1.
# "make SDLNET=1" to use SDL_net (NOT recommended) instead of platform
# specific code.
### Enable/disable codecs for streaming music support
USE_CODEC_WAVE=1

View file

@ -1,10 +1,8 @@
# GNU Makefile for cross-compiling quakespasm.exe (Win64: MinGW-w64)
# using cross-toolchains on a linux host, Oct. 25, 2012
# using cross-toolchains on a linux host, Sep. 10, 2014
# "make DEBUG=1" to build a debug client.
# "make SDL_CONFIG=/path/to/sdl-config" for unusual SDL installations.
# "make WINSOCK2=0" to use the old WinSock 1.1 api (NOT recommended).
# "make SDLNET=1" to use SDL_net (NOT recommended) instead of platform
# specific code.
### Enable/disable codecs for streaming music support
USE_CODEC_WAVE=1
@ -54,8 +52,6 @@ WINDRES = $(TOOLCHAIN_PREFIX)windres
STRIP = $(TOOLCHAIN_PREFIX)strip
#CPUFLAGS= -mtune=k8
#CPUFLAGS= -march=atom
CPUFLAGS=
LDFLAGS =
DFLAGS ?=

View file

@ -1890,6 +1890,7 @@ static void COM_AddGameDirectory (const char *base, const char *dir)
searchpath_t *search;
pack_t *pak, *qspak;
char pakfile[MAX_OSPATH];
qboolean been_here = false;
q_strlcpy (com_gamedir, va("%s/%s", base, dir), sizeof(com_gamedir));
@ -1898,6 +1899,7 @@ static void COM_AddGameDirectory (const char *base, const char *dir)
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
_add_path:
// add the directory to the search path
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id;
@ -1914,6 +1916,7 @@ static void COM_AddGameDirectory (const char *base, const char *dir)
qspak = NULL;
else {
qboolean old = com_modified;
if (been_here) base = host_parms->userdir;
q_snprintf (pakfile, sizeof(pakfile), "%s/quakespasm.pak", base);
qspak = COM_LoadPackFile (pakfile);
com_modified = old;
@ -1934,6 +1937,14 @@ static void COM_AddGameDirectory (const char *base, const char *dir)
}
if (!pak) break;
}
if (!been_here && host_parms->userdir != host_parms->basedir)
{
been_here = true;
q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, dir), sizeof(com_gamedir));
Sys_mkdir(com_gamedir);
goto _add_path;
}
}
//==============================================================================

View file

@ -29,6 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/time.h>
#include <fcntl.h>
#include <time.h>
#ifdef DO_USERDIRS
#include <pwd.h>
#endif
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2)
@ -147,9 +150,51 @@ int Sys_FileTime (const char *path)
return -1;
}
#ifdef DO_USERDIRS
static char userdir[MAX_OSPATH];
#ifdef PLATFORM_OSX
#define SYS_USERDIR "Library/Application Support/QuakeSpasm"
#else
#define SYS_USERDIR ".quakespasm"
#endif
static void Sys_GetUserdir (char *dst, size_t dstsize)
{
size_t n;
const char *home_dir = NULL;
struct passwd *pwent;
pwent = getpwuid( getuid() );
if (pwent == NULL)
perror("getpwuid");
else
home_dir = pwent->pw_dir;
if (home_dir == NULL)
home_dir = getenv("HOME");
if (home_dir == NULL)
Sys_Error ("Couldn't determine userspace directory");
/* what would be a maximum path for a file in the user's directory...
* $HOME/SYS_USERDIR/game_dir/dirname1/dirname2/dirname3/filename.ext
* still fits in the MAX_OSPATH == 256 definition, but just in case :
*/
n = strlen(home_dir) + strlen(SYS_USERDIR) + 50;
if (n >= dstsize)
Sys_Error ("Insufficient array size for userspace directory");
q_snprintf (dst, dstsize, "%s/%s", home_dir, SYS_USERDIR);
}
#endif /* DO_USERDIRS */
void Sys_Init (void)
{
host_parms->userdir = host_parms->basedir; /* TODO: implement properly! */
#ifndef DO_USERDIRS
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
#else
Sys_GetUserdir(userdir, sizeof(userdir));
Sys_mkdir (userdir);
host_parms->userdir = userdir;
#endif
}
void Sys_mkdir (const char *path)