修复错误判断

This commit is contained in:
ZtRXR 2023-10-14 14:46:11 +08:00
parent 745d2e2b6c
commit 872644e47e
1 changed files with 47 additions and 35 deletions

View File

@ -34,53 +34,59 @@ public class FileCopy
{
foreach (var file in sourceDir.GetFiles())
{
string destinationFile = Path.Combine(desDir.FullName, file.Name);
var tryGetFileDbInfo = fileInfoDb.Files.Where(w => w.Path == destinationFile).FirstOrDefault();
if (tryGetFileDbInfo != null)
try
{
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}");
continue;
if (tryGetFileDbInfo.Size == file.Length)
{
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
{
tryGetFileDbInfo.NeedChange = true;
tryGetFileDbInfo = new MyDB.Class.FileInfoTable();
tryGetFileDbInfo.Path = destinationFile;
tryGetFileDbInfo.Size = file.Length;
file.CopyTo(destinationFile,true);
Debug.WriteLine($"renew {destinationFile} from Db");
fileInfoDb.Files.Add(tryGetFileDbInfo);
file.CopyTo(destinationFile, true);
Debug.WriteLine($"new {destinationFile} into Db and Copy");
}
}
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)
/*if (File.Exists(destinationFile))
{
*//*Console.WriteLine($"Renew {file} --> {destinationFile}");*//*
copyList.Add((file.Length, file, destinationFile, "Renew"));
*//*file.CopyTo(destinationFile, true);*//*
var desFileInfo = new FileInfo(destinationFile);
if (desFileInfo.Length != file.Length)
{
*//*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
{
Debug.WriteLine($"Same {file} --> {destinationFile} {file.Length / 1024 / 1024}MB");
*//*copyList.Add((file, destinationFile, 0, "Same"));*//*
}
}
else
{
*//*Console.WriteLine($"NewFile {file} --> {destinationFile}");*//*
copyList.Add((file.Length, file, destinationFile, "NewFile"));
}*/
*//*Console.WriteLine($"NewFile {file} --> {destinationFile}");*//*
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
{