2014-04-28 05:40:28 +00:00
|
|
|
initial experimental support for user directories, based on uhexen2
|
|
|
|
and tyrquake:
|
|
|
|
** against quakespasm svn revision 906.
|
2011-12-30 18:20:28 +00:00
|
|
|
** on-the-fly game directory switching not supported yet.
|
|
|
|
** minimally tested, needs more work.
|
2010-08-14 05:01:12 +00:00
|
|
|
|
2011-04-19 18:02:00 +00:00
|
|
|
Index: Quake/sys_sdl_unix.c
|
|
|
|
===================================================================
|
2014-04-28 05:40:28 +00:00
|
|
|
--- Quake/sys_sdl_unix.c (revision 906)
|
2011-04-19 18:02:00 +00:00
|
|
|
+++ 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 */
|
|
|
|
|
2012-09-15 20:11:47 +00:00
|
|
|
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
@@ -143,9 +148,43 @@
|
2011-04-19 18:02:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#define SYS_USERDIR ".quakespasm"
|
|
|
|
+static char userdir[MAX_OSPATH];
|
|
|
|
+
|
|
|
|
+static void Sys_GetUserdir (char *dst, size_t dstsize)
|
|
|
|
+{
|
2011-10-24 17:40:12 +00:00
|
|
|
+ size_t n;
|
|
|
|
+ const char *home_dir = NULL;
|
2011-04-19 18:02:00 +00:00
|
|
|
+#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 :
|
|
|
|
+ */
|
2011-10-24 17:40:12 +00:00
|
|
|
+ n = strlen(home_dir) + strlen(SYS_USERDIR) + 50;
|
|
|
|
+ if (n >= dstsize)
|
2011-04-19 18:02:00 +00:00
|
|
|
+ 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));
|
2011-10-24 17:40:12 +00:00
|
|
|
+ Sys_mkdir (userdir);
|
2011-04-19 18:02:00 +00:00
|
|
|
+ host_parms->userdir = userdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_mkdir (const char *path)
|
2010-08-14 05:01:12 +00:00
|
|
|
Index: Quake/common.c
|
|
|
|
===================================================================
|
2014-04-28 05:40:28 +00:00
|
|
|
--- Quake/common.c (revision 906)
|
2010-08-14 05:01:12 +00:00
|
|
|
+++ Quake/common.c (working copy)
|
2014-04-28 05:40:28 +00:00
|
|
|
@@ -1919,6 +1919,7 @@ static void COM_AddGameDirectory (const
|
2010-08-14 05:01:12 +00:00
|
|
|
searchpath_t *search;
|
2014-04-27 08:28:16 +00:00
|
|
|
pack_t *pak, *qspak;
|
2010-08-14 05:01:12 +00:00
|
|
|
char pakfile[MAX_OSPATH];
|
2011-01-11 20:05:12 +00:00
|
|
|
+ qboolean been_here = false;
|
2010-08-14 05:01:12 +00:00
|
|
|
|
2014-04-27 08:28:16 +00:00
|
|
|
q_strlcpy (com_gamedir, va("%s/%s", base, dir), sizeof(com_gamedir));
|
2010-08-14 05:01:12 +00:00
|
|
|
|
2014-04-28 05:40:28 +00:00
|
|
|
@@ -1927,6 +1928,7 @@ static void COM_AddGameDirectory (const
|
2011-01-11 20:05:12 +00:00
|
|
|
path_id = com_searchpaths->path_id << 1;
|
|
|
|
else path_id = 1U;
|
|
|
|
|
|
|
|
+_add_path:
|
2010-08-14 05:01:12 +00:00
|
|
|
// add the directory to the search path
|
2010-08-29 11:15:21 +00:00
|
|
|
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
|
2011-01-11 20:05:12 +00:00
|
|
|
search->path_id = path_id;
|
2014-04-28 05:40:28 +00:00
|
|
|
@@ -1943,6 +1945,7 @@ static void COM_AddGameDirectory (const
|
|
|
|
qspak = NULL;
|
|
|
|
else {
|
|
|
|
qboolean old = com_modified;
|
|
|
|
+ if (been_here) base = host_parms->basedir;
|
|
|
|
q_snprintf (pakfile, sizeof(pakfile), "%s/quakespasm.pak", base);
|
|
|
|
qspak = COM_LoadPackFile (pakfile);
|
|
|
|
com_modified = old;
|
|
|
|
@@ -1963,6 +1966,14 @@ static void COM_AddGameDirectory (const
|
2014-04-27 08:28:16 +00:00
|
|
|
}
|
|
|
|
if (!pak) break;
|
2011-01-11 20:05:12 +00:00
|
|
|
}
|
|
|
|
+
|
2011-04-19 18:02:00 +00:00
|
|
|
+ if (!been_here && host_parms->userdir != host_parms->basedir)
|
2011-01-11 20:05:12 +00:00
|
|
|
+ {
|
|
|
|
+ been_here = true;
|
2011-12-30 18:20:28 +00:00
|
|
|
+ q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, dir), sizeof(com_gamedir));
|
2011-01-11 20:05:12 +00:00
|
|
|
+ Sys_mkdir(com_gamedir);
|
|
|
|
+ goto _add_path;
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
2014-04-27 08:28:16 +00:00
|
|
|
/*
|