Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app will search for pk3 inside and next to the app bundle #245

Merged
merged 11 commits into from
Oct 17, 2023
11 changes: 11 additions & 0 deletions code/qcommon/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ static char fs_gamedir[MAX_OSPATH]; // this will be a single file name with no
static cvar_t *fs_debug;
static cvar_t *fs_homepath;

#ifdef __APPLE__
// Also search the .app bundle for .pk3 files
static cvar_t *fs_apppath;
#endif
static cvar_t *fs_steampath;

static cvar_t *fs_basepath;
Expand Down Expand Up @@ -4697,6 +4701,13 @@ static void FS_Startup( void ) {
FS_AddGameDirectory( fs_basepath->string, fs_basegame->string );
}

#ifdef __APPLE__
fs_apppath = Cvar_Get ("fs_apppath", Sys_DefaultAppPath(), CVAR_INIT|CVAR_PROTECTED );
// Make MacOSX also include the base path included with the .app bundle
if (fs_apppath->string[0])
FS_AddGameDirectory(fs_apppath->string, fs_basegame->string);
#endif

// fs_homepath is somewhat particular to *nix systems, only add if relevant
// NOTE: same filtering below for mods and basegame
if ( fs_homepath->string[0] && Q_stricmp( fs_homepath->string, fs_basepath->string ) ) {
Expand Down
9 changes: 8 additions & 1 deletion code/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,17 @@ FILE *Sys_FOpen( const char *ospath, const char *mode );
qboolean Sys_ResetReadOnlyAttribute( const char *ospath );

const char *Sys_Pwd( void );
void Sys_SetDefaultBasePath(const char *path);
const char *Sys_DefaultBasePath( void );
const char *Sys_DefaultHomePath( void );
const char *Sys_SteamPath( void );

#ifdef __APPLE__
char *Sys_DefaultAppPath(void);
#endif

const char *Sys_DefaultHomePath( void );
const char *Sys_Dirname( char *path );

char **Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qboolean wantsubs );
void Sys_FreeFileList( char **list );

Expand Down
4 changes: 4 additions & 0 deletions code/unix/linux_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ char *strlwr (char *s);
// signals.c
void InitSig(void);

#ifdef __APPLE__
char *Sys_StripAppBundle( char *pwd );
#endif

#endif // __LINUX_LOCAL_H__
Binary file modified code/unix/quake3_flat.icns
Binary file not shown.
73 changes: 73 additions & 0 deletions code/unix/unix_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,68 @@ void Sys_PrintBinVersion( const char* name )
}


static char binaryPath[ MAX_OSPATH ] = { 0 };
static char installPath[ MAX_OSPATH ] = { 0 };


/*
=================
Sys_SetBinaryPath
=================
*/
void Sys_SetBinaryPath(const char *path)
{
Q_strncpyz(binaryPath, path, sizeof(binaryPath));
}


/*
=================
Sys_BinaryPath
=================
*/
char *Sys_BinaryPath(void)
{
return binaryPath;
}


/*
=================
Sys_SetDefaultBasePath
=================
*/
void Sys_SetDefaultBasePath(const char *path)
{
Q_strncpyz(installPath, path, sizeof(installPath));
}


/*
=================
Sys_DefaultBasePath
=================
*/
const char *Sys_DefaultBasePath(void)
{
if (*installPath)
return installPath;
else
return Sys_Pwd();
}


/*
=================
Sys_DefaultAppPath
=================
*/
char *Sys_DefaultAppPath(void)
{
return Sys_BinaryPath();
}


/*
=================
Sys_BinName
Expand Down Expand Up @@ -876,6 +938,15 @@ int Sys_ParseArgs( int argc, const char* argv[] )
}


#ifndef DEFAULT_BASEDIR
# ifdef __APPLE__
# define DEFAULT_BASEDIR Sys_StripAppBundle(Sys_BinaryPath())
# else
# define DEFAULT_BASEDIR Sys_BinaryPath()
# endif
#endif


int main( int argc, const char* argv[] )
{
char con_title[ MAX_CVAR_VALUE_STRING ];
Expand All @@ -893,6 +964,8 @@ int main( int argc, const char* argv[] )

if ( Sys_ParseArgs( argc, argv ) ) // added this for support
return 0;
Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) );
Sys_SetDefaultBasePath( DEFAULT_BASEDIR );

// merge the command line, this is kinda silly
for ( len = 1, i = 1; i < argc; i++ )
Expand Down
61 changes: 51 additions & 10 deletions code/unix/unix_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,28 @@ qboolean Sys_GetFileStats( const char *filename, fileOffset_t *size, fileTime_t
}


/*
==================
Sys_Basename
==================
*/
const char *Sys_Basename( char *path )
{
return basename( path );
}


/*
==================
Sys_Dirname
==================
*/
const char *Sys_Dirname( char *path )
{
return dirname( path );
}


/*
=================
Sys_Mkdir
Expand Down Expand Up @@ -393,23 +415,16 @@ const char *Sys_Pwd( void )
}


/*
=================
Sys_DefaultBasePath
=================
*/
const char *Sys_DefaultBasePath( void )
{
return Sys_Pwd();
}
// Used to determine where to store user-specific files
static char homePath[ MAX_OSPATH ] = { 0 };


/*
=================
Sys_DefaultHomePath
=================
*/
const char *Sys_DefaultHomePath( void )
const char *Sys_DefaultHomePath(void)
{
// Used to determine where to store user-specific files
static char homePath[ MAX_OSPATH ];
Expand Down Expand Up @@ -621,3 +636,29 @@ qboolean Sys_SetAffinityMask( const uint64_t mask )
}
}
#endif // USE_AFFINITY_MASK


/*
=================
Sys_StripAppBundle
Discovers if passed dir is suffixed with the directory structure of a Mac OS X
.app bundle. If it is, the .app directory structure is stripped off the end and
the result is returned. If not, dir is returned untouched.
=================
*/
char *Sys_StripAppBundle( char *dir )
{
static char cwd[MAX_OSPATH];

Q_strncpyz(cwd, dir, sizeof(cwd));
if(strcmp(Sys_Basename(cwd), "MacOS"))
return dir;
Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
if(strcmp(Sys_Basename(cwd), "Contents"))
return dir;
Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
if(!strstr(Sys_Basename(cwd), ".app"))
return dir;
Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
return cwd;
}
2 changes: 1 addition & 1 deletion make-macosx-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fi

AVAILABLE_ARCHS=""

Q3E_VERSION=`grep '^VERSION=' Makefile | sed -e 's/.*=\(.*\)/\1/'`
Q3E_VERSION="1.32e"
Q3E_CLIENT_ARCHS=""
Q3E_SERVER_ARCHS=""
Q3E_CGAME_ARCHS=""
Expand Down