Files
DrakiaXYZ 47089afdd1 Further attempt to resolve profile corruption issues (#650)
* Further attempt to resolve profile corruption issues
- FileUtil now uses File.Replace and does a sync flush
- Add restore capabilities to BackupService
- If loading a profile fails, attempt to restore from the most recent backup
- Trigger a backup creation on raid start, raid end, and game close
- Load profiles before starting the backupService to avoid backing up corrupt profiles

* - Switch async calls to .GetAwaiter().GetResult() for better exception handling

---------

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
2025-10-23 07:49:24 +02:00

35 lines
1.0 KiB
C#

using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
namespace SPTarkov.Server.Core.Callbacks;
[Injectable(TypePriority = OnLoadOrder.SaveCallbacks)]
public class SaveCallbacks(SaveServer saveServer, ConfigServer configServer, BackupService backupService) : IOnLoad, IOnUpdate
{
protected readonly CoreConfig CoreConfig = configServer.GetConfig<CoreConfig>();
public async Task OnLoad()
{
await saveServer.LoadAsync();
// Note: This has to happen after loading the saveServer so we don't backup corrupted profiles
await backupService.StartBackupSystem();
}
public async Task<bool> OnUpdate(long secondsSinceLastRun)
{
if (secondsSinceLastRun < CoreConfig.ProfileSaveIntervalInSeconds)
{
// Not enough time has passed since last run, exit early
return false;
}
await saveServer.SaveAsync();
return true;
}
}