Introduce fs_configpath

Split fs_savepath for config files. This is in preparation for
moving the writable paths on *nix to $XDG_DATA_HOME and
$XDG_CONFIG_HOME.
Affected files: config.spec, *.cfg, doomkey, xpkey.
This commit is contained in:
dhewg 2012-07-02 23:42:24 +02:00
parent 8f6f1883ff
commit e55753e626
7 changed files with 27 additions and 12 deletions

View file

@ -978,7 +978,7 @@ idCommonLocal::WriteFlaggedCVarsToFile
void idCommonLocal::WriteFlaggedCVarsToFile( const char *filename, int flags, const char *setCmd ) {
idFile *f;
f = fileSystem->OpenFileWrite( filename );
f = fileSystem->OpenFileWrite( filename, "fs_configpath" );
if ( !f ) {
Printf( "Couldn't write %s.\n", filename );
return;
@ -1002,7 +1002,7 @@ void idCommonLocal::WriteConfigToFile( const char *filename ) {
idBase64 out;
#endif
f = fileSystem->OpenFileWrite( filename );
f = fileSystem->OpenFileWrite( filename, "fs_configpath" );
if ( !f ) {
Printf ("Couldn't write %s.\n", filename );
return;
@ -2920,12 +2920,12 @@ void idCommonLocal::InitGame( void ) {
// force r_fullscreen 0 if running a tool
CheckToolMode();
idFile *file = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( CONFIG_SPEC, "fs_savepath" ) );
idFile *file = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( CONFIG_SPEC, "fs_configpath" ) );
bool sysDetect = ( file == NULL );
if ( file ) {
fileSystem->CloseFile( file );
} else {
file = fileSystem->OpenFileWrite( CONFIG_SPEC );
file = fileSystem->OpenFileWrite( CONFIG_SPEC, "fs_configpath" );
fileSystem->CloseFile( file );
}

View file

@ -418,6 +418,7 @@ private:
static idCVar fs_restrict;
static idCVar fs_copyfiles;
static idCVar fs_basepath;
static idCVar fs_configpath;
static idCVar fs_savepath;
static idCVar fs_cdpath;
static idCVar fs_devpath;
@ -485,6 +486,7 @@ idCVar idFileSystemLocal::fs_restrict( "fs_restrict", "", CVAR_SYSTEM | CVAR_INI
idCVar idFileSystemLocal::fs_debug( "fs_debug", "0", CVAR_SYSTEM | CVAR_INTEGER, "", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
idCVar idFileSystemLocal::fs_copyfiles( "fs_copyfiles", "0", CVAR_SYSTEM | CVAR_INIT | CVAR_INTEGER, "", 0, 4, idCmdSystem::ArgCompletion_Integer<0,3> );
idCVar idFileSystemLocal::fs_basepath( "fs_basepath", "", CVAR_SYSTEM | CVAR_INIT, "" );
idCVar idFileSystemLocal::fs_configpath( "fs_configpath", "", CVAR_SYSTEM | CVAR_INIT, "" );
idCVar idFileSystemLocal::fs_savepath( "fs_savepath", "", CVAR_SYSTEM | CVAR_INIT, "" );
idCVar idFileSystemLocal::fs_cdpath( "fs_cdpath", "", CVAR_SYSTEM | CVAR_INIT, "" );
idCVar idFileSystemLocal::fs_devpath( "fs_devpath", "", CVAR_SYSTEM | CVAR_INIT, "" );
@ -2176,6 +2178,11 @@ void idFileSystemLocal::SetupGameDirectories( const char *gameName ) {
if ( fs_savepath.GetString()[0] ) {
AddGameDirectory( fs_savepath.GetString(), gameName );
}
// setup configpath
if ( fs_configpath.GetString()[0] ) {
AddGameDirectory( fs_configpath.GetString(), gameName );
}
}
/*
@ -2804,6 +2811,7 @@ void idFileSystemLocal::Init( void ) {
// line variable sets don't happen until after the filesystem
// has already been initialized
common->StartupVariable( "fs_basepath", false );
common->StartupVariable( "fs_configpath", false );
common->StartupVariable( "fs_savepath", false );
common->StartupVariable( "fs_cdpath", false );
common->StartupVariable( "fs_devpath", false );
@ -2820,6 +2828,9 @@ void idFileSystemLocal::Init( void ) {
if (fs_savepath.GetString()[0] == '\0' && Sys_GetPath(PATH_SAVE, path))
fs_savepath.SetString(path);
if (fs_configpath.GetString()[0] == '\0' && Sys_GetPath(PATH_CONFIG, path))
fs_configpath.SetString(path);
if ( fs_devpath.GetString()[0] == '\0' ) {
#ifdef WIN32
fs_devpath.SetString( fs_cdpath.GetString()[0] ? fs_cdpath.GetString() : fs_basepath.GetString() );
@ -3980,7 +3991,7 @@ bool idFileSystemLocal::HasD3XP( void ) {
for ( i = 0; i < dirs.Num(); i++ ) {
if ( dirs[i].Icmp( "d3xp" ) == 0 ) {
gamepath = BuildOSPath( fs_savepath.GetString(), dirs[ i ], "default.cfg" );
gamepath = BuildOSPath( fs_configpath.GetString(), dirs[ i ], "default.cfg" );
idFile* cfg = OpenExplicitFileRead(gamepath);
if(cfg) {
CloseFile(cfg);

View file

@ -201,7 +201,7 @@ static void Sess_WritePrecache_f( const idCmdArgs &args ) {
}
idStr str = args.Argv(1);
str.DefaultFileExtension( ".cfg" );
idFile *f = fileSystem->OpenFileWrite( str );
idFile *f = fileSystem->OpenFileWrite( str, "fs_configpath" );
declManager->WritePrecacheCommands( f );
renderModelManager->WritePrecacheCommands( f );
uiManager->WritePrecacheCommands( f );
@ -2960,7 +2960,7 @@ void idSessionLocal::ReadCDKey( void ) {
cdkey_state = CDKEY_UNKNOWN;
filename = "../" BASE_GAMEDIR "/" CDKEY_FILE;
f = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( filename, "fs_savepath" ) );
f = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( filename, "fs_configpath" ) );
if ( !f ) {
common->Printf( "Couldn't read %s.\n", filename.c_str() );
cdkey[ 0 ] = '\0';
@ -2974,7 +2974,7 @@ void idSessionLocal::ReadCDKey( void ) {
xpkey_state = CDKEY_UNKNOWN;
filename = "../" BASE_GAMEDIR "/" XPKEY_FILE;
f = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( filename, "fs_savepath" ) );
f = fileSystem->OpenExplicitFileRead( fileSystem->RelativePathToOSPath( filename, "fs_configpath" ) );
if ( !f ) {
common->Printf( "Couldn't read %s.\n", filename.c_str() );
xpkey[ 0 ] = '\0';
@ -2998,10 +2998,10 @@ void idSessionLocal::WriteCDKey( void ) {
filename = "../" BASE_GAMEDIR "/" CDKEY_FILE;
// OpenFileWrite advertises creating directories to the path if needed, but that won't work with a '..' in the path
// occasionally on windows, but mostly on Linux and OSX, the fs_savepath/base may not exist in full
OSPath = fileSystem->BuildOSPath( cvarSystem->GetCVarString( "fs_savepath" ), BASE_GAMEDIR, CDKEY_FILE );
// occasionally on windows, but mostly on Linux and OSX, the fs_configpath/base may not exist in full
OSPath = fileSystem->BuildOSPath( cvarSystem->GetCVarString( "fs_configpath" ), BASE_GAMEDIR, CDKEY_FILE );
fileSystem->CreateOSPath( OSPath );
f = fileSystem->OpenFileWrite( filename );
f = fileSystem->OpenFileWrite( filename, "fs_configpath" );
if ( !f ) {
common->Printf( "Couldn't write %s.\n", filename.c_str() );
return;
@ -3010,7 +3010,7 @@ void idSessionLocal::WriteCDKey( void ) {
fileSystem->CloseFile( f );
filename = "../" BASE_GAMEDIR "/" XPKEY_FILE;
f = fileSystem->OpenFileWrite( filename );
f = fileSystem->OpenFileWrite( filename, "fs_configpath" );
if ( !f ) {
common->Printf( "Couldn't write %s.\n", filename.c_str() );
return;

View file

@ -79,6 +79,7 @@ bool Sys_GetPath(sysPath_t type, idStr &path) {
path = LINUX_DEFAULT_PATH;
return true;
case PATH_CONFIG:
case PATH_SAVE:
idStr::snPrintf(buf, sizeof(buf), "%s/.doom3", getenv("HOME"));
path = buf;

View file

@ -64,6 +64,7 @@ bool Sys_GetPath(sysPath_t type, idStr &path) {
path = buf;
return true;
case PATH_CONFIG:
case PATH_SAVE:
sprintf(buf, "%s/Library/Application Support/dhewm3", [NSHomeDirectory() cString]);
path = buf;

View file

@ -119,6 +119,7 @@ struct sysMemoryStats_t {
enum sysPath_t {
PATH_BASE,
PATH_CONFIG,
PATH_SAVE,
PATH_EXE
};

View file

@ -295,6 +295,7 @@ bool Sys_GetPath(sysPath_t type, idStr &path) {
path = Sys_Cwd();
return true;
case PATH_CONFIG:
case PATH_SAVE:
if (GetHomeDir(buf, sizeof(buf), "dhewm3") < 1) {
Sys_Error("ERROR: Couldn't get dir to home path");