From 7b5e7ea3746f46caba2acf6d2c4b63b471b5c64f Mon Sep 17 00:00:00 2001 From: tx00100xt Date: Fri, 24 Mar 2023 11:22:36 +0300 Subject: [PATCH] Added portable mode for command line (+portable). In portable mode, all user data is stored in the game directory. --- SamTFE/Sources/Engine/Base/Stream.cpp | 10 ++++++---- SamTFE/Sources/Engine/Base/Stream.h | 4 ++++ SamTFE/Sources/Engine/Engine.cpp | 6 +++++- SamTFE/Sources/SeriousSam/CmdLine.cpp | 4 ++++ SamTSE/Sources/Engine/Base/Stream.cpp | 10 ++++++---- SamTSE/Sources/Engine/Base/Stream.h | 4 ++++ SamTSE/Sources/Engine/Engine.cpp | 6 +++++- SamTSE/Sources/SeriousSam/CmdLine.cpp | 4 ++++ 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/SamTFE/Sources/Engine/Base/Stream.cpp b/SamTFE/Sources/Engine/Base/Stream.cpp index aa1482dd..f30213a5 100644 --- a/SamTFE/Sources/Engine/Base/Stream.cpp +++ b/SamTFE/Sources/Engine/Base/Stream.cpp @@ -61,6 +61,8 @@ THREADLOCAL(BOOL, _bThreadCanHandleStreams, FALSE); ULONG _ulVirtuallyAllocatedSpace = 0; ULONG _ulVirtuallyAllocatedSpaceTotal = 0; THREADLOCAL(CListHead *, _plhOpenedStreams, NULL); +// portable version (all user files stored in game dir) +INDEX _bPortableVersion = FALSE; #else extern INDEX fil_bPreferZips = FALSE; @@ -1663,20 +1665,20 @@ INDEX ExpandFilePath(ULONG ulType, const CTFileName &fnmFile, CTFileName &fnmExp //CPrintF("ExpandFilePath: %s\n",(const char *) fnmFile); - if( _savegame == 0 || _persistentsym == 0 || _gamesgms == 0 || - _comsolehistory == 0 || _userdemos == 0 || _playersplr == 0 || _screenshots == 0 ) { + if(( _savegame == 0 || _persistentsym == 0 || _gamesgms == 0 || + _comsolehistory == 0 || _userdemos == 0 || _playersplr == 0 || _screenshots == 0) && ( _bPortableVersion == FALSE)) { _fnmApplicationPathTMP = _fnmUserDir; } else { _fnmApplicationPathTMP = _fnmApplicationPath; } - if( _levelsvis == 0 ) { + if( _levelsvis == 0 && _bPortableVersion == FALSE) { if (fnmFileAbsolute.FileExt()==".vis") { _fnmApplicationPathTMP = _fnmUserDir; } } - if( _usercontrols == 0 ) { + if( _usercontrols == 0 && _bPortableVersion == FALSE) { CTFileName _fnSControls = fnmFileAbsolute.FileName(); int _controls = strncmp((const char *)_fnSControls, (const char *) "Controls", (size_t) 8 ); if ( _controls == 0 ) { diff --git a/SamTFE/Sources/Engine/Base/Stream.h b/SamTFE/Sources/Engine/Base/Stream.h index 4fe16067..8ff3de6b 100644 --- a/SamTFE/Sources/Engine/Base/Stream.h +++ b/SamTFE/Sources/Engine/Base/Stream.h @@ -406,6 +406,10 @@ ENGINE_API extern CTString _strModExt; ENGINE_API extern CTFileName _fnmCDPath; // global string with filename of the started application ENGINE_API extern CTFileName _fnmApplicationExe; +#ifdef PLATFORM_UNIX +// portable version (all user files stored in game dir) +ENGINE_API extern INDEX _bPortableVersion; +#endif // application path usage funtions ENGINE_API void UseApplicationPath(void); diff --git a/SamTFE/Sources/Engine/Engine.cpp b/SamTFE/Sources/Engine/Engine.cpp index 3259e771..37416726 100644 --- a/SamTFE/Sources/Engine/Engine.cpp +++ b/SamTFE/Sources/Engine/Engine.cpp @@ -696,7 +696,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _strLogFile = "SeriousSam"; } #ifdef PLATFORM_UNIX - _pConsole->Initialize(_fnmUserDir+_strLogFile+".log", 90, 512); + if (_bPortableVersion == FALSE) { + _pConsole->Initialize(_fnmUserDir+_strLogFile+".log", 90, 512); + } else { + _pConsole->Initialize(_fnmApplicationPath + _strLogFile + ".log", 90, 512); + } #else _pConsole->Initialize(_fnmApplicationPath + _strLogFile + ".log", 90, 512); #endif diff --git a/SamTFE/Sources/SeriousSam/CmdLine.cpp b/SamTFE/Sources/SeriousSam/CmdLine.cpp index 48b55aa6..446ab070 100644 --- a/SamTFE/Sources/SeriousSam/CmdLine.cpp +++ b/SamTFE/Sources/SeriousSam/CmdLine.cpp @@ -118,6 +118,10 @@ void ParseCommandLine(CTString strCmd) } } else if (strWord=="+cdpath") { _fnmCDPath = GetNextParam(); +#ifdef PLATFORM_UNIX + } else if (strWord=="+portable") { + _bPortableVersion = TRUE; // portable version (all user files stored in game dir) +#endif } else if (strWord=="+password") { cmd_strPassword = GetNextParam(); } else if (strWord=="+connect") { diff --git a/SamTSE/Sources/Engine/Base/Stream.cpp b/SamTSE/Sources/Engine/Base/Stream.cpp index aa1482dd..f30213a5 100644 --- a/SamTSE/Sources/Engine/Base/Stream.cpp +++ b/SamTSE/Sources/Engine/Base/Stream.cpp @@ -61,6 +61,8 @@ THREADLOCAL(BOOL, _bThreadCanHandleStreams, FALSE); ULONG _ulVirtuallyAllocatedSpace = 0; ULONG _ulVirtuallyAllocatedSpaceTotal = 0; THREADLOCAL(CListHead *, _plhOpenedStreams, NULL); +// portable version (all user files stored in game dir) +INDEX _bPortableVersion = FALSE; #else extern INDEX fil_bPreferZips = FALSE; @@ -1663,20 +1665,20 @@ INDEX ExpandFilePath(ULONG ulType, const CTFileName &fnmFile, CTFileName &fnmExp //CPrintF("ExpandFilePath: %s\n",(const char *) fnmFile); - if( _savegame == 0 || _persistentsym == 0 || _gamesgms == 0 || - _comsolehistory == 0 || _userdemos == 0 || _playersplr == 0 || _screenshots == 0 ) { + if(( _savegame == 0 || _persistentsym == 0 || _gamesgms == 0 || + _comsolehistory == 0 || _userdemos == 0 || _playersplr == 0 || _screenshots == 0) && ( _bPortableVersion == FALSE)) { _fnmApplicationPathTMP = _fnmUserDir; } else { _fnmApplicationPathTMP = _fnmApplicationPath; } - if( _levelsvis == 0 ) { + if( _levelsvis == 0 && _bPortableVersion == FALSE) { if (fnmFileAbsolute.FileExt()==".vis") { _fnmApplicationPathTMP = _fnmUserDir; } } - if( _usercontrols == 0 ) { + if( _usercontrols == 0 && _bPortableVersion == FALSE) { CTFileName _fnSControls = fnmFileAbsolute.FileName(); int _controls = strncmp((const char *)_fnSControls, (const char *) "Controls", (size_t) 8 ); if ( _controls == 0 ) { diff --git a/SamTSE/Sources/Engine/Base/Stream.h b/SamTSE/Sources/Engine/Base/Stream.h index 4fe16067..8ff3de6b 100644 --- a/SamTSE/Sources/Engine/Base/Stream.h +++ b/SamTSE/Sources/Engine/Base/Stream.h @@ -406,6 +406,10 @@ ENGINE_API extern CTString _strModExt; ENGINE_API extern CTFileName _fnmCDPath; // global string with filename of the started application ENGINE_API extern CTFileName _fnmApplicationExe; +#ifdef PLATFORM_UNIX +// portable version (all user files stored in game dir) +ENGINE_API extern INDEX _bPortableVersion; +#endif // application path usage funtions ENGINE_API void UseApplicationPath(void); diff --git a/SamTSE/Sources/Engine/Engine.cpp b/SamTSE/Sources/Engine/Engine.cpp index 3259e771..37416726 100644 --- a/SamTSE/Sources/Engine/Engine.cpp +++ b/SamTSE/Sources/Engine/Engine.cpp @@ -696,7 +696,11 @@ ENGINE_API void SE_InitEngine(CTString strGameID) _strLogFile = "SeriousSam"; } #ifdef PLATFORM_UNIX - _pConsole->Initialize(_fnmUserDir+_strLogFile+".log", 90, 512); + if (_bPortableVersion == FALSE) { + _pConsole->Initialize(_fnmUserDir+_strLogFile+".log", 90, 512); + } else { + _pConsole->Initialize(_fnmApplicationPath + _strLogFile + ".log", 90, 512); + } #else _pConsole->Initialize(_fnmApplicationPath + _strLogFile + ".log", 90, 512); #endif diff --git a/SamTSE/Sources/SeriousSam/CmdLine.cpp b/SamTSE/Sources/SeriousSam/CmdLine.cpp index 48b55aa6..446ab070 100644 --- a/SamTSE/Sources/SeriousSam/CmdLine.cpp +++ b/SamTSE/Sources/SeriousSam/CmdLine.cpp @@ -118,6 +118,10 @@ void ParseCommandLine(CTString strCmd) } } else if (strWord=="+cdpath") { _fnmCDPath = GetNextParam(); +#ifdef PLATFORM_UNIX + } else if (strWord=="+portable") { + _bPortableVersion = TRUE; // portable version (all user files stored in game dir) +#endif } else if (strWord=="+password") { cmd_strPassword = GetNextParam(); } else if (strWord=="+connect") {