mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2024-11-10 07:11:54 +00:00
use XDG_STATE_HOME if set for g_strTempPath (.pid file, radiant.log etc.), and related cleanups
This commit is contained in:
parent
1fe273a212
commit
d97f00e0e9
4 changed files with 24 additions and 120 deletions
136
radiant/main.cpp
136
radiant/main.cpp
|
@ -120,39 +120,10 @@ static void create_splash() {
|
||||||
|
|
||||||
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
||||||
|
|
||||||
/* A short game name, could be used as argv[0] */
|
|
||||||
static char game_name[100] = "";
|
|
||||||
|
|
||||||
/* The directory where the data files can be found (run directory) */
|
/* The directory where the data files can be found (run directory) */
|
||||||
static char datapath[PATH_MAX];
|
static char datapath[PATH_MAX];
|
||||||
|
|
||||||
char *loki_gethomedir( void ){
|
#ifdef __linux__
|
||||||
char *home = NULL;
|
|
||||||
|
|
||||||
home = getenv( "HOME" );
|
|
||||||
if ( home == NULL ) {
|
|
||||||
uid_t id = getuid();
|
|
||||||
struct passwd *pwd;
|
|
||||||
|
|
||||||
setpwent();
|
|
||||||
while ( ( pwd = getpwent() ) != NULL )
|
|
||||||
{
|
|
||||||
if ( pwd->pw_uid == id ) {
|
|
||||||
home = pwd->pw_dir;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
endpwent();
|
|
||||||
}
|
|
||||||
return home;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Must be called BEFORE loki_initialize */
|
|
||||||
void loki_setgamename( const char *n ){
|
|
||||||
strncpy( game_name, n, sizeof( game_name ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
/* Code to determine the mount point of a CD-ROM */
|
/* Code to determine the mount point of a CD-ROM */
|
||||||
int loki_getmountpoint( const char *device, char *mntpt, int max_size ){
|
int loki_getmountpoint( const char *device, char *mntpt, int max_size ){
|
||||||
char devpath[PATH_MAX], mntdevpath[PATH_MAX];
|
char devpath[PATH_MAX], mntdevpath[PATH_MAX];
|
||||||
|
@ -209,86 +180,32 @@ int loki_getmountpoint( const char *device, char *mntpt, int max_size ){
|
||||||
}
|
}
|
||||||
return( mounted );
|
return( mounted );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function gets the directory containing the running program.
|
This function gets the directory containing the running program.
|
||||||
argv0 - the 0'th argument to the program
|
argv0 - the 0'th argument to the program
|
||||||
*/
|
*/
|
||||||
// FIXME TTimo
|
char* loki_init_datapath( char *argv0 ){
|
||||||
// I don't understand this function. It looks like something cut from another piece of software
|
char temppath[PATH_MAX];
|
||||||
// we somehow get the g_strAppPath from it, but it's done through a weird scan across $PATH env. var.
|
char *home;
|
||||||
// even worse, it doesn't behave the same in all cases .. works well when ran through gdb and borks when ran from a shell
|
|
||||||
void loki_initpaths( char *argv0 ){
|
|
||||||
char temppath[PATH_MAX]; //, env[100];
|
|
||||||
char *home; //, *ptr, *data_env;
|
|
||||||
|
|
||||||
home = loki_gethomedir();
|
home = g_get_home_dir();
|
||||||
if ( home == NULL ) {
|
if ( home == NULL ) {
|
||||||
home = const_cast<char*>(".");
|
home = const_cast<char*>(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( *game_name == 0 ) { /* Game name defaults to argv[0] */
|
strcpy( temppath, argv0 );
|
||||||
loki_setgamename( argv0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy( temppath, argv0 ); /* If this overflows, it's your own fault :) */
|
|
||||||
if ( !strrchr( temppath, '/' ) ) {
|
|
||||||
char *path;
|
|
||||||
char *last;
|
|
||||||
int found;
|
|
||||||
|
|
||||||
found = 0;
|
|
||||||
path = getenv( "PATH" );
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/* Initialize our filename variable */
|
|
||||||
temppath[0] = '\0';
|
|
||||||
|
|
||||||
/* Get next entry from path variable */
|
|
||||||
last = strchr( path, ':' );
|
|
||||||
if ( !last ) {
|
|
||||||
last = path + strlen( path );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Perform tilde expansion */
|
|
||||||
if ( *path == '~' ) {
|
|
||||||
strcpy( temppath, home );
|
|
||||||
++path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill in the rest of the filename */
|
|
||||||
if ( last > ( path + 1 ) ) {
|
|
||||||
strncat( temppath, path, ( last - path ) );
|
|
||||||
strcat( temppath, "/" );
|
|
||||||
}
|
|
||||||
strcat( temppath, "./" );
|
|
||||||
strcat( temppath, argv0 );
|
|
||||||
|
|
||||||
/* See if it exists, and update path */
|
|
||||||
if ( access( temppath, X_OK ) == 0 ) {
|
|
||||||
++found;
|
|
||||||
}
|
|
||||||
path = last + 1;
|
|
||||||
|
|
||||||
} while ( *last && !found );
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Increment argv0 to the basename */
|
|
||||||
argv0 = strrchr( argv0, '/' ) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now canonicalize it to a full pathname for the data path */
|
/* Now canonicalize it to a full pathname for the data path */
|
||||||
if ( realpath( temppath, datapath ) ) {
|
if ( realpath( temppath, datapath ) ) {
|
||||||
/* There should always be '/' in the path */
|
/* There should always be '/' in the path, cut after so we end our directories with a slash */
|
||||||
*( strrchr( datapath, '/' ) ) = '\0';
|
*( strrchr( datapath, '/' ) + 1 ) = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *loki_getdatapath( void ){
|
char *loki_get_datapath( void ){
|
||||||
return( datapath );
|
return datapath;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -581,27 +498,20 @@ int mainRadiant( int argc, char* argv[] ) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
||||||
Str home;
|
const char *xdg_state_home = getenv( "XDG_STATE_HOME" );
|
||||||
home = g_get_home_dir();
|
if ( xdg_state_home != nullptr ) {
|
||||||
AddSlash( home );
|
g_strTempPath = xdg_state_home;
|
||||||
home += ".radiant/";
|
} else {
|
||||||
Q_mkdir( home.GetBuffer(), 0775 );
|
g_strTempPath = g_get_home_dir();
|
||||||
home += RADIANT_VERSION;
|
}
|
||||||
Q_mkdir( home.GetBuffer(), 0775 );
|
g_strTempPath += "/.radiant/";
|
||||||
g_strTempPath = home.GetBuffer();
|
Q_mkdir( g_strTempPath.GetBuffer(), 0775 );
|
||||||
|
g_strTempPath += RADIANT_VERSION;
|
||||||
|
Q_mkdir( g_strTempPath.GetBuffer(), 0775 );
|
||||||
AddSlash( g_strTempPath );
|
AddSlash( g_strTempPath );
|
||||||
|
|
||||||
loki_initpaths( argv[0] );
|
loki_init_datapath( argv[0] );
|
||||||
|
g_strAppPath = loki_get_datapath();
|
||||||
// NOTE: we build g_strAppPath with a '/' (or '\' on WIN32)
|
|
||||||
// it's a general convention in Radiant to have the slash at the end of directories
|
|
||||||
char real[PATH_MAX];
|
|
||||||
realpath( loki_getdatapath(), real );
|
|
||||||
if ( real[strlen( real ) - 1] != '/' ) {
|
|
||||||
strcat( real, "/" );
|
|
||||||
}
|
|
||||||
|
|
||||||
g_strAppPath = real;
|
|
||||||
|
|
||||||
// radiant is installed in the parent dir of "tools/"
|
// radiant is installed in the parent dir of "tools/"
|
||||||
// NOTE: this is not very easy for debugging
|
// NOTE: this is not very easy for debugging
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
CString g_strAppPath; ///< holds the full path of the executable
|
CString g_strAppPath; ///< holds the full path of the executable - readonly! (in flatpak at least)
|
||||||
CString g_strDTDPath; ///< path to the DTD files
|
CString g_strDTDPath; ///< path to the DTD files
|
||||||
CString g_pidFile; ///< the global .pid file (only for global part of the startup)
|
CString g_pidFile; ///< the global .pid file (only for global part of the startup)
|
||||||
CString g_pidGameFile; ///< the game-specific .pid file
|
CString g_pidGameFile; ///< the game-specific .pid file
|
||||||
|
|
|
@ -1922,10 +1922,6 @@ XVisualInfo* QEX_ChooseVisual( bool zbuffer ){
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
|
||||||
\todo FIXME TTimo broken most likely
|
|
||||||
actually .. that's not enough, you have to go down for the game pack specific?
|
|
||||||
*/
|
|
||||||
const char* WINAPI QERApp_ProfileGetDirectory(){
|
const char* WINAPI QERApp_ProfileGetDirectory(){
|
||||||
return g_strTempPath;
|
return g_strTempPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1271,8 +1271,6 @@ CGameDescription* CGameDialog::GameDescriptionForComboItem(){
|
||||||
|
|
||||||
void CGameDialog::InitGlobalPrefPath(){
|
void CGameDialog::InitGlobalPrefPath(){
|
||||||
GString *global_rc_path;
|
GString *global_rc_path;
|
||||||
// configure m_global_rc_path
|
|
||||||
// this is the g_strTempPath, and it has already been mkdir'ed
|
|
||||||
global_rc_path = g_string_new( g_strTempPath.GetBuffer() );
|
global_rc_path = g_string_new( g_strTempPath.GetBuffer() );
|
||||||
g_PrefsDlg.m_global_rc_path = global_rc_path;
|
g_PrefsDlg.m_global_rc_path = global_rc_path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue