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:
@@ -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()}");
|
||||||
|
|||||||
Reference in New Issue
Block a user