force replace file wich is currently in use
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Updating", "Pilz.Updat
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Updating.UpdateInstaller.Lib", "Pilz.Updating.UpdateInstaller.Lib\Pilz.Updating.UpdateInstaller.Lib.csproj", "{F05AAEA2-386F-4307-AE5E-6831F4EA2B66}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Updating.Test", "Pilz.Updating.Test\Pilz.Updating.Test.csproj", "{B98D1EA1-0C02-4337-97AD-B321EDD443E3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -45,6 +47,10 @@ Global
|
||||
{F05AAEA2-386F-4307-AE5E-6831F4EA2B66}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F05AAEA2-386F-4307-AE5E-6831F4EA2B66}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F05AAEA2-386F-4307-AE5E-6831F4EA2B66}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B98D1EA1-0C02-4337-97AD-B321EDD443E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B98D1EA1-0C02-4337-97AD-B321EDD443E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B98D1EA1-0C02-4337-97AD-B321EDD443E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B98D1EA1-0C02-4337-97AD-B321EDD443E3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user