修复错误判断

This commit is contained in:
ZtRXR 2023-10-14 14:46:11 +08:00
parent 745d2e2b6c
commit 872644e47e

View File

@ -33,12 +33,14 @@ public class FileCopy
using(var fileInfoDb = new FileInfoDb())
{
foreach (var file in sourceDir.GetFiles())
{
try
{
string destinationFile = Path.Combine(desDir.FullName, file.Name);
var tryGetFileDbInfo = fileInfoDb.Files.Where(w => w.Path == destinationFile).FirstOrDefault();
if (tryGetFileDbInfo != null)
{
if(tryGetFileDbInfo.Size == file.Length)
if (tryGetFileDbInfo.Size == file.Length)
{
Debug.WriteLine($"Find the Same File In Db {destinationFile}");
continue;
@ -47,7 +49,7 @@ public class FileCopy
{
tryGetFileDbInfo.NeedChange = true;
tryGetFileDbInfo.Size = file.Length;
file.CopyTo(destinationFile,true);
file.CopyTo(destinationFile, true);
Debug.WriteLine($"renew {destinationFile} from Db");
}
}
@ -57,7 +59,7 @@ public class FileCopy
tryGetFileDbInfo.Path = destinationFile;
tryGetFileDbInfo.Size = file.Length;
fileInfoDb.Files.Add(tryGetFileDbInfo);
file.CopyTo(destinationFile,true);
file.CopyTo(destinationFile, true);
Debug.WriteLine($"new {destinationFile} into Db and Copy");
}
/*if (File.Exists(destinationFile))
@ -81,6 +83,10 @@ public class FileCopy
copyList.Add((file.Length, file, destinationFile, "NewFile"));
}*/
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
fileInfoDb.SaveChanges();
}
@ -148,8 +154,14 @@ public class FileCopy
continue;
}
if (!desInfo.Directory.Exists)
{
try
{
desInfo.Directory.Create();
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
try
{