#define MAX_GAME_PATHS 10
#define MAX_PAK_PATHS 200
+qboolean customHomePath = qfalse;
char *homePath;
+
+#if GDEF_OS_MACOS
+char *macLibraryApplicationSupportPath;
+#endif
+
+#if (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+char *xdgDataHomePath;
+#endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+
char installPath[ MAX_OS_PATH ];
int numBasePaths;
*/
char *LokiGetHomeDir( void ){
- #ifndef Q_UNIX
+ #if GDEF_OS_WINDOWS
return NULL;
- #else
+ #else // !GDEF_OS_WINDOWS
static char buf[ 4096 ];
struct passwd pw, *pwp;
char *home;
home = homePath;
}
- #ifndef Q_UNIX
+ #if GDEF_OS_MACOS
+ char *subPath = "/Library/Application Support";
+ macLibraryApplicationSupportPath = safe_malloc( sizeof( char ) * ( strlen( home ) + strlen( subPath ) ) );
+ sprintf( macLibraryApplicationSupportPath, "%s%s", home, subPath );
+ #endif // GDEF_OS_MACOS
+
+ #if (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+ xdgDataHomePath = getenv( "XDG_DATA_HOME" );
+
+ if ( xdgDataHomePath == NULL ) {
+ char *subPath = "/.local/share";
+ xdgDataHomePath = safe_malloc( sizeof( char ) * ( strlen( home ) + strlen( subPath ) ) );
+ sprintf( xdgDataHomePath, "%s%s", home, subPath );
+ }
+ #endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+
+ #if GDEF_OS_WINDOWS
/* this is kinda crap, but hey */
strcpy( installPath, "../" );
- #else
+ #else // !GDEF_OS_WINDOWS
char temp[ MAX_OS_PATH ];
char *path;
*( strrchr( installPath, '/' ) ) = '\0';
*( strrchr( installPath, '/' ) ) = '\0';
}
- #endif
+ #endif // !GDEF_OS_WINDOWS
}
/*
AddHomeBasePath() - ydnar
- adds a base path to the beginning of the list, prefixed by ~/
+ adds a base path to the beginning of the list
*/
void AddHomeBasePath( char *path ){
strcpy( temp, homePath );
}
else {
+ char *tempHomePath;
+ tempHomePath = homePath;
+
+ /* homePath is . on Windows if not user supplied */
+
+ #if GDEF_OS_MACOS
+ /*
+ use ${HOME}/Library/Application as ${HOME}
+ if home path is not user supplied
+ and strip the leading dot from prefix in any case
+
+ basically it produces
+ ${HOME}/Library/Application/unvanquished
+ /user/supplied/home/path/unvanquished
+ */
+ tempHomePath = macLibraryApplicationSupportPath;
+ path = path + 1;
+ #endif // GDEF_OS_MACOS
+
+ #if (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+ /*
+ on Linux, check if game uses ${XDG_DATA_HOME}/prefix instead of ${HOME}/.prefix
+ if yes and home path is not user supplied
+ use XDG_DATA_HOME instead of HOME
+ and strip the leading dot
+
+ basically it produces
+ ${XDG_DATA_HOME}/unvanquished
+ /user/supplied/home/path/unvanquished
+
+ or
+ ${HOME}/.q3a
+ /user/supplied/home/path/.q3a
+ */
+
+ sprintf( temp, "%s/%s", xdgDataHomePath, ( path + 1 ) );
+ if ( access( temp, X_OK ) == 0 ) {
+ if ( customHomePath == qfalse ) {
+ tempHomePath = xdgDataHomePath;
+ }
+ path = path + 1;
+ }
+ #endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS)
+
/* concatenate home dir and path */
- sprintf( temp, "%s/%s", homePath, path );
+ sprintf( temp, "%s/%s", tempHomePath, path );
}
/* make a hole */
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
}
argv[ i - 1 ] = NULL;
+ customHomePath = qtrue;
homePath = argv[i];
argv[ i ] = NULL;
}