public async Task CleanUpAsync(CancellationToken cancellation) {
if (_gameProcess != null && !_gameProcess.HasExitedSafe()) {
try {
_gameProcess.Kill();
} catch (Exception) {
// ignored
}
}
_gameProcess?.Dispose();
_gameProcess = null;
if (_acLauncher == null || new FileInfo(_acLauncher).Length > ApproximateAcstarterSize) return;
await Task.Delay(200, cancellation);
if (cancellation.IsCancellationRequested) return;
var isRestored = false;
for (var i = 0; i < 10 && File.Exists(_acLauncherBackup); i++) {
try {
if (!isRestored) {
if (File.Exists(_acLauncher)) {
File.Delete(_acLauncher);
}
File.Copy(_acLauncherBackup, _acLauncher);
isRestored = true;
}
File.Delete(_acLauncherBackup);
} catch (IOException) { }
await Task.Delay(WaitIter, cancellation);
if (cancellation.IsCancellationRequested) return;
}
if (File.Exists(_acLauncherBackup)) {
throw new Exception("Cannot restore original AssettoCorsa.exe");
}
}
}