Skip to content

Commit 7c6a3f8

Browse files
committed
engine: Fix clear save dir from old saves, do mode switch saves (broken in 43738e9)
1 parent a1f6fce commit 7c6a3f8

4 files changed

Lines changed: 15 additions & 31 deletions

File tree

engine/host_saverestore.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ char *CSaveRestore::GetSaveDir()
503503
if ( szDirectory[0] ) return szDirectory;
504504

505505
// dimhotepus: Dropped / at the end to unify all places.
506-
V_sprintf_safe(szDirectory, "save" PLATFORM_DIR, MOD_DIR);
506+
V_strcpy_safe(szDirectory, "save" PLATFORM_DIR);
507507

508508
return szDirectory;
509509
}
@@ -530,7 +530,6 @@ void CSaveRestore::AgeSaveFile( const char *pName, const char *ext, int count )
530530
{
531531
char newName[MAX_OSPATH], oldName[MAX_OSPATH];
532532

533-
// dimhotepus: Use MOD inside GetSaveDir.
534533
if ( count == 1 )
535534
{
536535
V_sprintf_safe( oldName, "%s/%s.%s", GetSaveDir(), pName, ext ); // quick.sav.
@@ -540,9 +539,9 @@ void CSaveRestore::AgeSaveFile( const char *pName, const char *ext, int count )
540539
V_sprintf_safe( oldName, "%s/%s%02d.%s", GetSaveDir(), pName, count-1, ext ); // quick04.sav, etc.
541540
}
542541

543-
// dimhotepus: Use MOD inside GetSaveDir.
544542
V_sprintf_safe( newName, "%s/%s%02d.%s", GetSaveDir(), pName, count, ext );
545-
543+
544+
// dimhotepus: Use MOD for fs.
546545
// Scroll the name list down (rename quick04.sav to quick05.sav)
547546
if ( g_pFileSystem->FileExists( oldName, MOD_DIR ) )
548547
{
@@ -1022,8 +1021,6 @@ bool CSaveRestore::LoadGame( const char *pName )
10221021

10231022
m_bClearSaveDir = false;
10241023
DoClearSaveDir();
1025-
1026-
bool bLoadedToMemory = false;
10271024

10281025
int iElapsedMinutes = 0;
10291026
int iElapsedSeconds = 0;
@@ -1055,10 +1052,6 @@ bool CSaveRestore::LoadGame( const char *pName )
10551052
}
10561053
else
10571054
{
1058-
if ( bLoadedToMemory )
1059-
{
1060-
g_pSaveRestoreFileSystem->RemoveFile( name );
1061-
}
10621055
return NULL;
10631056
}
10641057

@@ -1076,11 +1069,6 @@ bool CSaveRestore::LoadGame( const char *pName )
10761069
Warning( "Map '%s' missing or invalid\n", gameHeader.mapName );
10771070
validload = false;
10781071
}
1079-
1080-
if ( bLoadedToMemory )
1081-
{
1082-
g_pSaveRestoreFileSystem->RemoveFile( name );
1083-
}
10841072
}
10851073
else
10861074
{
@@ -2579,7 +2567,7 @@ void CSaveRestore::DirectoryCount( const char *pPath, int *pResult )
25792567
//-----------------------------------------------------------------------------
25802568
void CSaveRestore::DirectoryClear( const char *pPath )
25812569
{
2582-
g_pSaveRestoreFileSystem->DirectoryClear( pPath, false );
2570+
g_pSaveRestoreFileSystem->DirectoryClear( pPath );
25832571
}
25842572

25852573

@@ -2603,6 +2591,8 @@ void CSaveRestore::DoClearSaveDir()
26032591
char szName[MAX_OSPATH];
26042592

26052593
V_strcpy_safe( szName, GetSaveDir() );
2594+
// dimhotepus: GetSaveDir after changes missed separator, readd it.
2595+
V_strcat_safe( szName, CORRECT_PATH_SEPARATOR_S );
26062596
Q_FixSlashes( szName );
26072597
// Create save directory if it doesn't exist
26082598
Sys_mkdir( szName );

engine/matsys_interface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ static void NukeModeSwitchSaveGames( void )
139139

140140
V_sprintf_safe( modeswitch, "%s/modeswitchsave.sav", saveDir );
141141

142-
if (g_pFileSystem->FileExists(modeswitch ))
142+
if (g_pFileSystem->FileExists(modeswitch, "MOD" ))
143143
{
144-
g_pFileSystem->RemoveFile( modeswitch );
144+
g_pFileSystem->RemoveFile( modeswitch, "MOD" );
145145
}
146146

147147
V_sprintf_safe( modeswitch, "%s/modeswitchsave.tga", saveDir );
148148

149-
if (g_pFileSystem->FileExists(modeswitch ))
149+
if (g_pFileSystem->FileExists(modeswitch, "MOD" ))
150150
{
151-
g_pFileSystem->RemoveFile( modeswitch );
151+
g_pFileSystem->RemoveFile( modeswitch, "MOD" );
152152
}
153153
}
154154

engine/saverestore_filesystem.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ class CSaveRestoreFileSystemPassthrough : public ISaveRestoreFileSystem
209209
Q_snprintf( szName, sizeof( szName ), "%s/%s", saverestore->GetSaveDir(), list[i].szFileName );
210210
Q_FixSlashes( szName );
211211

212-
unsigned fileSize = g_pFileSystem->Size( szName );
212+
// dimhotepus: Correctly check file size.
213+
unsigned fileSize = g_pFileSystem->Size( szName, "MOD" );
213214
if ( fileSize )
214215
{
215216
Assert( sizeof(list[i].szFileName) == MAX_PATH );
@@ -282,22 +283,15 @@ class CSaveRestoreFileSystemPassthrough : public ISaveRestoreFileSystem
282283
//-----------------------------------------------------------------------------
283284
// Purpose: Clears the save directory of all temporary files (*.hl)
284285
//-----------------------------------------------------------------------------
285-
void DirectoryClear( const char *pPath, bool bIsXSave )
286+
void DirectoryClear( const char *pPath )
286287
{
287288
char szPath[ MAX_PATH ];
288289

289290
const char *findfn = Sys_FindFirstEx( pPath, "DEFAULT_WRITE_PATH", NULL, 0 );
290291
RunCodeAtScopeExit(Sys_FindClose());
291292
while ( findfn != NULL )
292293
{
293-
if ( !bIsXSave )
294-
{
295-
Q_snprintf( szPath, sizeof( szPath ), "%s/%s", saverestore->GetSaveDir(), findfn );
296-
}
297-
else
298-
{
299-
Q_snprintf( szPath, sizeof( szPath ), "%s:\\%s", GetCurrentMod(), findfn );
300-
}
294+
Q_snprintf( szPath, sizeof( szPath ), "%s/%s", saverestore->GetSaveDir(), findfn );
301295

302296
// Delete the temporary save file
303297
g_pFileSystem->RemoveFile( szPath, "MOD" );

engine/saverestore_filesystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract_class ISaveRestoreFileSystem
5252
virtual void DirectoryCopy( const char *pPath, const char *pDestFileName ) = 0;
5353
virtual bool DirectoryExtract( FileHandle_t pFile, int fileCount ) = 0;
5454
virtual int DirectoryCount( const char *pPath ) = 0;
55-
virtual void DirectoryClear( const char *pPath, bool bIsXSave ) = 0;
55+
virtual void DirectoryClear( const char *pPath ) = 0;
5656

5757
virtual void AuditFiles( void ) = 0;
5858
virtual bool LoadFileFromDisk( const char *pFilename ) = 0;

0 commit comments

Comments
 (0)