use safe copy file on single file updating
This commit is contained in:
@@ -190,7 +190,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
Utils.CopyFiles(dataPathDir, destDir);
|
||||
}
|
||||
else if (package.UpdateType == UpdateType.File)
|
||||
File.Copy(dataPath, localInstallPath);
|
||||
Utils.CopyFile(new FileInfo(dataPath), new FileInfo(localInstallPath));
|
||||
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent);
|
||||
|
||||
// Delete Package
|
||||
|
||||
@@ -10,6 +10,18 @@ public static class Utils
|
||||
foreach (FileInfo sFile in sourceDir.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
var dFile = new FileInfo(Path.Combine(destinationDir.FullName, sFile.Name));
|
||||
CopyFile(sFile, dFile);
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo sDir in sourceDir.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
var dDir = destinationDir.CreateSubdirectory(sDir.Name);
|
||||
CopyFiles(sDir, dDir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyFile(FileInfo sourceFile, FileInfo destinationFile)
|
||||
{
|
||||
var triesLeft = 1;
|
||||
|
||||
while (triesLeft > 0)
|
||||
@@ -18,15 +30,15 @@ public static class Utils
|
||||
|
||||
try
|
||||
{
|
||||
sFile.CopyTo(dFile.FullName, true);
|
||||
sourceFile.CopyTo(destinationFile.FullName, true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
if (triesLeft == 0 && File.Exists(dFile.FullName))
|
||||
if (triesLeft == 0 && File.Exists(destinationFile.FullName))
|
||||
{
|
||||
var oldFile = dFile.FullName + ".old";
|
||||
var oldFile = destinationFile.FullName + ".old";
|
||||
File.Delete(oldFile);
|
||||
File.Move(dFile.FullName, oldFile, true);
|
||||
File.Move(destinationFile.FullName, oldFile, true);
|
||||
File.Delete(oldFile);
|
||||
triesLeft++;
|
||||
}
|
||||
@@ -36,11 +48,4 @@ public static class Utils
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo sDir in sourceDir.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
var dDir = destinationDir.CreateSubdirectory(sDir.Name);
|
||||
CopyFiles(sDir, dDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user