mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +00:00
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@999 af15c1b1-3010-417e-b628-4374ebc0bcbd
147 lines
4.1 KiB
Diff
147 lines
4.1 KiB
Diff
initial support for user directories, based on uhexen2 and tyrquake.
|
|
|
|
** minimally tested. **
|
|
|
|
Index: Quake/sys_sdl_unix.c
|
|
===================================================================
|
|
--- Quake/sys_sdl_unix.c (revision 998)
|
|
+++ 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 998)
|
|
+++ Quake/common.c (working copy)
|
|
@@ -1918,6 +1918,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));
|
|
|
|
@@ -1926,6 +1927,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;
|
|
@@ -1942,6 +1944,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;
|
|
@@ -1962,6 +1965,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;
|
|
+ }
|
|
}
|
|
|
|
/*
|
|
Index: Quake/host_cmd.c
|
|
===================================================================
|
|
--- Quake/host_cmd.c (revision 998)
|
|
+++ Quake/host_cmd.c (working copy)
|
|
@@ -149,10 +149,12 @@ void Host_Game_f (void)
|
|
|
|
if (q_strcasecmp(p, GAMENAME)) //game is not id1
|
|
{
|
|
+ qboolean been_here = false;
|
|
// assign a path_id to this game directory
|
|
if (com_searchpaths)
|
|
path_id = com_searchpaths->path_id << 1;
|
|
else path_id = 1U;
|
|
+ _add_path:
|
|
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
|
|
search->path_id = path_id;
|
|
q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
|
|
@@ -172,6 +174,14 @@ void Host_Game_f (void)
|
|
search->next = com_searchpaths;
|
|
com_searchpaths = search;
|
|
}
|
|
+
|
|
+ if (!been_here && host_parms->userdir != host_parms->basedir)
|
|
+ {
|
|
+ been_here = true;
|
|
+ q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, p), sizeof(com_gamedir));
|
|
+ Sys_mkdir(com_gamedir);
|
|
+ goto _add_path;
|
|
+ }
|
|
}
|
|
|
|
//clear out and reload appropriate data
|