From e55753e62638d302fee559198b7205bae6d0c258 Mon Sep 17 00:00:00 2001 From: dhewg Date: Mon, 2 Jul 2012 23:42:24 +0200 Subject: [PATCH] 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. --- neo/framework/Common.cpp | 8 ++++---- neo/framework/FileSystem.cpp | 13 ++++++++++++- neo/framework/Session.cpp | 14 +++++++------- neo/sys/linux/main.cpp | 1 + neo/sys/osx/DOOMController.mm | 1 + neo/sys/sys_public.h | 1 + neo/sys/win32/win_main.cpp | 1 + 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index 39bf9a69..56973651 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -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 ); } diff --git a/neo/framework/FileSystem.cpp b/neo/framework/FileSystem.cpp index 5920303f..fc67b868 100644 --- a/neo/framework/FileSystem.cpp +++ b/neo/framework/FileSystem.cpp @@ -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); diff --git a/neo/framework/Session.cpp b/neo/framework/Session.cpp index 93bfe12f..6ece7f7f 100644 --- a/neo/framework/Session.cpp +++ b/neo/framework/Session.cpp @@ -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; diff --git a/neo/sys/linux/main.cpp b/neo/sys/linux/main.cpp index 3b62109c..ff10553f 100644 --- a/neo/sys/linux/main.cpp +++ b/neo/sys/linux/main.cpp @@ -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; diff --git a/neo/sys/osx/DOOMController.mm b/neo/sys/osx/DOOMController.mm index 4cdbaa69..e34caf52 100644 --- a/neo/sys/osx/DOOMController.mm +++ b/neo/sys/osx/DOOMController.mm @@ -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; diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index 1826af09..a0a1c711 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -119,6 +119,7 @@ struct sysMemoryStats_t { enum sysPath_t { PATH_BASE, + PATH_CONFIG, PATH_SAVE, PATH_EXE }; diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 9f219c3d..00af4211 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -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");