diff --git a/Pilz.Updating.Client/Utils.cs b/Pilz.Updating.Client/Utils.cs index 4dc4b96..219d0ab 100644 --- a/Pilz.Updating.Client/Utils.cs +++ b/Pilz.Updating.Client/Utils.cs @@ -25,6 +25,7 @@ public static class Utils var triesLeft = 1; var srcFileName = sourceFile.FullName; var destFileName = destinationFile.FullName; + string? oldFile = null; while (triesLeft > 0) { @@ -38,9 +39,8 @@ public static class Utils { if (triesLeft == 0 && File.Exists(destFileName)) { - var oldFile = destFileName + ".old"; + oldFile = destFileName + ".old"; File.Move(destFileName, oldFile, true); - File.Delete(oldFile); triesLeft++; } } @@ -48,5 +48,16 @@ public static class Utils { } } + + if (oldFile != null) + { + try + { + File.Delete(oldFile); + } + catch (Exception) + { + } + } } }