refactor InitPaths()
get rid of MAX_OS_PATH
This commit is contained in:
parent
e22e6169c9
commit
b78513f9f8
|
|
@ -490,6 +490,14 @@ public:
|
||||||
typedef String< CopiedBuffer< DefaultAllocator<char> > > CopiedString;
|
typedef String< CopiedBuffer< DefaultAllocator<char> > > CopiedString;
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Writes CopiedString \p string to \p ostream.
|
||||||
|
template<typename TextOutputStreamType>
|
||||||
|
inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const CopiedString& string ){
|
||||||
|
ostream.write( string.c_str(), strlen( string.c_str() ) );
|
||||||
|
return ostream;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \brief A non-mutable string buffer which uses reference-counting to avoid unnecessary allocations.
|
/// \brief A non-mutable string buffer which uses reference-counting to avoid unnecessary allocations.
|
||||||
template<typename Allocator>
|
template<typename Allocator>
|
||||||
class SmartBuffer : private Allocator
|
class SmartBuffer : private Allocator
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef PATH_MAX
|
|
||||||
#define MAX_OS_PATH PATH_MAX
|
|
||||||
#else
|
|
||||||
#define MAX_OS_PATH 4096
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SAFE_MALLOC
|
#define SAFE_MALLOC
|
||||||
#ifdef SAFE_MALLOC
|
#ifdef SAFE_MALLOC
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -646,9 +646,9 @@ int pk3BSPMain( int argc, char **argv ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make a pack */
|
/* make a pack */
|
||||||
auto packname = StringOutputStream( 256 )( EnginePath, "/", nameOFmap.c_str(), "_autopacked.pk3" );
|
auto packname = StringOutputStream( 256 )( g_enginePath, nameOFmap.c_str(), "_autopacked.pk3" );
|
||||||
remove( packname );
|
remove( packname );
|
||||||
auto packFailName = StringOutputStream( 256 )( EnginePath, "/", nameOFmap.c_str(), "_FAILEDpack.pk3" );
|
auto packFailName = StringOutputStream( 256 )( g_enginePath, nameOFmap.c_str(), "_FAILEDpack.pk3" );
|
||||||
remove( packFailName );
|
remove( packFailName );
|
||||||
|
|
||||||
Sys_Printf( "\n--- ZipZip ---\n" );
|
Sys_Printf( "\n--- ZipZip ---\n" );
|
||||||
|
|
@ -1387,14 +1387,14 @@ int repackBSPMain( int argc, char **argv ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write shader */
|
/* write shader */
|
||||||
stream( EnginePath, "/", nameOFrepack.c_str(), "_strippedBYrepacker.shader" );
|
stream( g_enginePath, nameOFrepack.c_str(), "_strippedBYrepacker.shader" );
|
||||||
FILE *f = fopen( stream, "wb" );
|
FILE *f = fopen( stream, "wb" );
|
||||||
fwrite( allShaders, sizeof( char ), allShaders.end() - allShaders.begin(), f );
|
fwrite( allShaders, sizeof( char ), allShaders.end() - allShaders.begin(), f );
|
||||||
fclose( f );
|
fclose( f );
|
||||||
Sys_Printf( "Shaders saved to %s\n", stream.c_str() );
|
Sys_Printf( "Shaders saved to %s\n", stream.c_str() );
|
||||||
|
|
||||||
/* make a pack */
|
/* make a pack */
|
||||||
stream( EnginePath, "/", nameOFrepack.c_str(), "_repacked.pk3" );
|
stream( g_enginePath, nameOFrepack.c_str(), "_repacked.pk3" );
|
||||||
remove( stream );
|
remove( stream );
|
||||||
|
|
||||||
Sys_Printf( "\n--- ZipZip ---\n" );
|
Sys_Printf( "\n--- ZipZip ---\n" );
|
||||||
|
|
|
||||||
|
|
@ -32,24 +32,6 @@
|
||||||
#include "q3map2.h"
|
#include "q3map2.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* path support */
|
|
||||||
#define MAX_BASE_PATHS 10
|
|
||||||
#define MAX_GAME_PATHS 10
|
|
||||||
#define MAX_PAK_PATHS 200
|
|
||||||
|
|
||||||
const char *homePath;
|
|
||||||
char installPath[ MAX_OS_PATH ];
|
|
||||||
|
|
||||||
int numBasePaths;
|
|
||||||
char *basePaths[ MAX_BASE_PATHS ];
|
|
||||||
int numGamePaths;
|
|
||||||
char *gamePaths[ MAX_GAME_PATHS ];
|
|
||||||
int numPakPaths;
|
|
||||||
char *pakPaths[ MAX_PAK_PATHS ];
|
|
||||||
const char *homeBasePath = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
some of this code is based off the original q3map port from loki
|
some of this code is based off the original q3map port from loki
|
||||||
and finds various paths. moved here from bsp.c for clarity.
|
and finds various paths. moved here from bsp.c for clarity.
|
||||||
|
|
@ -60,31 +42,27 @@ const char *homeBasePath = NULL;
|
||||||
gets the user's home dir (for ~/.q3a)
|
gets the user's home dir (for ~/.q3a)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *LokiGetHomeDir( void ){
|
CopiedString LokiGetHomeDir( void ){
|
||||||
#ifndef Q_UNIX
|
#ifndef Q_UNIX
|
||||||
return NULL;
|
return "";
|
||||||
#else
|
#else
|
||||||
static char buf[ 4096 ];
|
|
||||||
struct passwd pw, *pwp;
|
|
||||||
char *home;
|
|
||||||
static char homeBuf[MAX_OS_PATH];
|
|
||||||
|
|
||||||
|
|
||||||
/* get the home environment variable */
|
/* get the home environment variable */
|
||||||
home = getenv( "HOME" );
|
const char *home = getenv( "HOME" );
|
||||||
|
|
||||||
/* look up home dir in password database */
|
/* look up home dir in password database */
|
||||||
if( home == NULL )
|
if( home == NULL )
|
||||||
{
|
{
|
||||||
|
struct passwd pw, *pwp;
|
||||||
|
char buf[ 4096 ];
|
||||||
if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) {
|
if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) {
|
||||||
return pw.pw_dir;
|
return pw.pw_dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
snprintf( homeBuf, sizeof( homeBuf ), "%s/.", home );
|
return StringOutputStream( 256 )( home, "/." ).c_str();
|
||||||
}
|
}
|
||||||
/* return it */
|
/* return it */
|
||||||
return homeBuf;
|
return "";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,29 +73,23 @@ char *LokiGetHomeDir( void ){
|
||||||
initializes some paths on linux/os x
|
initializes some paths on linux/os x
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void LokiInitPaths( char *argv0 ){
|
void LokiInitPaths( const char *argv0, CopiedString& homePath, CopiedString& installPath ){
|
||||||
if ( homePath == NULL ) {
|
if ( homePath.empty() ) {
|
||||||
/* get home dir */
|
/* get home dir */
|
||||||
homePath = LokiGetHomeDir();
|
homePath = LokiGetHomeDir();
|
||||||
if ( homePath == NULL ) {
|
if ( homePath.empty() ) {
|
||||||
homePath = ".";
|
homePath = ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_UNIX
|
#ifndef Q_UNIX
|
||||||
/* this is kinda crap, but hey */
|
/* this is kinda crap, but hey */
|
||||||
strcpy( installPath, "../" );
|
installPath = "../";
|
||||||
#else
|
#else
|
||||||
char temp[ MAX_OS_PATH ];
|
const char *path = getenv( "PATH" );
|
||||||
char *path;
|
auto temp = StringOutputStream( 256 )( argv0 );
|
||||||
char *last;
|
|
||||||
bool found;
|
|
||||||
|
|
||||||
|
|
||||||
path = getenv( "PATH" );
|
|
||||||
|
|
||||||
/* do some path divining */
|
/* do some path divining */
|
||||||
strcpyQ( temp, argv0, sizeof( temp ) );
|
|
||||||
if ( strEmpty( path_get_last_separator( temp ) ) && path != NULL ) {
|
if ( strEmpty( path_get_last_separator( temp ) ) && path != NULL ) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -138,14 +110,14 @@ void LokiInitPaths( char *argv0 ){
|
||||||
so it will use "/opt/radiant/" as installPath, which will be expanded later to "/opt/radiant/baseq3" to find paks.
|
so it will use "/opt/radiant/" as installPath, which will be expanded later to "/opt/radiant/baseq3" to find paks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
found = false;
|
bool found = false;
|
||||||
last = path;
|
const char *last = path;
|
||||||
|
|
||||||
/* go through each : segment of path */
|
/* go through each : segment of path */
|
||||||
while ( !strEmpty( last ) && !found )
|
while ( !strEmpty( last ) && !found )
|
||||||
{
|
{
|
||||||
/* null out temp */
|
/* null out temp */
|
||||||
strClear( temp );
|
temp.clear();
|
||||||
|
|
||||||
/* find next chunk */
|
/* find next chunk */
|
||||||
last = strchr( path, ':' );
|
last = strchr( path, ':' );
|
||||||
|
|
@ -155,17 +127,16 @@ void LokiInitPaths( char *argv0 ){
|
||||||
|
|
||||||
/* found home dir candidate */
|
/* found home dir candidate */
|
||||||
if ( *path == '~' ) {
|
if ( *path == '~' ) {
|
||||||
strcpyQ( temp, homePath, sizeof( temp ) );
|
temp( homePath );
|
||||||
path++;
|
path++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* concatenate */
|
/* concatenate */
|
||||||
if ( last > ( path + 1 ) ) {
|
if ( last > ( path + 1 ) ) {
|
||||||
strncatQ( temp, path, sizeof( temp ), ( last - path ) );
|
temp << StringRange( path, last ) << '/';
|
||||||
strcatQ( temp, "/", sizeof( temp ) );
|
|
||||||
}
|
}
|
||||||
strcatQ( temp, argv0, sizeof( temp ) );
|
temp << argv0;
|
||||||
|
|
||||||
/* verify the path */
|
/* verify the path */
|
||||||
if ( access( temp, X_OK ) == 0 ) {
|
if ( access( temp, X_OK ) == 0 ) {
|
||||||
|
|
@ -176,13 +147,15 @@ void LokiInitPaths( char *argv0 ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flake */
|
/* flake */
|
||||||
if ( realpath( temp, installPath ) ) {
|
if ( char *real = realpath( temp, nullptr ); real != nullptr ) {
|
||||||
/*
|
/*
|
||||||
if "q3map2" is "/opt/radiant/tools/q3map2",
|
if "q3map2" is "/opt/radiant/tools/q3map2",
|
||||||
installPath is "/opt/radiant"
|
installPath is "/opt/radiant"
|
||||||
*/
|
*/
|
||||||
strClear( path_get_last_separator( installPath ) );
|
strClear( path_get_last_separator( real ) );
|
||||||
strClear( path_get_last_separator( installPath ) );
|
strClear( path_get_last_separator( real ) );
|
||||||
|
installPath = real;
|
||||||
|
free( real );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -227,24 +200,32 @@ const game_t *GetGame( char *arg ){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool is_unique( const std::vector<CopiedString>& list, const char *string ){
|
||||||
|
for( const auto& str : list )
|
||||||
|
if( striEqual( str.c_str(), string ) )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void insert_unique( std::vector<CopiedString>& list, const char *string ){
|
||||||
|
if( is_unique( list, string ) )
|
||||||
|
list.emplace_back( string );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
AddBasePath() - ydnar
|
AddBasePath() - ydnar
|
||||||
adds a base path to the list
|
adds a base path to the list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void AddBasePath( char *path ){
|
void AddBasePath( std::vector<CopiedString>& basePaths, const char *path ){
|
||||||
/* dummy check */
|
/* dummy check */
|
||||||
if ( strEmptyOrNull( path ) || numBasePaths >= MAX_BASE_PATHS ) {
|
if ( !strEmptyOrNull( path ) ) {
|
||||||
return;
|
/* add it to the list */
|
||||||
|
insert_unique( basePaths, StringOutputStream( 256 )( DirectoryCleaned( path ) ) );
|
||||||
|
if ( g_enginePath.empty() )
|
||||||
|
g_enginePath = basePaths.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add it to the list */
|
|
||||||
basePaths[ numBasePaths ] = copystring( path );
|
|
||||||
FixDOSName( basePaths[ numBasePaths ] );
|
|
||||||
if ( strEmpty( EnginePath ) )
|
|
||||||
strcpy( EnginePath, basePaths[ numBasePaths ] );
|
|
||||||
numBasePaths++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -254,98 +235,42 @@ void AddBasePath( char *path ){
|
||||||
adds a base path to the beginning of the list, prefixed by ~/
|
adds a base path to the beginning of the list, prefixed by ~/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void AddHomeBasePath( const char *path ){
|
void AddHomeBasePath( std::vector<CopiedString>& basePaths, const char *homePath, const char *homeBasePath ){
|
||||||
int i;
|
if ( strEmpty( homePath ) ) {
|
||||||
char temp[ MAX_OS_PATH ];
|
|
||||||
|
|
||||||
if ( homePath == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dummy check */
|
/* dummy check */
|
||||||
if ( strEmptyOrNull( path ) ) {
|
if ( strEmptyOrNull( homeBasePath ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringOutputStream str( 256 );
|
||||||
|
|
||||||
/* strip leading dot, if homePath does not end in /. */
|
/* strip leading dot, if homePath does not end in /. */
|
||||||
if ( strEqual( path, "." ) ) {
|
if ( strEqual( homeBasePath, "." ) ) {
|
||||||
/* -fs_homebase . means that -fs_home is to be used as is */
|
/* -fs_homebase . means that -fs_home is to be used as is */
|
||||||
strcpy( temp, homePath );
|
str( homePath );
|
||||||
}
|
}
|
||||||
else if ( strEqualSuffix( homePath, "/." ) ) {
|
else if ( strEqualSuffix( homePath, "/." ) ) {
|
||||||
/* concatenate home dir and path */ /* remove trailing /. of homePath */
|
/* concatenate home dir and path */ /* remove trailing /. of homePath */
|
||||||
sprintf( temp, "%.*s/%s", (int)strlen( homePath ) - 2, homePath, path );
|
str( StringRange( homePath, homePath + strlen( homePath ) - 1 ), homeBasePath );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* remove leading . of path */
|
/* remove leading . of path */
|
||||||
if ( path[0] == '.' ) {
|
if ( homeBasePath[0] == '.' ) {
|
||||||
++path;
|
++homeBasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* concatenate home dir and path */
|
/* concatenate home dir and path */
|
||||||
sprintf( temp, "%s/%s", homePath, path );
|
str( homePath, '/', homeBasePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make a hole */
|
/* add it to the beginning of the list */
|
||||||
for ( i = ( MAX_BASE_PATHS - 2 ); i >= 0; i-- )
|
const auto clean = StringOutputStream( 256 )( DirectoryCleaned( str ) );
|
||||||
basePaths[ i + 1 ] = basePaths[ i ];
|
if( is_unique( basePaths, clean ) )
|
||||||
|
basePaths.emplace( basePaths.cbegin(), clean );
|
||||||
/* add it to the list */
|
|
||||||
basePaths[ 0 ] = copystring( temp );
|
|
||||||
FixDOSName( basePaths[ 0 ] );
|
|
||||||
numBasePaths++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
AddGamePath() - ydnar
|
|
||||||
adds a game path to the list
|
|
||||||
*/
|
|
||||||
|
|
||||||
void AddGamePath( const char *path ){
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* dummy check */
|
|
||||||
if ( strEmptyOrNull( path ) || numGamePaths >= MAX_GAME_PATHS ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add it to the list */
|
|
||||||
gamePaths[ numGamePaths ] = copystring( path );
|
|
||||||
FixDOSName( gamePaths[ numGamePaths ] );
|
|
||||||
numGamePaths++;
|
|
||||||
|
|
||||||
/* don't add it if it's already there */
|
|
||||||
for ( i = 0; i < numGamePaths - 1; i++ )
|
|
||||||
{
|
|
||||||
if ( strEqual( gamePaths[i], gamePaths[numGamePaths - 1] ) ) {
|
|
||||||
free( gamePaths[numGamePaths - 1] );
|
|
||||||
gamePaths[numGamePaths - 1] = NULL;
|
|
||||||
numGamePaths--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
AddPakPath()
|
|
||||||
adds a pak path to the list
|
|
||||||
*/
|
|
||||||
|
|
||||||
void AddPakPath( char *path ){
|
|
||||||
/* dummy check */
|
|
||||||
if ( strEmptyOrNull( path ) || numPakPaths >= MAX_PAK_PATHS ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add it to the list */
|
|
||||||
pakPaths[ numPakPaths ] = copystring( path );
|
|
||||||
FixDOSName( pakPaths[ numPakPaths ] );
|
|
||||||
numPakPaths++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -357,23 +282,27 @@ void AddPakPath( char *path ){
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void InitPaths( int *argc, char **argv ){
|
void InitPaths( int *argc, char **argv ){
|
||||||
|
std::vector<CopiedString> basePaths;
|
||||||
|
std::vector<CopiedString> gamePaths;
|
||||||
|
std::vector<CopiedString> pakPaths;
|
||||||
|
|
||||||
|
CopiedString homePath;
|
||||||
|
CopiedString installPath;
|
||||||
|
const char *homeBasePath = nullptr;
|
||||||
|
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
char temp[ MAX_OS_PATH ];
|
|
||||||
const char *baseGame = nullptr;
|
const char *baseGame = nullptr;
|
||||||
|
StringOutputStream stream( 256 );
|
||||||
|
|
||||||
|
|
||||||
/* note it */
|
/* note it */
|
||||||
Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
|
Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
|
||||||
|
|
||||||
/* get the install path for backup */
|
/* get the install path for backup */
|
||||||
LokiInitPaths( argv[ 0 ] );
|
LokiInitPaths( argv[ 0 ], homePath, installPath );
|
||||||
|
|
||||||
/* set game to default (q3a) */
|
/* set game to default (q3a) */
|
||||||
g_game = &g_games[ 0 ];
|
g_game = &g_games[ 0 ];
|
||||||
numBasePaths = 0;
|
|
||||||
numGamePaths = 0;
|
|
||||||
|
|
||||||
strClear( EnginePath );
|
|
||||||
|
|
||||||
/* parse through the arguments and extract those relevant to paths */
|
/* parse through the arguments and extract those relevant to paths */
|
||||||
for ( i = 0; i < *argc; i++ )
|
for ( i = 0; i < *argc; i++ )
|
||||||
|
|
@ -385,96 +314,87 @@ void InitPaths( int *argc, char **argv ){
|
||||||
|
|
||||||
/* -game */
|
/* -game */
|
||||||
if ( striEqual( argv[ i ], "-game" ) ) {
|
if ( striEqual( argv[ i ], "-game" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );
|
Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
g_game = GetGame( argv[ i ] );
|
g_game = GetGame( argv[ i ] );
|
||||||
if ( g_game == NULL ) {
|
if ( g_game == NULL ) {
|
||||||
g_game = &g_games[ 0 ];
|
g_game = &g_games[ 0 ];
|
||||||
}
|
}
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_forbiddenpath */
|
/* -fs_forbiddenpath */
|
||||||
else if ( striEqual( argv[ i ], "-fs_forbiddenpath" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_forbiddenpath" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
g_strForbiddenDirs.emplace_back( argv[i] );
|
g_strForbiddenDirs.emplace_back( argv[i] );
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_basepath */
|
/* -fs_basepath */
|
||||||
else if ( striEqual( argv[ i ], "-fs_basepath" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_basepath" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
AddBasePath( basePaths, argv[ i ] );
|
||||||
AddBasePath( argv[ i ] );
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
argv[ i ] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_game */
|
/* -fs_game */
|
||||||
else if ( striEqual( argv[ i ], "-fs_game" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_game" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
insert_unique( gamePaths, stream( DirectoryCleaned( argv[i] ) ) );
|
||||||
AddGamePath( argv[ i ] );
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
argv[ i ] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_basegame */
|
/* -fs_basegame */
|
||||||
else if ( striEqual( argv[ i ], "-fs_basegame" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_basegame" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
baseGame = argv[ i ];
|
baseGame = argv[ i ];
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_home */
|
/* -fs_home */
|
||||||
else if ( striEqual( argv[ i ], "-fs_home" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_home" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
homePath = argv[i];
|
homePath = argv[i];
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_homebase */
|
/* -fs_homebase */
|
||||||
else if ( striEqual( argv[ i ], "-fs_homebase" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_homebase" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
homeBasePath = argv[i];
|
homeBasePath = argv[i];
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_homepath - sets both of them */
|
/* -fs_homepath - sets both of them */
|
||||||
else if ( striEqual( argv[ i ], "-fs_homepath" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_homepath" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
|
||||||
homePath = argv[i];
|
homePath = argv[i];
|
||||||
homeBasePath = ".";
|
homeBasePath = ".";
|
||||||
argv[ i ] = NULL;
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -fs_pakpath */
|
/* -fs_pakpath */
|
||||||
else if ( striEqual( argv[ i ], "-fs_pakpath" ) ) {
|
else if ( striEqual( argv[ i ], "-fs_pakpath" ) ) {
|
||||||
if ( ++i >= *argc || !argv[ i ] ) {
|
if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
|
||||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||||
}
|
}
|
||||||
argv[ i - 1 ] = NULL;
|
insert_unique( pakPaths, stream( DirectoryCleaned( argv[i] ) ) );
|
||||||
AddPakPath( argv[ i ] );
|
argv[ i - 1 ] = argv[ i ] = NULL;
|
||||||
argv[ i ] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -492,72 +412,59 @@ void InitPaths( int *argc, char **argv ){
|
||||||
*argc = k;
|
*argc = k;
|
||||||
|
|
||||||
/* add standard game path */
|
/* add standard game path */
|
||||||
AddGamePath( baseGame == nullptr? g_game->gamePath : baseGame );
|
insert_unique( gamePaths, stream( DirectoryCleaned( baseGame == nullptr? g_game->gamePath : baseGame ) ) );
|
||||||
|
|
||||||
/* if there is no base path set, figure it out */
|
/* if there is no base path set, figure it out */
|
||||||
if ( numBasePaths == 0 ) {
|
if ( basePaths.empty() ) {
|
||||||
/* this is another crappy replacement for SetQdirFromPath() */
|
/* this is another crappy replacement for SetQdirFromPath() */
|
||||||
for ( i = 0; i < *argc && numBasePaths == 0; i++ )
|
for ( i = 0; i < *argc && basePaths.empty(); i++ )
|
||||||
{
|
{
|
||||||
/* extract the arg */
|
/* extract the arg */
|
||||||
strcpy( temp, argv[ i ] );
|
stream( DirectoryCleaned( argv[ i ] ) );
|
||||||
FixDOSName( temp );
|
Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", g_game->magic, stream.c_str(), i );
|
||||||
Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", g_game->magic, temp, i );
|
|
||||||
/* check for the game's magic word */
|
/* check for the game's magic word */
|
||||||
char* found = strIstr( temp, g_game->magic );
|
char* found = strIstr( stream.c_str(), g_game->magic );
|
||||||
if( found ){
|
if( found ){
|
||||||
/* now find the next slash and nuke everything after it */
|
/* now find the next slash and nuke everything after it */
|
||||||
found = strchr( found, '/' );
|
found = strchr( found, '/' );
|
||||||
if( found )
|
if( found )
|
||||||
strClear( found );
|
strClear( found );
|
||||||
/* add this as a base path */
|
/* add this as a base path */
|
||||||
AddBasePath( temp );
|
AddBasePath( basePaths, stream.c_str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add install path */
|
/* add install path */
|
||||||
if ( numBasePaths == 0 ) {
|
if ( basePaths.empty() ) {
|
||||||
AddBasePath( installPath );
|
AddBasePath( basePaths, installPath.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check again */
|
/* check again */
|
||||||
if ( numBasePaths == 0 ) {
|
if ( basePaths.empty() ) {
|
||||||
Error( "Failed to find a valid base path." );
|
Error( "Failed to find a valid base path." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this only affects unix */
|
/* this only affects unix */
|
||||||
if ( homeBasePath != NULL ) {
|
AddHomeBasePath( basePaths, homePath.c_str(), homeBasePath != nullptr? homeBasePath : g_game->homeBasePath );
|
||||||
AddHomeBasePath( homeBasePath );
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
AddHomeBasePath( g_game->homeBasePath );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize vfs paths */
|
/* initialize vfs paths */
|
||||||
value_minimize( numBasePaths, MAX_BASE_PATHS );
|
|
||||||
value_minimize( numGamePaths, MAX_GAME_PATHS );
|
|
||||||
|
|
||||||
/* walk the list of game paths */
|
/* walk the list of game paths */
|
||||||
for ( j = 0; j < numGamePaths; j++ )
|
for ( const auto& gamePath : gamePaths )
|
||||||
{
|
{
|
||||||
/* walk the list of base paths */
|
/* walk the list of base paths */
|
||||||
for ( i = 0; i < numBasePaths; i++ )
|
for ( const auto& basePath : basePaths )
|
||||||
{
|
{
|
||||||
/* create a full path and initialize it */
|
/* create a full path and initialize it */
|
||||||
sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] );
|
vfsInitDirectory( stream( basePath, gamePath ) );
|
||||||
vfsInitDirectory( temp );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize vfs paths */
|
|
||||||
value_minimize( numPakPaths, MAX_PAK_PATHS );
|
|
||||||
|
|
||||||
/* walk the list of pak paths */
|
/* walk the list of pak paths */
|
||||||
for ( i = 0; i < numPakPaths; i++ )
|
for ( const auto& pakPath : pakPaths )
|
||||||
{
|
{
|
||||||
/* initialize this pak path */
|
/* initialize this pak path */
|
||||||
vfsInitDirectory( pakPaths[ i ] );
|
vfsInitDirectory( pakPath.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* done */
|
/* done */
|
||||||
|
|
|
||||||
|
|
@ -1909,7 +1909,7 @@ Q_EXTERN int numMapEntities Q_ASSIGN( 0 );
|
||||||
|
|
||||||
inline int blockSize[ 3 ] = { 1024, 1024, 1024 }; /* should be the same as in radiant */
|
inline int blockSize[ 3 ] = { 1024, 1024, 1024 }; /* should be the same as in radiant */
|
||||||
|
|
||||||
Q_EXTERN char EnginePath[ 1024 ];
|
Q_EXTERN CopiedString g_enginePath;
|
||||||
|
|
||||||
Q_EXTERN char name[ 1024 ];
|
Q_EXTERN char name[ 1024 ];
|
||||||
Q_EXTERN char source[ 1024 ];
|
Q_EXTERN char source[ 1024 ];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user