mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-26 22:31:17 +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;
|
||||
}
|
||||
|
||||
const char *Sys_DefaultBasePath( void ) {
|
||||
return Sys_Cwd();
|
||||
}
|
||||
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||
switch(type) {
|
||||
case PATH_BASE:
|
||||
path = Sys_Cwd();
|
||||
return true;
|
||||
|
||||
const char *Sys_DefaultSavePath( void ) {
|
||||
return cvarSystem->GetCVarString( "fs_basepath" );
|
||||
}
|
||||
case PATH_SAVE:
|
||||
path = cvarSystem->GetCVarString("fs_basepath");
|
||||
return true;
|
||||
|
||||
const char *Sys_EXEPath( void ) {
|
||||
return "";
|
||||
case PATH_EXE:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
const char * Sys_DefaultBasePath( void ) { return ""; }
|
||||
const char * Sys_DefaultSavePath( void ) { return ""; }
|
||||
bool Sys_GetPath(sysPath_t, idStr &) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) { return 0; }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2813,12 +2813,12 @@ void idFileSystemLocal::Init( void ) {
|
|||
common->StartupVariable( "fs_restrict", false );
|
||||
common->StartupVariable( "fs_searchAddons", false );
|
||||
|
||||
if ( fs_basepath.GetString()[0] == '\0' ) {
|
||||
fs_basepath.SetString( Sys_DefaultBasePath() );
|
||||
}
|
||||
if ( fs_savepath.GetString()[0] == '\0' ) {
|
||||
fs_savepath.SetString( Sys_DefaultSavePath() );
|
||||
}
|
||||
idStr path;
|
||||
if (fs_basepath.GetString()[0] == '\0' && Sys_GetPath(PATH_BASE, path))
|
||||
fs_basepath.SetString(path);
|
||||
|
||||
if (fs_savepath.GetString()[0] == '\0' && Sys_GetPath(PATH_SAVE, path))
|
||||
fs_savepath.SetString(path);
|
||||
|
||||
if ( fs_devpath.GetString()[0] == '\0' ) {
|
||||
#ifdef WIN32
|
||||
|
@ -3824,10 +3824,9 @@ void idFileSystemLocal::FindDLL( const char *name, char _dllPath[ MAX_OSPATH ],
|
|||
#if ID_FAKE_PURE
|
||||
if ( 1 ) {
|
||||
#else
|
||||
if ( !serverPaks.Num() ) {
|
||||
if (!serverPaks.Num() && Sys_GetPath(PATH_EXE, dllPath)) {
|
||||
#endif
|
||||
// from executable directory first - this is handy for developement
|
||||
dllPath = Sys_EXEPath( );
|
||||
dllPath.StripFilename( );
|
||||
dllPath.AppendPath( dllName );
|
||||
dllFile = OpenExplicitFileRead( dllPath );
|
||||
|
|
|
@ -42,73 +42,61 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#include <locale.h>
|
||||
|
||||
static idStr basepath;
|
||||
static idStr savepath;
|
||||
|
||||
/*
|
||||
==============
|
||||
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) {
|
||||
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||
const char *s;
|
||||
char buf[MAX_OSPATH];
|
||||
char buf2[MAX_OSPATH];
|
||||
struct stat st;
|
||||
idStr testbase;
|
||||
basepath = Sys_EXEPath();
|
||||
if ( basepath.Length() ) {
|
||||
basepath.StripFilename();
|
||||
testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR;
|
||||
if ( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
|
||||
return basepath.c_str();
|
||||
} else {
|
||||
common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() );
|
||||
size_t len;
|
||||
|
||||
path.Clear();
|
||||
|
||||
switch(type) {
|
||||
case PATH_BASE:
|
||||
if (Sys_GetPath(PATH_EXE, path)) {
|
||||
path.StripFilename();
|
||||
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() ) {
|
||||
basepath = Posix_Cwd();
|
||||
testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR;
|
||||
if ( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
|
||||
return basepath.c_str();
|
||||
} else {
|
||||
common->Printf("no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str());
|
||||
|
||||
s = Posix_Cwd();
|
||||
if (path != s) {
|
||||
idStr::snPrintf(buf, sizeof(buf), "%s/" BASE_GAMEDIR, s);
|
||||
if (stat(buf, &st) != -1 && S_ISDIR(st.st_mode)) {
|
||||
path = buf;
|
||||
return true;
|
||||
} 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 ) {
|
||||
basepath.Clear();
|
||||
savepath.Clear();
|
||||
Posix_Shutdown();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,43 +50,32 @@ FPU_EXCEPTION_DIVIDE_BY_ZERO | \
|
|||
/* FPU_EXCEPTION_INEXACT_RESULT | */ \
|
||||
0
|
||||
|
||||
/*
|
||||
==============
|
||||
Sys_EXEPath
|
||||
==============
|
||||
*/
|
||||
const char *Sys_EXEPath( void ) {
|
||||
static char exepath[ MAXPATHLEN ];
|
||||
strncpy( exepath, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
||||
return exepath;
|
||||
}
|
||||
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||
char buf[MAXPATHLEN];
|
||||
char *snap;
|
||||
|
||||
/*
|
||||
==========
|
||||
Sys_DefaultSavePath
|
||||
==========
|
||||
*/
|
||||
const char *Sys_DefaultSavePath(void) {
|
||||
static char savepath[ MAXPATHLEN ];
|
||||
sprintf( savepath, "%s/Library/Application Support/Doom 3", [NSHomeDirectory() cString] );
|
||||
return savepath;
|
||||
}
|
||||
switch(type) {
|
||||
case PATH_BASE:
|
||||
strncpy(buf, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
||||
snap = strrchr(buf, '/');
|
||||
if (snap)
|
||||
*snap = '\0';
|
||||
|
||||
/*
|
||||
==========
|
||||
Sys_DefaultBasePath
|
||||
==========
|
||||
*/
|
||||
const char *Sys_DefaultBasePath(void) {
|
||||
static char basepath[ MAXPATHLEN ];
|
||||
path = buf;
|
||||
return true;
|
||||
|
||||
strncpy( basepath, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN );
|
||||
char *snap = strrchr( basepath, '/' );
|
||||
if ( snap ) {
|
||||
*snap = '\0';
|
||||
case PATH_SAVE:
|
||||
sprintf(buf, "%s/Library/Application Support/Doom 3", [NSHomeDirectory() cString]);
|
||||
path = buf;
|
||||
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__
|
||||
#define __SYS_PUBLIC__
|
||||
|
||||
class idStr;
|
||||
|
||||
typedef enum {
|
||||
CPUID_NONE = 0x00000,
|
||||
CPUID_UNSUPPORTED = 0x00001, // unsupported (386/486)
|
||||
|
@ -115,6 +117,12 @@ struct sysMemoryStats_t {
|
|||
int availExtendedVirtual;
|
||||
};
|
||||
|
||||
enum sysPath_t {
|
||||
PATH_BASE,
|
||||
PATH_SAVE,
|
||||
PATH_EXE
|
||||
};
|
||||
|
||||
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 );
|
||||
// NOTE: do we need to guarantee the same output on all platforms?
|
||||
const char * Sys_TimeStampToStr( ID_TIME_T timeStamp );
|
||||
const char * Sys_DefaultBasePath( void );
|
||||
const char * Sys_DefaultSavePath( void );
|
||||
const char * Sys_EXEPath( void );
|
||||
|
||||
bool Sys_GetPath(sysPath_t type, idStr &path);
|
||||
|
||||
// use fs_debug to verbose Sys_ListFiles
|
||||
// returns -1 if directory was not found (the list is cleared)
|
||||
|
|
|
@ -228,33 +228,25 @@ const char *Sys_Cwd( void ) {
|
|||
return cwd;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
Sys_DefaultBasePath
|
||||
==============
|
||||
*/
|
||||
const char *Sys_DefaultBasePath( void ) {
|
||||
return Sys_Cwd();
|
||||
}
|
||||
bool Sys_GetPath(sysPath_t type, idStr &path) {
|
||||
char buf[MAX_OSPATH];
|
||||
|
||||
/*
|
||||
==============
|
||||
Sys_DefaultSavePath
|
||||
==============
|
||||
*/
|
||||
const char *Sys_DefaultSavePath( void ) {
|
||||
return cvarSystem->GetCVarString( "fs_basepath" );
|
||||
}
|
||||
switch(type) {
|
||||
case PATH_BASE:
|
||||
path = Sys_Cwd();
|
||||
return true;
|
||||
|
||||
/*
|
||||
==============
|
||||
Sys_EXEPath
|
||||
==============
|
||||
*/
|
||||
const char *Sys_EXEPath( void ) {
|
||||
static char exe[ MAX_OSPATH ];
|
||||
GetModuleFileName( NULL, exe, sizeof( exe ) - 1 );
|
||||
return exe;
|
||||
case PATH_SAVE:
|
||||
path = cvarSystem->GetCVarString("fs_basepath");
|
||||
return true;
|
||||
|
||||
case PATH_EXE:
|
||||
GetModuleFileName(NULL, buf, sizeof(buf) - 1);
|
||||
path = buf;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue