force replace file wich is currently in use

This commit is contained in:
2024-06-26 15:04:24 +02:00
parent 890a2787a3
commit 5bc0c374cf
2 changed files with 29 additions and 5 deletions

View File

@@ -131,12 +131,30 @@ public class UpdateInstaller(UpdateInstallerConfig config)
foreach (FileInfo sFile in sourceDir.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
{
var dFile = new FileInfo(Path.Combine(destinationDir.FullName, sFile.Name));
try
{
sFile.CopyTo(dFile.FullName, true);
}
catch (Exception)
var triesLeft = 1;
while (triesLeft > 0)
{
triesLeft--;
try
{
sFile.CopyTo(dFile.FullName, true);
}
catch (IOException)
{
if (triesLeft == 0 && File.Exists(dFile.FullName))
{
var oldFile = dFile.FullName + ".old";
File.Delete(oldFile);
File.Move(dFile.FullName, oldFile, true);
File.Delete(oldFile);
triesLeft++;
}
}
catch (Exception)
{
}
}
}