private static List <MissingCheckModel> DoAllRelatedJav(string table, string content) { List <MissingCheckModel> ret = new List <MissingCheckModel>(); var avs = JavDataBaseManager.GetAllAV(); switch (table) { case "category": avs = avs.Where(x => x.Category.Contains(content)).ToList(); break; case "actress": avs = avs.Where(x => x.Actress.Contains(content)).ToList(); break; case "prefix": avs = avs.Where(x => x.ID.StartsWith(content.ToUpper() + "-")).ToList(); break; } foreach (var av in avs) { MissingCheckModel mcm = new MissingCheckModel { Av = av, Fi = new List <FileInfo>(), IsMatch = false, Seeds = new List <SeedMagnetSearchModel>() }; ret.Add(mcm); } return(ret.OrderBy(x => x.Av.ID).ToList()); }
public static void GenerateReportDataOnly() { List <ReportItem> items = new List <ReportItem>(); ScanDataBaseManager.DeleteReportItem(); var allAv = JavDataBaseManager.GetAllAV(); var allMatch = GenerateExistingAVs(); Report report = new Report(); report.ExtensionModel = new Dictionary <string, int>(); report.TotalCount = allAv.Count; var reportId = ScanDataBaseManager.InsertReport(report); report.ReportId = reportId; int process = 0; foreach (var av in allAv) { ProcessReportType(av, allMatch, report, items); process++; Console.WriteLine(process + " / " + allAv.Count); } ; ScanDataBaseManager.BatchInserReportItem(items); ScanDataBaseManager.UpdateReport(report); ScanDataBaseManager.UpdateReportFinish(reportId); }
static void Main(string[] args) { Dictionary <string, AV> match = new Dictionary <string, AV>(); ReportModel report = new ReportModel(); report.Top = 10; Console.WriteLine("正在获取AV爬虫信息..."); var filesContainer = ReportHelper.GenerateExistingAVs(); Console.WriteLine("正在获取本地AV信息..."); var avs = JavDataBaseManager.GetAllAV(); Console.WriteLine("正在生成基本报表..."); ReportHelper.GenerateBasicReport(filesContainer, avs, match, report); Console.WriteLine("正在生成匹配报表..."); ReportHelper.GenerateMatchReport(filesContainer, avs, match, report); Console.WriteLine("正在生成报表其他部分..."); ReportHelper.GenerateOtherReport(filesContainer, avs, match, report); Console.WriteLine(ReportHelper.GenerateActuralReport(report)); //ReportHelper.Test(filesContainer, avs, match, report); Console.ReadKey(); }
private static void GetAVFromIdAndName() { var folder = "E:\\New folder\\Fin"; var files = Directory.GetFiles(folder); int total = files.Length; int match = 0; List <string> unmatched = new List <string>(); foreach (var file in files) { FileInfo fi = new FileInfo(file); var split = fi.Name.Split('-'); if (split.Length >= 3) { var id = split[0] + "-" + split[1]; var nameAfter = fi.Name.Replace(id, "").Split('-'); string name = ""; if (nameAfter.Length == 0) { name = fi.Name.Replace(id, "").Replace(fi.Extension, ""); } else { name = nameAfter[0]; foreach (var slice in nameAfter) { if (slice.Length > 1) { name += "-" + slice; } } } var avs = JavDataBaseManager.GetAllAV(id, name); if (avs != null && avs.Count == 1) { match++; } else { unmatched.Add(fi.FullName); } } } foreach (var unmatch in unmatched) { Console.WriteLine(unmatch); } Console.WriteLine("Total: " + total + " Matched: " + match); }
private void FindAv(string id) { var avs = JavDataBaseManager.GetAllAV(id); if (avs != null && avs.Count > 0) { ShowAv(avs); } }
private void ShowRenameDetail() { RenameInitPartial(); var file = renameFi[indexOfRename]; currentFi = file; var scan = new Scan() { FileName = file.FullName, Location = file.DirectoryName, Size = Utils.FileSize.GetAutoSizeString(file.Length, 1) }; txtRenameFinal.Text = ""; pbRename.Maximum = renameFi.Count; pbRename.Value = indexOfRename; txtRenameOri.Text = currentFi.FullName; txtRenameFinal.Text = currentFi.FullName; if (file != null) { var ids = FileUtility.GetPossibleID(scan, prefixs); if (ids.Count > 0) { currentAVS = new List <AV>(); currentAVS.AddRange(JavDataBaseManager.GetAllAV(ids)); if (currentAVS.Count > 0) { indexOfCurrentAV = 0; ShowRenameInfo(); if (currentAVS.Count > 1) { btRenameLeft.Show(); btRenameRight.Show(); } else { btRenameLeft.Hide(); btRenameRight.Hide(); } } else { //MessageBox.Show("Not found, please add manually."); } } else { //MessageBox.Show("Not found, please add manually."); } } }
private void RefreshCache() { foreach (var name in JavDataBaseManager.GetAllAV().Select(x => x.ID).ToList()) { if (!allPrefix.Contains(name.Split('-')[0])) { allPrefix.Add(name.Split('-')[0]); } } allPrefix = allPrefix.OrderByDescending(x => x.Length).ToList(); }
public static List <AV> GetClosetMatch(string inputName) { List <AV> ret = new List <AV>(); List <string> allPossibleMatch = new List <string>(); inputName = inputName.ToUpper(); if (!CacheTools.HasCache("cache-prefix")) { UpdateCache(); } var allPrefix = CacheTools.GetCache <List <string> >("cache-prefix"); foreach (var prefix in allPrefix) { if (inputName.Contains(prefix)) { var pattern = prefix + "{1}-?\\d{1,5}"; var possibleId = Regex.Match(inputName, pattern).Value; if (possibleId.Contains("-")) { allPossibleMatch.Add(possibleId); } else { bool isFirst = true; StringBuilder sb = new StringBuilder(); foreach (var c in possibleId) { if (c >= '0' && c <= '9') { if (isFirst) { sb.Append("-"); isFirst = false; } } sb.Append(c); } allPossibleMatch.Add(sb.ToString()); } } } ret = JavDataBaseManager.GetAllAV(allPossibleMatch); ret = ret.OrderByDescending(x => x.AvLength).ToList(); return(ret); }
private void btnRenameSearch_Click(object sender, EventArgs e) { currentAVS = new List <AV>(); currentAVS.AddRange(JavDataBaseManager.GetAllAV(txtKeyword.Text)); if (currentAVS.Count > 0) { indexOfCurrentAV = 0; ShowRenameInfo(); } else { //MessageBox.Show("Not found, please add manually."); } }
private static void AddTemp(Scan scan, List <string> possibleIDs, List <Match> temp) { foreach (var id in possibleIDs) { var avs = JavDataBaseManager.GetAllAV(id); foreach (var av in avs) { temp.Add(new Match { AvID = av.ID.ToLower(), Location = scan.Location.ToLower(), Name = scan.FileName.ToLower() }); } } }
private static void ClearJav() { var all = JavDataBaseManager.GetAllAV(); var idDIc = all.GroupBy(x => x.ID).ToDictionary(x => x.Key, x => x.ToList()).Where(x => x.Value.Count > 1).ToDictionary(x => x.Key, x => x); var urlDic = all.GroupBy(x => x.URL).ToDictionary(x => x.Key, x => x.ToList()).Where(x => x.Value.Count > 1).ToDictionary(x => x.Key, x => x); var fileName = "G:\\JavAvBak.json"; File.Create(fileName).Close(); StreamWriter sw = new StreamWriter(fileName); sw.WriteLine(JsonConvert.SerializeObject(all)); sw.Close(); }
public static void MakeUpPic() { var imageFolder = @"E:\JavLibraryImgs\"; var avs = JavDataBaseManager.GetAllAV().OrderByDescending(x => x.CreateTime); int index = 0; foreach (var av in avs) { var pic = imageFolder + av.ID + av.Name + ".jpg"; if (!File.Exists(pic)) { DownloadHelper.DownloadHttps(av.PictureURL, pic, ""); Console.WriteLine(++index + " " + pic); } } }
private static void AddTemp(Scan scan, List <string> possibleIDs, List <Match> temp) { foreach (var id in possibleIDs) { var avs = JavDataBaseManager.GetAllAV(id); foreach (var av in avs) { temp.Add(new Match { AvID = av.ID.ToLower(), AvName = av.Name.ToLower(), Location = scan.Location.ToLower(), Name = scan.FileName.ToLower() }); sb.AppendLine(string.Format("文件{0}找到一个符合条件的AV -> {1}", scan.FileName, av.ID)); } } }
private void ShowRenameFiles(string folder) { RenameInit(); currentFolder = folder + "/"; renameFi = new List <FileInfo>(); FileUtility.GetFilesRecursive(folder, formats, excludes, renameFi); renameFi = renameFi.Where(x => !x.Name.Contains("-fin")).ToList(); avs = JavDataBaseManager.GetAllAV(); prefixs = FileUtility.GetPrefix(avs); pbRename.Minimum = 0; pbRename.Maximum = renameFi.Count; pbRename.Step = 1; if (renameFi.Count > 0) { indexOfRename = 0; lbRenameTotal.Text = string.Format(renameTotal, (indexOfRename + 1), renameFi.Count, renameFi[indexOfRename].FullName); btnRenamePre.Enabled = true; btnRenameNext.Enabled = true; ShowRenameDetail(); } }
public static void GenerateReport() { ReportModel report = new ReportModel(); report.Formats = new Dictionary <string, int>(); report.ActressRatio = new List <ReportRatioModel>(); report.CategoryRatio = new List <ReportRatioModel>(); report.CompanyRatio = new List <ReportRatioModel>(); report.DirectorRatio = new List <ReportRatioModel>(); report.PrefixRatio = new List <ReportRatioModel>(); report.YearRatio = new List <ReportRatioModel>(); report.TopActress = new Dictionary <string, int>(); report.TopCategory = new Dictionary <string, int>(); report.TopCompany = new Dictionary <string, int>(); report.TopDirctor = new Dictionary <string, int>(); report.TopPrefix = new Dictionary <string, int>(); report.TopDate = new Dictionary <string, int>(); report.Top = 10; Console.WriteLine("正在获取AV爬虫信息..."); var avs = JavDataBaseManager.GetAllAV(); Console.WriteLine("正在获取本地AV信息..."); var filesContainer = GenerateExistingAVs(); Console.WriteLine("正在生成报表基本数据..."); GenerateBasicReportData(avs, filesContainer, report); var reportStr = PrintReport(report); Console.WriteLine(reportStr); }
static void Main(string[] args) { var files = GetFiles(); var avs = JavDataBaseManager.GetAllAV(); var prefix = FileUtility.GetPrefix(avs); List <Match> temp = new List <Match>(); foreach (var f in files) { FileInfo file = new FileInfo(f); var scan = new Scan { FileName = file.Name.Trim().ToLower(), Location = file.DirectoryName.Trim().ToLower(), Size = FileSize.GetAutoSizeString(file.Length, 2) }; var possibleIDs = FileUtility.GetPossibleID(scan, prefix); AddTemp(scan, possibleIDs, temp); } Console.ReadKey(); }
private static void RemoveDuplicate() { List <AV> needToFixIds = new List <AV>(); int invalidCount = 0; int tureInvalidCount = 0; var invalids = FileUtility.GetInvalidChar(); var avs = JavDataBaseManager.GetAllAV(); foreach (var av in avs) { foreach (var invalid in invalids) { if (av.Name.Contains(invalid)) { needToFixIds.Add(av); } } } foreach (var id in needToFixIds) { invalidCount++; var effectedRows = avs.Where(x => x.ID == id.ID && x.Company == id.Company && x.Director == id.Director).ToList(); if (effectedRows.Count == 1) { tureInvalidCount++; var target = effectedRows.FirstOrDefault(); target.Name = FileUtility.ReplaceInvalidChar(target.Name); JavDataBaseManager.UpdateInvalid(target); } else if (effectedRows.Count > 1) { tureInvalidCount++; int needToFixCount = 0; List <AV> toBeDeleted = new List <AV>(); foreach (var item in effectedRows) { foreach (var invalid in invalids) { if (item.Name.Contains(invalid)) { needToFixCount++; toBeDeleted.Add(item); } } } if (needToFixCount == effectedRows.Count) { var orderedList = toBeDeleted.OrderBy(x => x.AvId).ToList(); var keep = orderedList.FirstOrDefault(); keep.Name = FileUtility.ReplaceInvalidChar(keep.Name); JavDataBaseManager.UpdateInvalid(keep); foreach (var delete in toBeDeleted.Skip(1)) { JavDataBaseManager.DeleteInvalid(delete); } } else { foreach (var delete in toBeDeleted) { JavDataBaseManager.DeleteInvalid(delete); } } } } Console.WriteLine("Has --> " + invalidCount + " invalid.... trueInvalidCount " + tureInvalidCount); Console.ReadKey(); }
private static void CheckNameMapping() { var avs = JavDataBaseManager.GetAllAV(); var files = new DirectoryInfo(imageFolder).GetFiles(); //foreach (var av in avs) //{ // if (!File.Exists(imageFolder + av.ID + av.Name + ".jpg")) // { // var possibleFiles = files.Where(x => x.Name.StartsWith(av.ID)).ToList(); // if (possibleFiles != null && possibleFiles.Count == 1 && av.PictureURL != "http:../img/noimagepl.gif") // { // Console.WriteLine(av.ID + " " + av.Name); // foreach (var sub in possibleFiles) // { // //sub.MoveTo(FileUtility.ReplaceInvalidChar(sub.Name.Replace(sub.Extension, "")) + sub.Extension); // //JavDataBaseManager.UpdateAvName(FileUtility.ReplaceInvalidChar(sub.Name.Replace(av.ID,"").Replace(sub.Extension, "")), av.AvId); // Console.WriteLine("\t" + sub.Name); // } // } // } //} //foreach (var av in avs) //{ // if (av.Name.Contains(".jpg")) // { // JavDataBaseManager.UpdateAvName(av.Name.Replace(".jpg", ""), av.AvId); // } //} //JavLibraryHelper.DoListSearch(list, true); //var files = new DirectoryInfo(imageFolder).GetFiles(); //foreach (var file in files) //{ // if (file.Name.Replace(file.Extension, "").EndsWith(" ")) // { // if (!File.Exists(imageFolder + file.Name.Replace(file.Extension, "").Trim() + file.Extension)) // { // file.MoveTo(imageFolder + file.Name.Replace(file.Extension, "").Trim() + file.Extension); // } // else // { // file.Delete(); // } // } //} //int fcount = 0; //int dcount = 0; //foreach (var file in files) //{ // if (FileUtility.HasInvalidChar(file.Name.Replace(file.Extension, ""))) // { // var newFile = imageFolder + FileUtility.ReplaceInvalidChar(file.Name.Replace(file.Extension, "")) + file.Extension; // if (File.Exists(newFile)) // { // file.Delete(); // } // else // { // file.MoveTo(newFile); // fcount++; // } // } //} //foreach (var av in avs) //{ // if (FileUtility.HasInvalidChar(av.Name)) // { // var newName = FileUtility.ReplaceInvalidChar(av.Name); // if (JavDataBaseManager.HasAv(av.ID, newName)) // { // JavDataBaseManager.DeleteAV(av.AvId); // } // else // { // JavDataBaseManager.UpdateAvName(newName, av.AvId); // dcount++; // } // } //} //Console.WriteLine("File " + fcount); //Console.WriteLine("DB " + dcount); Console.WriteLine("完毕"); }
static void Main(string[] args) { StringBuilder logSb = new StringBuilder(); Dictionary <string, int> moveReocrd = new Dictionary <string, int>(); Dictionary <FileInfo, List <AV> > ret = new Dictionary <FileInfo, List <AV> >(); string folder = ""; string moveFolder = ""; string logFolder = ""; int fount = 0; int notFount = 0; while (string.IsNullOrEmpty(folder)) { Console.WriteLine("请输入文件夹,按回车键继续"); var tempFolder = Console.ReadLine(); if (!string.IsNullOrEmpty(tempFolder) && Directory.Exists(tempFolder)) { folder = tempFolder; moveFolder = tempFolder + "/tempFin/"; logFolder = tempFolder + "/log/"; if (!Directory.Exists(moveFolder)) { Directory.CreateDirectory(moveFolder); } if (!Directory.Exists(logFolder)) { Directory.CreateDirectory(logFolder); } } } Console.WriteLine("加载AV缓存"); var avs = JavDataBaseManager.GetAllAV(); Console.WriteLine("共加载 --> " + avs.Count); Console.WriteLine("处理番号前缀"); foreach (var name in avs.Select(x => x.ID).ToList()) { if (!allPrefix.Contains(name.Split('-')[0])) { allPrefix.Add(name.Split('-')[0]); } } Console.WriteLine("共收集 --> " + allPrefix.Count + " 番号前缀"); allPrefix = allPrefix.OrderByDescending(x => x.Length).ToList(); Console.WriteLine("获取文件夹 --> " + folder + " 下的文件"); var files = Directory.GetFiles(folder); Console.WriteLine("共获取 --> " + files.Count() + " 个文件"); foreach (var f in files) { bool findMatch = false; string pi = ""; FileInfo fi = new FileInfo(f); List <AV> fiMatchList = new List <AV>(); var fiNameUpper = fi.Name.ToUpper(); var fileNameWithoutFormat = fiNameUpper.Replace(fi.Extension.ToUpper(), ""); ret.Add(fi, fiMatchList); //Console.WriteLine("正在处理 --> " + fi.FullName); foreach (var prefix in allPrefix) { if (fileNameWithoutFormat.Contains(prefix)) { //Console.WriteLine("\t找到适配的前缀 --> " + prefix); var pattern = prefix + "{1}-?\\d{1,5}"; var possibleId = Regex.Match(fileNameWithoutFormat, pattern).Value; if (possibleId.Contains("-")) { pi = possibleId; } else { bool isFirst = true; StringBuilder sb = new StringBuilder(); foreach (var c in possibleId) { if (c >= '0' && c <= '9') { if (isFirst) { sb.Append("-"); isFirst = false; } } sb.Append(c); } pi = sb.ToString(); } if (!string.IsNullOrEmpty(pi)) { var possibleAv = avs.Where(x => x.ID == pi).ToList(); //Console.WriteLine("\t找到一个匹配 --> " + pi); findMatch = true; foreach (var av in possibleAv) { fiMatchList.AddRange(possibleAv); } break; } } } if (findMatch) { fount++; } else { notFount++; } } foreach (var item in ret) { if (item.Value.Count == 0) { //Console.WriteLine(item.Key.FullName + "没有找到匹配"); } else if (item.Value.Count > 1) { //Console.WriteLine(item.Key.FullName + "找到多个匹配"); foreach (var subItem in item.Value) { //Console.WriteLine("\t" + subItem); } } else if (item.Value.Count == 1) { var tempFileName = item.Value.FirstOrDefault().ID + "-" + item.Value.FirstOrDefault().Name + item.Key.Extension; if (moveReocrd.ContainsKey(tempFileName)) { moveReocrd[tempFileName]++; } else { moveReocrd.Add(tempFileName, 1); } if (File.Exists(moveFolder + tempFileName)) { //logSb.AppendLine("-------移动 --> " + moveFolder + tempFileName + " 到 --> " + moveFolder + item.Value.FirstOrDefault().ID + "-" + item.Value.FirstOrDefault().Name + "-1" + item.Key.Extension); //File.Move(moveFolder + tempFileName, moveFolder + item.Value.FirstOrDefault().ID + "-" + item.Value.FirstOrDefault().Name + "-1" + item.Key.Extension); tempFileName = item.Value.FirstOrDefault().ID + "-" + item.Value.FirstOrDefault().Name + "-" + moveReocrd[tempFileName] + item.Key.Extension; logSb.AppendLine("*******移动 --> " + item.Key.FullName + " 到 --> " + moveFolder + tempFileName); } else { logSb.AppendLine("移动 --> " + item.Key.FullName + " 到 --> " + moveFolder + tempFileName); } try { File.Move(item.Key.FullName, moveFolder + tempFileName); } catch (Exception ee) { logSb.AppendLine(ee.ToString()); } } } Console.WriteLine("找到匹配 --> " + fount + " 未找到匹配 --> " + notFount); var logFile = logFolder + "log" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; File.Create(logFile).Close(); StreamWriter sw = new StreamWriter(logFile, true, Encoding.UTF8); sw.WriteLine(logSb.ToString()); Console.WriteLine("按任意键结束"); Console.ReadKey(); }
public static void BackUpJav(string drive) { var dateStr = DateTime.Today.ToString("yyyyMMdd"); var extension = ".json"; var folder = drive + @"\Github\AllInOneAV\Scripts\\"; var rawFolder = folder + "dataRaw\\"; var zipFileFoler = folder + "dataZip\\"; var zipFile = zipFileFoler + dateStr + ".zip"; var avFile = rawFolder + "av" + dateStr + extension; var actressFile = rawFolder + "actress" + dateStr + extension; var directorFile = rawFolder + "director" + dateStr + extension; var companyFile = rawFolder + "company" + dateStr + extension; var publisherFile = rawFolder + "publisher" + dateStr + extension; StreamWriter sw = null; var avs = JavDataBaseManager.GetAllAV(); var actress = JavDataBaseManager.GetActress(); var director = JavDataBaseManager.GetDirector(); var company = JavDataBaseManager.GetCompany(); var publisher = JavDataBaseManager.GetPublisher(); if (!Directory.Exists(rawFolder)) { Directory.CreateDirectory(rawFolder); } if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if (!Directory.Exists(zipFileFoler)) { Directory.CreateDirectory(zipFileFoler); } foreach (var file in new DirectoryInfo(rawFolder).GetFiles()) { file.Delete(); Thread.Sleep(50); } if (!File.Exists(avFile)) { File.Create(avFile).Close(); sw = new StreamWriter(avFile); sw.WriteLine(JsonConvert.SerializeObject(avs)); sw.Close(); } if (!File.Exists(actressFile)) { File.Create(actressFile).Close(); sw = new StreamWriter(actressFile); sw.WriteLine(JsonConvert.SerializeObject(actress)); sw.Close(); } if (!File.Exists(directorFile)) { File.Create(directorFile).Close(); sw = new StreamWriter(directorFile); sw.WriteLine(JsonConvert.SerializeObject(director)); sw.Close(); } if (!File.Exists(companyFile)) { File.Create(companyFile).Close(); sw = new StreamWriter(companyFile); sw.WriteLine(JsonConvert.SerializeObject(company)); sw.Close(); } if (!File.Exists(publisherFile)) { File.Create(publisherFile).Close(); sw = new StreamWriter(publisherFile); sw.WriteLine(JsonConvert.SerializeObject(publisher)); sw.Close(); } }
public static void Rename(List <FileItemModel> files, string toFolder, string notFoundFolder, CookieContainer cc) { var avs = JavDataBaseManager.GetAllAV(); List <string> allPrefix = new List <string>(); foreach (var name in avs.Select(x => x.ID).ToList()) { var tempPrefix = name.Split('-')[0]; if (!allPrefix.Contains(tempPrefix)) { allPrefix.Add(tempPrefix); } } allPrefix = allPrefix.OrderByDescending(x => x.Length).ToList(); foreach (var file in files.OrderBy(x => x.n)) { List <RenameModel> tempRet = new List <RenameModel>(); List <AV> possibleAv = new List <AV>(); var fileNameWithoutFormat = file.n.Replace("." + file.ico, "").ToLower(); var fileNameWithoutFormatAndEpisode = ""; if (fileNameWithoutFormat.Split('-').Length >= 3) { fileNameWithoutFormatAndEpisode = fileNameWithoutFormat.Split('-')[0] + "-" + fileNameWithoutFormat.Split('-')[1] + "-" + fileNameWithoutFormat.Split('-')[2].Substring(0, 3); } foreach (var prefix in allPrefix) { var pattern = prefix + "{1}-?\\d{1,7}"; var matches = Regex.Matches(fileNameWithoutFormat, pattern, RegexOptions.IgnoreCase); foreach (System.Text.RegularExpressions.Match m in matches) { var possibleAvId = m.Groups[0].Value; if (!possibleAvId.Contains("-")) { bool isFirst = true; StringBuilder sb = new StringBuilder(); foreach (var c in possibleAvId) { if (c >= '0' && c <= '9') { if (isFirst) { sb.Append("-"); isFirst = false; } } sb.Append(c); } possibleAvId = sb.ToString(); } var tempAv = JavDataBaseManager.GetAllAV(possibleAvId); if (tempAv != null && tempAv.Count > 0) { possibleAv.AddRange(tempAv); } else { var prefixPart = possibleAvId.Split('-')[0]; var numberPart = possibleAvId.Split('-')[1]; while (numberPart.StartsWith("0")) { numberPart = numberPart.Substring(1); possibleAvId = prefixPart + "-" + numberPart; tempAv = JavDataBaseManager.GetAllAV(possibleAvId); if (tempAv != null && tempAv.Count > 0) { possibleAv.AddRange(tempAv); } } } } } if (possibleAv != null && possibleAv.Count >= 1) { var rename = possibleAv.OrderByDescending(x => x.Name.Length).Take(1).FirstOrDefault(); var chinese = (fileNameWithoutFormat.EndsWith("-c") || fileNameWithoutFormat.EndsWith("-ch") || fileNameWithoutFormat.EndsWith("ch")) ? "-C" : ""; var tempName = rename.ID + "-" + rename.Name + chinese + "." + file.ico; Rename(file.fid, tempName, cc); //115 var sameShaFiles = new List <FileItemModel>(); //Get115SearchFileResult(cc, file.sha, toFolder); //TODO 查询目标文件夹有没有相同SHA,如果有删除当前 if (sameShaFiles != null && sameShaFiles.Any()) { Delete(file.fid, cc); } else { //TODO 查询目标文件夹有没有相同名称,如果有旧的名称加上-1,当前文件用之前同名文件最大的-X + 1 var similarName = Get115SearchFileResult(cc, fileNameWithoutFormat, toFolder); var sameName = new List <FileItemModel>(); if (similarName != null && !string.IsNullOrEmpty(fileNameWithoutFormatAndEpisode)) { sameName = similarName.Where(x => x.n.StartsWith(fileNameWithoutFormatAndEpisode, StringComparison.OrdinalIgnoreCase) && x.cid == toFolder).ToList(); } if (sameName != null && sameName.Any()) { var relatedFile = sameName; if (relatedFile.Count == 1) { var existFile = relatedFile.FirstOrDefault(); Rename(existFile.fid, fileNameWithoutFormat.ToUpper() + "-1." + existFile.ico, cc); Rename(file.fid, fileNameWithoutFormat.ToUpper() + "-" + (relatedFile.Count + 1) + "." + file.ico, cc); Move(file.fid, toFolder, cc); } else { //TODO从(x)数字大的开始倒序重命名,举例3个文件的时候,(2)实际应该是-1, (1)实际应该是-2, 不带(X)的实际应该是-3 var count = relatedFile.Count; foreach (var fi in relatedFile) { var fileName = fi.n.Replace("." + fi.ico, ""); if (fileName.EndsWith(")")) { int number = -1; var numberStr = fileName.Substring(fileName.LastIndexOf("(") + 1); int.TryParse(numberStr.Substring(0, numberStr.Length - 1), out number); if (number > 0 && number < count) { fileName = fileName.Substring(0, fileName.LastIndexOf("(")); fileName += "-" + (count - number) + "." + file.ico; } } else { fileName += "-" + count + "." + file.ico; } Rename(fi.fid, fileName.ToUpper(), cc); } Rename(file.fid, fileNameWithoutFormat.ToUpper() + "-" + relatedFile.Count + 1 + "." + file.ico, cc); Move(file.fid, toFolder, cc); } } else { Move(file.fid, toFolder, cc); } } } else { Move(file.fid, notFoundFolder, cc); } } }
public static Dictionary<string, List<RenameModel>> PrepareRename(string sourceFolder, int fileSizeLimit, int take = 1) { Dictionary<string, List<RenameModel>> ret = new Dictionary<string, List<RenameModel>>(); if (Directory.Exists(sourceFolder)) { var files = new DirectoryInfo(sourceFolder).GetFiles(); if (fileSizeLimit > 0) { files = files.Where(x => x.Length >= fileSizeLimit * 1024 * 1024 * 1024).ToArray(); } if (files.Count() > 0) { var avs = JavDataBaseManager.GetAllAV(); List<string> allPrefix = new List<string>(); foreach (var name in avs.Select(x => x.ID).ToList()) { var tempPrefix = name.Split('-')[0]; if (!allPrefix.Contains(tempPrefix)) { allPrefix.Add(tempPrefix); } } allPrefix = allPrefix.OrderByDescending(x => x.Length).ToList(); foreach (var file in files) { List<RenameModel> tempRet = new List<RenameModel>(); List<AV> possibleAv = new List<AV>(); var fileNameWithoutFormat = file.Name.Replace(file.Extension, "").ToLower(); foreach (var prefix in allPrefix) { var pattern = prefix + "{1}-?\\d{1,7}"; var matches = Regex.Matches(fileNameWithoutFormat, pattern, RegexOptions.IgnoreCase); foreach (Match m in matches) { var possibleAvId = m.Groups[0].Value; if (!possibleAvId.Contains("-")) { bool isFirst = true; StringBuilder sb = new StringBuilder(); foreach (var c in possibleAvId) { if (c >= '0' && c <= '9') { if (isFirst) { sb.Append("-"); isFirst = false; } } sb.Append(c); } possibleAvId = sb.ToString(); } var tempAv = JavDataBaseManager.GetAllAV(possibleAvId); if (tempAv != null && tempAv.Count > 0) { possibleAv.AddRange(tempAv); } else { var prefixPart = possibleAvId.Split('-')[0]; var numberPart = possibleAvId.Split('-')[1]; while (numberPart.StartsWith("0")) { numberPart = numberPart.Substring(1); possibleAvId = prefixPart + "-" + numberPart; tempAv = JavDataBaseManager.GetAllAV(possibleAvId); if (tempAv != null && tempAv.Count > 0) { possibleAv.AddRange(tempAv); } } } } } List<RenameModel> temp = new List<RenameModel>(); foreach (var av in possibleAv.Take(take)) { var chinese = (fileNameWithoutFormat.EndsWith("-c") || fileNameWithoutFormat.EndsWith("-ch") || fileNameWithoutFormat.EndsWith("ch")) ? "-C" : ""; var tempName = av.ID + "-" + av.Name + chinese + file.Extension; temp.Add(new RenameModel() { AvId = av.ID, AvImg = av.PictureURL, AvName = av.Name, MoveFile = tempName }); } ret.Add(file.FullName, temp); } } } return ret; }
public static void Start() { try { sb.AppendLine(string.Format("开始扫描 {0}", DateTime.Now.ToLongTimeString())); //var drivers = Environment.GetLogicalDrives().Skip(1).ToList(); List <FileInfo> fi = new List <FileInfo>(); List <Match> temp = new List <Match>(); foreach (var driver in folders) { sb.AppendLine(string.Format("添加扫描驱动器: {0}", driver)); Console.WriteLine("Processing " + driver); if (!string.IsNullOrEmpty(FileUtility.GetFilesRecursive(driver, formats, excludes, fi, 100))) { sb.AppendLine("获取文件失败"); } } var avs = JavDataBaseManager.GetAllAV(); var prefix = FileUtility.GetPrefix(avs); Console.WriteLine("Fi -> " + fi.Count); Console.WriteLine("AV -> " + avs.Count + " Prefix -> " + prefix.Count); sb.AppendLine(string.Format("符合条件文件: {0}, 总共AV: {1}", fi.Count, avs.Count)); foreach (var file in fi) { var scan = new Scan { FileName = file.Name.Trim().ToUpper(), Location = file.DirectoryName.Trim().ToLower(), Size = FileSize.GetAutoSizeString(file.Length, 2) }; var possibleIDs = FileUtility.GetPossibleID(scan, prefix); possibleIDs = possibleIDs.OrderByDescending(x => x.Length).Take(1).ToList(); sb.AppendLine(string.Format("文件{0}可能的Match有{1}", file, possibleIDs.Count)); Console.WriteLine("PossibleIDs -> " + possibleIDs.Count); AddTemp(scan, possibleIDs, temp); } Console.WriteLine("Temp -> " + temp.Count); sb.AppendLine(string.Format("一共找到{0}个Match", temp.Count)); ScanDataBaseManager.ClearMatch(); foreach (var m in temp) { Console.WriteLine(string.Format("Insert {0}\\{1}", m.Location, m.Name)); sb.AppendLine(string.Format("在库中添加Match -> {0}", m.Location)); ScanDataBaseManager.SaveMatch(m); } sb.AppendLine("更新数据库状态"); ScanDataBaseManager.InsertFinish(); var duplicateItemList = new List <DuplicateItem>(); var tempDic = temp.GroupBy(x => x.AvID.ToLower()).ToDictionary(x => x.Key, y => y.ToList()); foreach (var item in tempDic) { var tempItem = new DuplicateItem(); tempItem.AvId = item.Key; tempItem.Matches = item.Value; duplicateItemList.Add(tempItem); } var jsonRoot = "C:/AvLog/"; var jsonStr = JsonConvert.SerializeObject(duplicateItemList).Replace("\\", "\\\\"); var jsonFile = "ScanJson" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".json"; LogHelper.WriteLog(jsonFile, jsonStr); EmailHelper.SendEmail("ScanJson", "详情见附件", new[] { "*****@*****.**" }, new[] { jsonRoot + jsonFile }); } catch (Exception e) { sb.AppendLine(e.ToString()); } finally { sb.AppendLine(string.Format("扫描结束 {0}", DateTime.Now.ToLongTimeString())); //var root = "C:/AvLog/"; //var file = "ScanAndMatch" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "-log.txt"; //LogHelper.WriteLog(file, sb.ToString()); //EmailHelper.SendEmail("ScanAndMatchLog", "详情见附件", new[] { "*****@*****.**" }, new[] { root + file }); } }
public static void Start() { try { Console.WriteLine(string.Format("开始扫描 {0}", DateTime.Now.ToLongTimeString())); var drivers = Environment.GetLogicalDrives().ToList(); List <FileInfo> fi = new List <FileInfo>(); List <Match> temp = new List <Match>(); List <Match> matches = new List <Match>(); foreach (var driver in drivers) { Console.WriteLine(string.Format("添加扫描驱动器: {0}", driver)); if (Directory.Exists(driver + "\\fin\\")) { if (!string.IsNullOrEmpty(FileUtility.GetFilesRecursive(driver + "\\fin\\", formats, excludes, fi, 100))) { Console.WriteLine("获取文件失败"); } } } var avs = JavDataBaseManager.GetAllAV(); avs.ForEach(x => x.ID = x.ID.ToUpper()); var prefix = FileUtility.GetPrefix(avs); Console.WriteLine(string.Format("获取AV {0} 条, 前缀 {1} 条", avs.Count, prefix.Count)); Parallel.ForEach(fi, new ParallelOptions { MaxDegreeOfParallelism = 10 }, file => { var split = file.Name.Split('-'); if (split.Length >= 3) { var id = split[0].ToUpper() + "-" + split[1].ToUpper(); var matchedAvs = avs.Where(x => x.ID == id).ToList(); if (matchedAvs != null) { Console.WriteLine(string.Format("{0} 找到 {1} 个匹配AV", file.FullName, matchedAvs.Count)); foreach (var av in matchedAvs) { Match m = new Match { AvID = id, AvName = av.Name, Location = file.DirectoryName, Name = file.Name, MatchAVId = av.AvId }; matches.Add(m); } } } }); Console.WriteLine("清空匹配记录"); ScanDataBaseManager.ClearMatch(); foreach (var match in matches) { try { //Console.WriteLine("保存 " + match.AvID); ScanDataBaseManager.SaveMatch(match); } catch (Exception ee) { //MessageBox.Show(match.Location + match.Name); //MessageBox.Show(ee.ToString()); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { Console.WriteLine(string.Format("扫描结束 {0}", DateTime.Now.ToLongTimeString())); } }