mirror of
https://github.com/YGGverse/hlsdk-portable.git
synced 2025-03-12 13:31:33 +00:00
Implement autosave clean
This commit is contained in:
parent
bf9184bcf5
commit
6b2a8218a9
@ -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 )
|
||||
if( !COOP_ProcessTransition() )
|
||||
{
|
||||
ALERT( at_console, "Transition failed, new game started\n");
|
||||
|
||||
COOP_ClearSaves();
|
||||
|
||||
while( g_CoopState.pMapStates )
|
||||
{
|
||||
COOPMapState *pMapState = g_CoopState.pMapStates;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 )
|
||||
if( pev->message )
|
||||
{
|
||||
g_engfuncs.pfnEndSection( STRING( pev->message ) );
|
||||
if( mp_coop.value )
|
||||
COOP_ClearSaves();
|
||||
}
|
||||
UTIL_Remove( this );
|
||||
}
|
||||
|
@ -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 )
|
||||
{
|
||||
// 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…
x
Reference in New Issue
Block a user