mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-27 06:32:27 +00:00
Unify Sys_*Path() into Sys_GetPath()
This commit is contained in:
parent
3256783af1
commit
478fa783f6
6 changed files with 123 additions and 143 deletions
|
@ -119,16 +119,21 @@ const char *Sys_Cwd( void ) {
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Sys_DefaultBasePath( void ) {
|
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||||
return Sys_Cwd();
|
switch(type) {
|
||||||
}
|
case PATH_BASE:
|
||||||
|
path = Sys_Cwd();
|
||||||
|
return true;
|
||||||
|
|
||||||
const char *Sys_DefaultSavePath( void ) {
|
case PATH_SAVE:
|
||||||
return cvarSystem->GetCVarString( "fs_basepath" );
|
path = cvarSystem->GetCVarString("fs_basepath");
|
||||||
}
|
return true;
|
||||||
|
|
||||||
const char *Sys_EXEPath( void ) {
|
case PATH_EXE:
|
||||||
return "";
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) {
|
int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) {
|
||||||
|
@ -172,8 +177,10 @@ int Sys_ListFiles( const char *directory, const char *extension, idStrList &list
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
const char * Sys_DefaultBasePath( void ) { return ""; }
|
bool Sys_GetPath(sysPath_t, idStr &) {
|
||||||
const char * Sys_DefaultSavePath( void ) { return ""; }
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) { return 0; }
|
int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) { return 0; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2813,12 +2813,12 @@ void idFileSystemLocal::Init( void ) {
|
||||||
common->StartupVariable( "fs_restrict", false );
|
common->StartupVariable( "fs_restrict", false );
|
||||||
common->StartupVariable( "fs_searchAddons", false );
|
common->StartupVariable( "fs_searchAddons", false );
|
||||||
|
|
||||||
if ( fs_basepath.GetString()[0] == '\0' ) {
|
idStr path;
|
||||||
fs_basepath.SetString( Sys_DefaultBasePath() );
|
if (fs_basepath.GetString()[0] == '\0' && Sys_GetPath(PATH_BASE, path))
|
||||||
}
|
fs_basepath.SetString(path);
|
||||||
if ( fs_savepath.GetString()[0] == '\0' ) {
|
|
||||||
fs_savepath.SetString( Sys_DefaultSavePath() );
|
if (fs_savepath.GetString()[0] == '\0' && Sys_GetPath(PATH_SAVE, path))
|
||||||
}
|
fs_savepath.SetString(path);
|
||||||
|
|
||||||
if ( fs_devpath.GetString()[0] == '\0' ) {
|
if ( fs_devpath.GetString()[0] == '\0' ) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -3824,10 +3824,9 @@ void idFileSystemLocal::FindDLL( const char *name, char _dllPath[ MAX_OSPATH ],
|
||||||
#if ID_FAKE_PURE
|
#if ID_FAKE_PURE
|
||||||
if ( 1 ) {
|
if ( 1 ) {
|
||||||
#else
|
#else
|
||||||
if ( !serverPaks.Num() ) {
|
if (!serverPaks.Num() && Sys_GetPath(PATH_EXE, dllPath)) {
|
||||||
#endif
|
#endif
|
||||||
// from executable directory first - this is handy for developement
|
// from executable directory first - this is handy for developement
|
||||||
dllPath = Sys_EXEPath( );
|
|
||||||
dllPath.StripFilename( );
|
dllPath.StripFilename( );
|
||||||
dllPath.AppendPath( dllName );
|
dllPath.AppendPath( dllName );
|
||||||
dllFile = OpenExplicitFileRead( dllPath );
|
dllFile = OpenExplicitFileRead( dllPath );
|
||||||
|
|
|
@ -42,73 +42,61 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
static idStr basepath;
|
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||||
static idStr savepath;
|
const char *s;
|
||||||
|
char buf[MAX_OSPATH];
|
||||||
/*
|
char buf2[MAX_OSPATH];
|
||||||
==============
|
|
||||||
Sys_DefaultSavePath
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
const char *Sys_DefaultSavePath(void) {
|
|
||||||
sprintf( savepath, "%s/.doom3", getenv( "HOME" ) );
|
|
||||||
return savepath.c_str();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
==============
|
|
||||||
Sys_EXEPath
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
const char *Sys_EXEPath( void ) {
|
|
||||||
static char buf[ 1024 ];
|
|
||||||
idStr linkpath;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
buf[ 0 ] = '\0';
|
|
||||||
sprintf( linkpath, "/proc/%d/exe", getpid() );
|
|
||||||
len = readlink( linkpath.c_str(), buf, sizeof( buf ) );
|
|
||||||
if ( len == -1 ) {
|
|
||||||
Sys_Printf("couldn't stat exe path link %s\n", linkpath.c_str());
|
|
||||||
buf[ 0 ] = '\0';
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_DefaultBasePath
|
|
||||||
|
|
||||||
Get the default base path
|
|
||||||
- binary image path
|
|
||||||
- current directory
|
|
||||||
- hardcoded
|
|
||||||
Try to be intelligent: if there is no BASE_GAMEDIR, try the next path
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
const char *Sys_DefaultBasePath(void) {
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
idStr testbase;
|
size_t len;
|
||||||
basepath = Sys_EXEPath();
|
|
||||||
if ( basepath.Length() ) {
|
path.Clear();
|
||||||
basepath.StripFilename();
|
|
||||||
testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR;
|
switch(type) {
|
||||||
if ( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
|
case PATH_BASE:
|
||||||
return basepath.c_str();
|
if (Sys_GetPath(PATH_EXE, path)) {
|
||||||
} else {
|
path.StripFilename();
|
||||||
common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() );
|
idStr::snPrintf(buf, sizeof(buf), "%s/" BASE_GAMEDIR, path.c_str());
|
||||||
|
if (stat(buf, &st) != -1 && S_ISDIR(st.st_mode)) {
|
||||||
|
path = buf;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
common->Printf("no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, path.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ( basepath != Posix_Cwd() ) {
|
s = Posix_Cwd();
|
||||||
basepath = Posix_Cwd();
|
if (path != s) {
|
||||||
testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR;
|
idStr::snPrintf(buf, sizeof(buf), "%s/" BASE_GAMEDIR, s);
|
||||||
if ( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
|
if (stat(buf, &st) != -1 && S_ISDIR(st.st_mode)) {
|
||||||
return basepath.c_str();
|
path = buf;
|
||||||
} else {
|
return true;
|
||||||
common->Printf("no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str());
|
} else {
|
||||||
|
common->Printf("no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
common->Printf("WARNING: using hardcoded default base path\n");
|
||||||
|
path = LINUX_DEFAULT_PATH;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case PATH_SAVE:
|
||||||
|
idStr::snPrintf(buf, sizeof(buf), "%s/.doom3", getenv("HOME"));
|
||||||
|
path = buf;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case PATH_EXE:
|
||||||
|
idStr::snPrintf(buf, sizeof(buf), "/proc/%d/exe", getpid());
|
||||||
|
len = readlink(buf, buf2, sizeof(buf2));
|
||||||
|
if (len == -1) {
|
||||||
|
Sys_Printf("couldn't stat exe path link %s\n", buf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = buf2;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
common->Printf( "WARNING: using hardcoded default base path\n" );
|
|
||||||
return LINUX_DEFAULT_PATH;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -117,8 +105,6 @@ Sys_Shutdown
|
||||||
===============
|
===============
|
||||||
*/
|
*/
|
||||||
void Sys_Shutdown( void ) {
|
void Sys_Shutdown( void ) {
|
||||||
basepath.Clear();
|
|
||||||
savepath.Clear();
|
|
||||||
Posix_Shutdown();
|
Posix_Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,43 +50,32 @@ FPU_EXCEPTION_DIVIDE_BY_ZERO | \
|
||||||
/* FPU_EXCEPTION_INEXACT_RESULT | */ \
|
/* FPU_EXCEPTION_INEXACT_RESULT | */ \
|
||||||
0
|
0
|
||||||
|
|
||||||
/*
|
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||||
==============
|
char buf[MAXPATHLEN];
|
||||||
Sys_EXEPath
|
char *snap;
|
||||||
==============
|
|
||||||
*/
|
|
||||||
const char *Sys_EXEPath( void ) {
|
|
||||||
static char exepath[ MAXPATHLEN ];
|
|
||||||
strncpy( exepath, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
|
||||||
return exepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
switch(type) {
|
||||||
==========
|
case PATH_BASE:
|
||||||
Sys_DefaultSavePath
|
strncpy(buf, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
||||||
==========
|
snap = strrchr(buf, '/');
|
||||||
*/
|
if (snap)
|
||||||
const char *Sys_DefaultSavePath(void) {
|
*snap = '\0';
|
||||||
static char savepath[ MAXPATHLEN ];
|
|
||||||
sprintf( savepath, "%s/Library/Application Support/Doom 3", [NSHomeDirectory() cString] );
|
|
||||||
return savepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
path = buf;
|
||||||
==========
|
return true;
|
||||||
Sys_DefaultBasePath
|
|
||||||
==========
|
|
||||||
*/
|
|
||||||
const char *Sys_DefaultBasePath(void) {
|
|
||||||
static char basepath[ MAXPATHLEN ];
|
|
||||||
|
|
||||||
strncpy( basepath, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
case PATH_SAVE:
|
||||||
char *snap = strrchr( basepath, '/' );
|
sprintf(buf, "%s/Library/Application Support/Doom 3", [NSHomeDirectory() cString]);
|
||||||
if ( snap ) {
|
path = buf;
|
||||||
*snap = '\0';
|
return true;
|
||||||
|
|
||||||
|
case PATH_EXE:
|
||||||
|
strncpy(buf, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN);
|
||||||
|
path = buf;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return basepath;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -29,6 +29,8 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
#ifndef __SYS_PUBLIC__
|
#ifndef __SYS_PUBLIC__
|
||||||
#define __SYS_PUBLIC__
|
#define __SYS_PUBLIC__
|
||||||
|
|
||||||
|
class idStr;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CPUID_NONE = 0x00000,
|
CPUID_NONE = 0x00000,
|
||||||
CPUID_UNSUPPORTED = 0x00001, // unsupported (386/486)
|
CPUID_UNSUPPORTED = 0x00001, // unsupported (386/486)
|
||||||
|
@ -115,6 +117,12 @@ struct sysMemoryStats_t {
|
||||||
int availExtendedVirtual;
|
int availExtendedVirtual;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sysPath_t {
|
||||||
|
PATH_BASE,
|
||||||
|
PATH_SAVE,
|
||||||
|
PATH_EXE
|
||||||
|
};
|
||||||
|
|
||||||
template<class type> class idList; // for Sys_ListFiles
|
template<class type> class idList; // for Sys_ListFiles
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,9 +237,8 @@ void Sys_Mkdir( const char *path );
|
||||||
ID_TIME_T Sys_FileTimeStamp( FILE *fp );
|
ID_TIME_T Sys_FileTimeStamp( FILE *fp );
|
||||||
// NOTE: do we need to guarantee the same output on all platforms?
|
// NOTE: do we need to guarantee the same output on all platforms?
|
||||||
const char * Sys_TimeStampToStr( ID_TIME_T timeStamp );
|
const char * Sys_TimeStampToStr( ID_TIME_T timeStamp );
|
||||||
const char * Sys_DefaultBasePath( void );
|
|
||||||
const char * Sys_DefaultSavePath( void );
|
bool Sys_GetPath(sysPath_t type, idStr &path);
|
||||||
const char * Sys_EXEPath( void );
|
|
||||||
|
|
||||||
// use fs_debug to verbose Sys_ListFiles
|
// use fs_debug to verbose Sys_ListFiles
|
||||||
// returns -1 if directory was not found (the list is cleared)
|
// returns -1 if directory was not found (the list is cleared)
|
||||||
|
|
|
@ -228,33 +228,25 @@ const char *Sys_Cwd( void ) {
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||||
==============
|
char buf[MAX_OSPATH];
|
||||||
Sys_DefaultBasePath
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
const char *Sys_DefaultBasePath( void ) {
|
|
||||||
return Sys_Cwd();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
switch(type) {
|
||||||
==============
|
case PATH_BASE:
|
||||||
Sys_DefaultSavePath
|
path = Sys_Cwd();
|
||||||
==============
|
return true;
|
||||||
*/
|
|
||||||
const char *Sys_DefaultSavePath( void ) {
|
|
||||||
return cvarSystem->GetCVarString( "fs_basepath" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
case PATH_SAVE:
|
||||||
==============
|
path = cvarSystem->GetCVarString("fs_basepath");
|
||||||
Sys_EXEPath
|
return true;
|
||||||
==============
|
|
||||||
*/
|
case PATH_EXE:
|
||||||
const char *Sys_EXEPath( void ) {
|
GetModuleFileName(NULL, buf, sizeof(buf) - 1);
|
||||||
static char exe[ MAX_OSPATH ];
|
path = buf;
|
||||||
GetModuleFileName( NULL, exe, sizeof( exe ) - 1 );
|
return true;
|
||||||
return exe;
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue