mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-10 17:50:48 +00:00
use getcwd() or some equivalent for host_parms->basedir instead of '.' (from uhexen2)
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1016 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
52f8653d4c
commit
61775cc8b4
2 changed files with 95 additions and 3 deletions
|
@ -26,6 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef PLATFORM_OSX
|
||||||
|
#include <libgen.h> /* dirname() and basename() */
|
||||||
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -151,6 +154,7 @@ int Sys_FileTime (const char *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char cwd[MAX_OSPATH];
|
||||||
#ifdef DO_USERDIRS
|
#ifdef DO_USERDIRS
|
||||||
static char userdir[MAX_OSPATH];
|
static char userdir[MAX_OSPATH];
|
||||||
#ifdef PLATFORM_OSX
|
#ifdef PLATFORM_OSX
|
||||||
|
@ -187,11 +191,75 @@ static void Sys_GetUserdir (char *dst, size_t dstsize)
|
||||||
}
|
}
|
||||||
#endif /* DO_USERDIRS */
|
#endif /* DO_USERDIRS */
|
||||||
|
|
||||||
|
#ifdef PLATFORM_OSX
|
||||||
|
static char *OSX_StripAppBundle (char *dir)
|
||||||
|
{ /* based on the ioquake3 project at icculus.org. */
|
||||||
|
static char osx_path[MAX_OSPATH];
|
||||||
|
|
||||||
|
q_strlcpy (osx_path, dir, sizeof(osx_path));
|
||||||
|
if (strcmp(basename(osx_path), "MacOS"))
|
||||||
|
return dir;
|
||||||
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
||||||
|
if (strcmp(basename(osx_path), "Contents"))
|
||||||
|
return dir;
|
||||||
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
||||||
|
if (!strstr(basename(osx_path), ".app"))
|
||||||
|
return dir;
|
||||||
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
||||||
|
return osx_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (realpath(argv0, dst) == NULL)
|
||||||
|
{
|
||||||
|
perror("realpath");
|
||||||
|
if (getcwd(dst, dstsize - 1) == NULL)
|
||||||
|
_fail: Sys_Error ("Couldn't determine current directory");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* strip off the binary name */
|
||||||
|
if (! (tmp = strdup (dst))) goto _fail;
|
||||||
|
q_strlcpy (dst, dirname(tmp), dstsize);
|
||||||
|
free (tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = OSX_StripAppBundle(dst);
|
||||||
|
if (tmp != dst)
|
||||||
|
q_strlcpy (dst, tmp, dstsize);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (getcwd(dst, dstsize - 1) == NULL)
|
||||||
|
Sys_Error ("Couldn't determine current directory");
|
||||||
|
|
||||||
|
tmp = dst;
|
||||||
|
while (*tmp != 0)
|
||||||
|
tmp++;
|
||||||
|
while (*tmp == 0 && tmp != dst)
|
||||||
|
{
|
||||||
|
--tmp;
|
||||||
|
if (tmp != dst && *tmp == '/')
|
||||||
|
*tmp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Sys_Init (void)
|
void Sys_Init (void)
|
||||||
{
|
{
|
||||||
|
memset (cwd, 0, sizeof(cwd));
|
||||||
|
Sys_GetBasedir(host_parms->argv[0], cwd, sizeof(cwd));
|
||||||
|
host_parms->basedir = cwd;
|
||||||
#ifndef DO_USERDIRS
|
#ifndef DO_USERDIRS
|
||||||
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
||||||
#else
|
#else
|
||||||
|
memset (userdir, 0, sizeof(userdir));
|
||||||
Sys_GetUserdir(userdir, sizeof(userdir));
|
Sys_GetUserdir(userdir, sizeof(userdir));
|
||||||
Sys_mkdir (userdir);
|
Sys_mkdir (userdir);
|
||||||
host_parms->userdir = userdir;
|
host_parms->userdir = userdir;
|
||||||
|
|
|
@ -148,13 +148,37 @@ int Sys_FileTime (const char *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char cwd[1024];
|
||||||
|
|
||||||
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (GetCurrentDirectory(dstsize, dst) == 0)
|
||||||
|
Sys_Error ("Couldn't determine current directory");
|
||||||
|
|
||||||
|
tmp = dst;
|
||||||
|
while (*tmp != 0)
|
||||||
|
tmp++;
|
||||||
|
while (*tmp == 0 && tmp != dst)
|
||||||
|
{
|
||||||
|
--tmp;
|
||||||
|
if (tmp != dst && (*tmp == '/' || *tmp == '\\'))
|
||||||
|
*tmp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Sys_Init (void)
|
void Sys_Init (void)
|
||||||
{
|
{
|
||||||
OSVERSIONINFO vinfo;
|
OSVERSIONINFO vinfo;
|
||||||
|
|
||||||
host_parms->userdir = host_parms->basedir;
|
memset (cwd, 0, sizeof(cwd));
|
||||||
|
Sys_GetBasedir(NULL, cwd, sizeof(cwd));
|
||||||
|
host_parms->basedir = cwd;
|
||||||
|
|
||||||
/* userdirs not really necessary for windows guys.
|
/* userdirs not really necessary for windows guys.
|
||||||
* can be done if necessary, though... */
|
* can be done if necessary, though... */
|
||||||
|
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
||||||
|
|
||||||
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue