Restore project file on cancel event

Adds a handler for Console.CancelKeyPress to restore the project file from backup if the process is interrupted, ensuring changes are not left in an inconsistent state.
This commit is contained in:
qwsdcvghyu89
2025-09-27 15:56:20 +10:00
parent 05a0540476
commit ad729133a6
+5
View File
@@ -124,6 +124,11 @@ public static class Program {
try { try {
projectFile.Backup(); projectFile.Backup();
Console.CancelKeyPress += (sender, eventArgs) => {
projectFile.Restore();
AnsiConsole.MarkupLine("[yellow]Restored project file from backup.[/]");
};
if (Verbose) if (Verbose)
AnsiConsole.WriteLine( AnsiConsole.WriteLine(
$"Created project file backup at {projectFile.GetDefaultBackupLocation()}"); $"Created project file backup at {projectFile.GetDefaultBackupLocation()}");