public static List <string> InitLocalSha(bool earse = false) { List <string> needToCalculateSha = new List <string>(); var filesIn115 = OneOneFiveService.Get115FilesModel(); var localFiles = GetAllLocalAvs(); if (filesIn115 != null && filesIn115.Any()) { if (earse) { ScanDataBaseManager.TruncateLocalShaMapping(); } foreach (var localFile in localFiles) { var matchedRecord = filesIn115.FirstOrDefault(x => x.n.Equals(localFile.Name, StringComparison.OrdinalIgnoreCase) && x.s == localFile.Length); if (matchedRecord != null && !string.IsNullOrEmpty(matchedRecord.sha)) { LocalShaMapping temp = new LocalShaMapping { FilePath = localFile.Name, FileFolder = Path.GetPathRoot(localFile.FullName), FileSize = localFile.Length, Sha1 = matchedRecord.sha }; ScanDataBaseManager.InsertLocalShaMapping(temp); } else { needToCalculateSha.Add(localFile.FullName); } } } return(needToCalculateSha); }
public static void Match115AndMoveLocalFile() { var filesIn115 = OneOneFiveService.Get115FilesModel(); foreach (var drive in Environment.GetLogicalDrives()) { Console.WriteLine($"处理 {drive}"); List <string> files = new List <string>(); List <string> toFin = new List <string>(); List <string> to115 = new List <string>(); var fin = drive + FinFolder; var up = drive + UpFolder; if (Directory.Exists(fin)) { files.AddRange(new DirectoryInfo(fin).GetFiles().Select(y => y.FullName).ToList()); } if (Directory.Exists(up)) { files.AddRange(new DirectoryInfo(up).GetFiles().Select(y => y.FullName).ToList()); } foreach (var file in files) { var name = Path.GetFileName(file); if (filesIn115.Exists(x => x.n.Equals(Path.GetFileName(file), StringComparison.OrdinalIgnoreCase) && x.s == new FileInfo(file).Length)) { var path = Path.GetDirectoryName(file) + "\\"; if (path == up) { toFin.Add(file); } } else { var path = Path.GetDirectoryName(file) + "\\"; if (path == fin) { to115.Add(file); } } } if (toFin.Count > 0) { if (!Directory.Exists(fin)) { Directory.CreateDirectory(fin); } Console.WriteLine($"移动 {toFin.Count} 到 FIN"); FileUtility.TransferFileUsingSystem(toFin, fin, true, true); } if (to115.Count > 0) { if (!Directory.Exists(up)) { Directory.CreateDirectory(up); } Console.WriteLine($"移动 {to115.Count} 到 UP115"); FileUtility.TransferFileUsingSystem(to115, up, true, true); } } }
private static Dictionary <int, List <MyFileInfo> > GenerateExistingAVs(List <AV> avs) { Dictionary <int, List <MyFileInfo> > fileContainer = new Dictionary <int, List <MyFileInfo> >(); var oneOneFiveFiles = OneOneFiveService.Get115FilesModel(); List <OneOneFiveItemWIthMatchId> matches = new List <OneOneFiveItemWIthMatchId>(); avs.ForEach(x => x.AvIdAndName = x.ID + "-" + x.Name); foreach (var file in oneOneFiveFiles) { if (file.n.Split('-').Length >= 3) { file.AvId = file.n.Split('-')[0] + "-" + file.n.Split('-')[1]; file.AvName = file.n.Replace(file.AvId, "").Substring(1).Replace("." + file.ico, "").Replace("-C", ""); } } foreach (var file in oneOneFiveFiles.Where(x => !string.IsNullOrEmpty(x.AvName))) { var matchList = avs.FirstOrDefault(x => x.Name == file.AvName); AV match = null; if (matchList != null) { match = matchList; } if (match != null) { matches.Add(new OneOneFiveItemWIthMatchId() { ico = file.ico, n = file.n, s = file.s, MatchId = match.AvId }); } } foreach (var match in matches) { if (fileContainer.ContainsKey(match.MatchId)) { fileContainer[match.MatchId].Add(new MyFileInfo() { Extension = "." + match.ico, FullName = match.n, Length = match.s, Name = match.n }); } else { fileContainer.Add(match.MatchId, new List <MyFileInfo> { new MyFileInfo() { Extension = "." + match.ico, FullName = match.n, Length = match.s, Name = match.n } }); } } return(fileContainer); }