使用数据库维护文件管理,修复文件管理BUG
This commit is contained in:
parent
c07715536c
commit
745d2e2b6c
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
19
FileCopy.cs
19
FileCopy.cs
@ -58,7 +58,7 @@ public class FileCopy
|
||||
tryGetFileDbInfo.Size = file.Length;
|
||||
fileInfoDb.Files.Add(tryGetFileDbInfo);
|
||||
file.CopyTo(destinationFile,true);
|
||||
Debug.WriteLine($"new {destinationFile} from Db");
|
||||
Debug.WriteLine($"new {destinationFile} into Db and Copy");
|
||||
}
|
||||
/*if (File.Exists(destinationFile))
|
||||
{
|
||||
@ -104,9 +104,9 @@ public class FileCopy
|
||||
{
|
||||
num = fileInfoDb.Files.Where(w=>w.NeedChange==true).Count();
|
||||
/*FileNum(source,ref num);*/
|
||||
Debug.WriteLine($"Totle Dic Num is {num}");
|
||||
Debug.WriteLine($"Totle Dic Num is {num} (From Db)");
|
||||
}
|
||||
return num;
|
||||
return num<0?0:num;
|
||||
}
|
||||
private static void FileNum(string source, ref long num)
|
||||
{
|
||||
@ -143,17 +143,26 @@ public class FileCopy
|
||||
var fileInfo = new FileInfo(file.Path);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
Debug.WriteLine($"暂存位置文件消失 {fileInfo.FullName}");
|
||||
Debug.WriteLine($"Cannot Find File In Computer {fileInfo.FullName}");
|
||||
file.NeedChange= false;
|
||||
continue;
|
||||
}
|
||||
if (!desInfo.Directory.Exists)
|
||||
{
|
||||
desInfo.Directory.Create();
|
||||
}
|
||||
try
|
||||
{
|
||||
fileInfo.CopyTo(desInfo.FullName, true);
|
||||
fileInfo.Delete();
|
||||
file.NeedChange = false;
|
||||
Debug.WriteLine($"moved the file and marked {fileInfo.FullName} --> {desInfo.FullName}");
|
||||
Debug.WriteLine($"moved the file and marked into Db {fileInfo.FullName} --> {desInfo.FullName}");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error: moved the file and marked into Db {fileInfo.FullName} --> {desInfo.FullName}\n{ex.ToString()}");
|
||||
}
|
||||
|
||||
doneNum++;
|
||||
}
|
||||
fileInfoDb.SaveChanges();
|
||||
|
18
Program.cs
18
Program.cs
@ -48,15 +48,17 @@ using System.Management;
|
||||
FileCopy.SimpleCopy(Path.Join(driveName, "FILE", "USBCopy"), Path.Join("D:", "老师文档"), ref doneNum);
|
||||
});
|
||||
var planPrint = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine("scanning and get totle num");
|
||||
var fileNumber = FileCopy.DicFileNum(Path.Join("D:", "老师文档"));
|
||||
Debug.WriteLine("scanned ok and get totle num");
|
||||
|
||||
Debug.WriteLine($"{doneNum} {fileNumber} {((int)((float)doneNum / (float)fileNumber * 100) < 0 ? 100 : (int)((float)doneNum / (float)fileNumber * 100))}.upd");
|
||||
while (!copyTask.IsCompleted)
|
||||
{
|
||||
var usbRoot = new DirectoryInfo(driveName);
|
||||
if (usbRoot.GetFiles().Where(w => w.Name == $"{(int)((float)doneNum / (float)fileNumber * 100)}.upd").ToArray().Length != 1)
|
||||
if (usbRoot.GetFiles().Where(w => w.Name == $"{((int)((float)doneNum / (float)fileNumber * 100) < 0 ? 100 : (int)((float)doneNum / (float)fileNumber * 100))}.upd").ToArray().Length != 1)
|
||||
{
|
||||
var oldPrint = usbRoot.GetFiles().Where(w => w.Name.EndsWith(".upd")).ToArray();
|
||||
Debug.WriteLine(doneNum.ToString());
|
||||
@ -67,9 +69,10 @@ using System.Management;
|
||||
}
|
||||
}
|
||||
|
||||
var newPrint = new FileInfo(Path.Join(driveName, $"{(int)((float)doneNum / (float)fileNumber * 100)}.upd"));
|
||||
var newPrint = new FileInfo(Path.Join(driveName, $"{((int)((float)doneNum / (float)fileNumber * 100) < 0 ? 100 : (int)((float)doneNum / (float)fileNumber * 100))}.upd"));
|
||||
var nPStream = newPrint.Create();
|
||||
nPStream.Close();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
{
|
||||
@ -82,10 +85,14 @@ using System.Management;
|
||||
file.Delete();
|
||||
}
|
||||
|
||||
var newPrint = new FileInfo(Path.Join(driveName, $"{(int)((float)doneNum / (float)fileNumber * 100)}.upd"));
|
||||
var newPrint = new FileInfo(Path.Join(driveName, $"{((int)((float)doneNum / (float)fileNumber * 100) < 0 ? 100: (int)((float)doneNum / (float)fileNumber * 100))}.upd"));
|
||||
var nPStream = newPrint.Create();
|
||||
nPStream.Close();
|
||||
}
|
||||
}catch(Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
});
|
||||
|
||||
Task.WaitAll(copyTask, planPrint);
|
||||
@ -103,9 +110,6 @@ using System.Management;
|
||||
{
|
||||
Directory.CreateDirectory(dPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FileCopy.Copy(driveName, dPath);
|
||||
|
||||
/*Console.WriteLine($"元素个数{sortedList.Count()}");*/
|
||||
|
Loading…
Reference in New Issue
Block a user