修复错误判断

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

View File

@ -34,53 +34,59 @@ public class FileCopy
{ {
foreach (var file in sourceDir.GetFiles()) foreach (var file in sourceDir.GetFiles())
{ {
string destinationFile = Path.Combine(desDir.FullName, file.Name); try
var tryGetFileDbInfo = fileInfoDb.Files.Where(w => w.Path == destinationFile).FirstOrDefault();
if (tryGetFileDbInfo != null)
{ {
if(tryGetFileDbInfo.Size == file.Length) string destinationFile = Path.Combine(desDir.FullName, file.Name);
var tryGetFileDbInfo = fileInfoDb.Files.Where(w => w.Path == destinationFile).FirstOrDefault();
if (tryGetFileDbInfo != null)
{ {
Debug.WriteLine($"Find the Same File In Db {destinationFile}"); if (tryGetFileDbInfo.Size == file.Length)
continue; {
Debug.WriteLine($"Find the Same File In Db {destinationFile}");
continue;
}
else
{
tryGetFileDbInfo.NeedChange = true;
tryGetFileDbInfo.Size = file.Length;
file.CopyTo(destinationFile, true);
Debug.WriteLine($"renew {destinationFile} from Db");
}
} }
else else
{ {
tryGetFileDbInfo.NeedChange = true; tryGetFileDbInfo = new MyDB.Class.FileInfoTable();
tryGetFileDbInfo.Path = destinationFile;
tryGetFileDbInfo.Size = file.Length; tryGetFileDbInfo.Size = file.Length;
file.CopyTo(destinationFile,true); fileInfoDb.Files.Add(tryGetFileDbInfo);
Debug.WriteLine($"renew {destinationFile} from Db"); file.CopyTo(destinationFile, true);
Debug.WriteLine($"new {destinationFile} into Db and Copy");
} }
} /*if (File.Exists(destinationFile))
else
{
tryGetFileDbInfo = new MyDB.Class.FileInfoTable();
tryGetFileDbInfo.Path = destinationFile;
tryGetFileDbInfo.Size = file.Length;
fileInfoDb.Files.Add(tryGetFileDbInfo);
file.CopyTo(destinationFile,true);
Debug.WriteLine($"new {destinationFile} into Db and Copy");
}
/*if (File.Exists(destinationFile))
{
var desFileInfo = new FileInfo(destinationFile);
if (desFileInfo.Length != file.Length)
{ {
*//*Console.WriteLine($"Renew {file} --> {destinationFile}");*//* var desFileInfo = new FileInfo(destinationFile);
copyList.Add((file.Length, file, destinationFile, "Renew")); if (desFileInfo.Length != file.Length)
*//*file.CopyTo(destinationFile, true);*//* {
*//*Console.WriteLine($"Renew {file} --> {destinationFile}");*//*
copyList.Add((file.Length, file, destinationFile, "Renew"));
*//*file.CopyTo(destinationFile, true);*//*
}
else
{
Debug.WriteLine($"Same {file} --> {destinationFile} {file.Length / 1024 / 1024}MB");
*//*copyList.Add((file, destinationFile, 0, "Same"));*//*
}
} }
else else
{ {
Debug.WriteLine($"Same {file} --> {destinationFile} {file.Length / 1024 / 1024}MB"); *//*Console.WriteLine($"NewFile {file} --> {destinationFile}");*//*
*//*copyList.Add((file, destinationFile, 0, "Same"));*//* copyList.Add((file.Length, file, destinationFile, "NewFile"));
} }*/
}
else
{
*//*Console.WriteLine($"NewFile {file} --> {destinationFile}");*//*
copyList.Add((file.Length, file, destinationFile, "NewFile"));
}*/
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
} }
fileInfoDb.SaveChanges(); fileInfoDb.SaveChanges();
} }
@ -148,8 +154,14 @@ public class FileCopy
continue; continue;
} }
if (!desInfo.Directory.Exists) if (!desInfo.Directory.Exists)
{
try
{ {
desInfo.Directory.Create(); desInfo.Directory.Create();
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
} }
try try
{ {