Browse Source

Implement autosave clean

gravgun
mittorn 6 years ago
parent
commit
6b2a8218a9
  1. 45
      dlls/coop.cpp
  2. 2
      dlls/coop_util.h
  3. 4
      dlls/triggers.cpp
  4. 5
      dlls/world.cpp

45
dlls/coop.cpp

@ -199,6 +199,48 @@ void COOP_AutoSave( void ) @@ -199,6 +199,48 @@ void COOP_AutoSave( void )
GGM_Save( g_CoopState.p.rgszSaveSlots[COOP_SAVE_AUTO1] );
}
#include <dirent.h>
#ifdef _WIN32
#define PATHSEP "\\"
#else
#define PATHSEP "/"
#endif
void COOP_ClearSaves( void )
{
char path[256];
GET_GAME_DIR(path);
strcat( path, PATHSEP"save" );
DIR *dir;
struct dirent *entry;
ALERT( at_console, "COOP_ClearSaves\n" );
memset( g_CoopState.p.rgszSaveSlots, 0, sizeof( g_CoopState.p.rgszSaveSlots ) );
g_CoopState.p.iLastAutoSave = 0;
dir = opendir( path );
if( !dir )
{
ALERT( at_error, "opendir failed, cannot clean save files!\n");
return;
}
while( entry = readdir( dir) )
{
if( Q_stricmpext("auto0-*", entry->d_name ) ||
Q_stricmpext("auto1-*", entry->d_name ) ||
Q_stricmpext("start-*", entry->d_name ) )
{
char fpath[256] = "";
strcpy( fpath, path );
strcat( fpath, PATHSEP );
strcat( fpath, entry->d_name );
ALERT( at_console, "Removing %s\n", fpath );
remove( fpath );
}
}
closedir(dir);
}
/*
=========================
COOP_MapStartSave
@ -658,6 +700,9 @@ void COOP_ServerActivate( void ) @@ -658,6 +700,9 @@ void COOP_ServerActivate( void )
if( !COOP_ProcessTransition() )
{
ALERT( at_console, "Transition failed, new game started\n");
COOP_ClearSaves();
while( g_CoopState.pMapStates )
{
COOPMapState *pMapState = g_CoopState.pMapStates;

2
dlls/coop_util.h

@ -57,7 +57,7 @@ void COOP_WriteState( const char *path ); @@ -57,7 +57,7 @@ void COOP_WriteState( const char *path );
bool COOP_ReadState( const char *path );
void COOP_AutoSave( void );
bool COOP_PlayerSpawn( CBasePlayer *pPlayer );
void COOP_ClearSaves( void );
struct COOPChangelevelData *COOP_GetTriggerData( CBaseEntity *pTrigger );
#endif // COOP_UTIL_H

4
dlls/triggers.cpp

@ -2323,6 +2323,8 @@ void CTriggerEndSection::EndSectionUse( CBaseEntity *pActivator, CBaseEntity *pC @@ -2323,6 +2323,8 @@ void CTriggerEndSection::EndSectionUse( CBaseEntity *pActivator, CBaseEntity *pC
if( pev->message )
{
g_engfuncs.pfnEndSection( STRING( pev->message ) );
if( mp_coop.value )
COOP_ClearSaves();
}
UTIL_Remove( this );
}
@ -2355,6 +2357,8 @@ void CTriggerEndSection::EndSectionTouch( CBaseEntity *pOther ) @@ -2355,6 +2357,8 @@ void CTriggerEndSection::EndSectionTouch( CBaseEntity *pOther )
if( pev->message )
{
g_engfuncs.pfnEndSection( STRING( pev->message ) );
if( mp_coop.value )
COOP_ClearSaves();
}
UTIL_Remove( this );
}

5
dlls/world.cpp

@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "physcallback.h"
#include "coop_util.h"
extern CGraph WorldGraph;
extern CSoundEnt *pSoundEnt;
@ -706,7 +707,11 @@ void CWorld::KeyValue( KeyValueData *pkvd ) @@ -706,7 +707,11 @@ void CWorld::KeyValue( KeyValueData *pkvd )
{
// Single player only. Clear save directory if set
if( atoi( pkvd->szValue ) )
{
CVAR_SET_FLOAT( "sv_newunit", 1 );
if( mp_coop.value )
COOP_ClearSaves();
}
pkvd->fHandled = TRUE;
}
else if( FStrEq(pkvd->szKeyName, "gametitle" ) )

Loading…
Cancel
Save