Skip to content

Commit

Permalink
Added portable mode for command line (+portable). In portable mode, a…
Browse files Browse the repository at this point in the history
…ll user data is stored in the game directory.
  • Loading branch information
tx00100xt committed Mar 24, 2023
1 parent 8144d1d commit 7b5e7ea
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
10 changes: 6 additions & 4 deletions SamTFE/Sources/Engine/Base/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ) {
Expand Down
4 changes: 4 additions & 0 deletions SamTFE/Sources/Engine/Base/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion SamTFE/Sources/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions SamTFE/Sources/SeriousSam/CmdLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
10 changes: 6 additions & 4 deletions SamTSE/Sources/Engine/Base/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ) {
Expand Down
4 changes: 4 additions & 0 deletions SamTSE/Sources/Engine/Base/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion SamTSE/Sources/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions SamTSE/Sources/SeriousSam/CmdLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 7b5e7ea

Please sign in to comment.