Skip to content

Commit

Permalink
Unify com_homepath and use XDG_DATA_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Mar 4, 2018
1 parent cb7ccba commit 95c3dea
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
5 changes: 4 additions & 1 deletion code/qcommon/common.c
Expand Up @@ -2678,7 +2678,10 @@ void Com_Init( char *commandLine ) {

com_standalone = Cvar_Get("com_standalone", "0", CVAR_ROM);
com_basegame = Cvar_Get("com_basegame", BASEGAME, CVAR_INIT);
com_homepath = Cvar_Get("com_homepath", "", CVAR_INIT);
com_homepath = Cvar_Get("com_homepath", HOMEPATH_NAME, CVAR_INIT);
if ( !com_homepath->string[0] ) {
Cvar_ForceReset( "com_homepath" );
}

if(!com_basegame->string[0])
Cvar_ForceReset("com_basegame");
Expand Down
18 changes: 12 additions & 6 deletions code/qcommon/q_shared.h
Expand Up @@ -31,19 +31,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define BASEGAME "foobar"
#define CLIENT_WINDOW_TITLE "changeme"
#define CLIENT_WINDOW_MIN_TITLE "changeme2"
#define HOMEPATH_NAME_UNIX ".foo"
#define HOMEPATH_NAME_WIN "FooBar"
#define HOMEPATH_NAME_MACOSX HOMEPATH_NAME_WIN

// GNU/Linux: $HOME/.local/share/homepath-name (lower case and spaces replaced with hyphens)
// MacOS: $HOME/Library/Application Support/Homepath Name
// Windows: %APPDATA%\Homepath Name
#define HOMEPATH_NAME "FooBar"

#define GAMENAME_FOR_MASTER "foobar" // must NOT contain whitespace
// #define LEGACY_PROTOCOL // You probably don't need this for your standalone game
#else
#define PRODUCT_NAME "ioq3"
#define BASEGAME "baseq3"
#define CLIENT_WINDOW_TITLE "ioquake3"
#define CLIENT_WINDOW_MIN_TITLE "ioq3"
#define HOMEPATH_NAME_UNIX ".q3a"
#define HOMEPATH_NAME_WIN "Quake3"
#define HOMEPATH_NAME_MACOSX HOMEPATH_NAME_WIN

// GNU/Linux: $HOME/.local/share/homepath-name (lower case and spaces replaced with hyphens)
// MacOS: $HOME/Library/Application Support/Homepath Name
// Windows: %APPDATA%\Homepath Name
#define HOMEPATH_NAME "Lilium Quake3"

#define GAMENAME_FOR_MASTER "Quake3Arena"
#define LEGACY_PROTOCOL
#endif
Expand Down
49 changes: 36 additions & 13 deletions code/sys/sys_unix.c
Expand Up @@ -55,23 +55,46 @@ char *Sys_DefaultHomePath(void)

if( !*homePath && com_homepath != NULL )
{
if( ( p = getenv( "HOME" ) ) != NULL )
#ifdef __APPLE__
if( ( p = getenv( "HOME" ) ) != NULL && *p != '\0' )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP);
#ifdef MACOS_X
Q_strcat(homePath, sizeof(homePath),
"Library/Application Support/");

if(com_homepath->string[0])
Q_strcat(homePath, sizeof(homePath), com_homepath->string);
else
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_MACOSX);
Com_sprintf(homePath, sizeof(homePath), "%s%cLibrary%cApplication Support%c%s", p, PATH_SEP, PATH_SEP, PATH_SEP, com_homepath->string);
}
#else
if(com_homepath->string[0])
Q_strcat(homePath, sizeof(homePath), com_homepath->string);
char directory[MAX_OSPATH];
char *s;

Q_strncpyz( directory, com_homepath->string, sizeof(directory) );

// convert home directory name to lower case and replace spaces with hyphens
s = directory;
while( *s )
{
if( *s == ' ' )
{
*s = '-';
}
else
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_UNIX);
{
*s = tolower(*s);
}
s++;
}

if( ( p = getenv( "XDG_DATA_HOME" ) ) != NULL && *p != '\0' )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c%s", p, PATH_SEP, directory);
}
else if( ( p = getenv( "HOME" ) ) != NULL && *p != '\0' )
{
Com_sprintf(homePath, sizeof(homePath), "%s%c.local%cshare%c%s", p, PATH_SEP, PATH_SEP, PATH_SEP, directory);
}
#endif

if( !*homePath )
{
Com_Printf("Unable to detect home path\n");
return NULL;
}
}

Expand Down
7 changes: 1 addition & 6 deletions code/sys/sys_win32.c
Expand Up @@ -114,12 +114,7 @@ char *Sys_DefaultHomePath( void )
return NULL;
}

Com_sprintf(homePath, sizeof(homePath), "%s%c", szPath, PATH_SEP);

if(com_homepath->string[0])
Q_strcat(homePath, sizeof(homePath), com_homepath->string);
else
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_WIN);
Com_sprintf(homePath, sizeof(homePath), "%s%c%s", szPath, PATH_SEP, com_homepath->string);
}

FreeLibrary(shfolder);
Expand Down

0 comments on commit 95c3dea

Please sign in to comment.