private static int CountFilesInDownloadDirs() { int fileCount = 0; foreach (string s in TVSettings.Instance.DownloadFolders.ToArray()) { fileCount += DirCache.CountFiles(s, true); } return(fileCount); }
private static int CountFilesInDownloadDirs() { return(TVSettings.Instance.DownloadFolders.ToArray().Sum(s => DirCache.CountFiles(s, true))); }
public override void Check(SetProgressDelegate prog, int startpct, int totPct) { prog.Invoke(startpct); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = 0; foreach (string s in TVSettings.Instance.DownloadFolders) { fileCount += DirCache.CountFiles(s, true); } DirCache dirCache = new DirCache(); foreach (string s in TVSettings.Instance.DownloadFolders) { if (ActionCancel) { return; } dirCache.AddFolder(prog, 0, fileCount, s, true); } int currentItem = 0; int totalN = ActionList.Count; foreach (ItemMissing me in ActionList.MissingItems()) { if (ActionCancel) { return; } prog.Invoke(startpct + ((totPct - startpct) * (++currentItem) / (totalN + 1))); ItemList thisRound = new ItemList(); List <DirCacheEntry> matchedFiles = new List <DirCacheEntry>(); foreach (DirCacheEntry dce in dirCache) { if (!ReviewFile(me, thisRound, dce)) { continue; } matchedFiles.Add(dce); } if (matchedFiles.Count == 1) { if (!OtherActionsMatch(matchedFiles[0], me)) { toRemove.Add(me); newList.AddRange(thisRound); } else { LOGGER.Warn($"Ignoring potential match for {me.Episode.Show.ShowName} S{me.Episode.AppropriateSeasonNumber} E{me.Episode.AppropriateEpNum}: with file {matchedFiles[0]?.TheFile.FullName} as there are multiple actions for that file"); me.AddComment( $"Ignoring potential match with file {matchedFiles[0]?.TheFile.FullName} as there are multiple actions for that file"); } } else if (matchedFiles.Count > 1) { List <DirCacheEntry> bestMatchedFiles = IdentifyBestMatches(matchedFiles); if (bestMatchedFiles.Count == 1) { //We have one file that is better, lets use it toRemove.Add(me); newList.AddRange(thisRound); } else { foreach (DirCacheEntry matchedFile in matchedFiles) { LOGGER.Warn( $"Ignoring potential match for {me.Episode.Show.ShowName} S{me.Episode.AppropriateSeasonNumber} E{me.Episode.AppropriateEpNum}: with file {matchedFile?.TheFile.FullName} as there are multiple files for that action"); me.AddComment( $"Ignoring potential match with file {matchedFile?.TheFile.FullName} as there are multiple files for that action"); } } } } if (TVSettings.Instance.KeepTogether) { KeepTogether(newList); } prog.Invoke(totPct); if (!TVSettings.Instance.LeaveOriginals) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) { continue; } bool last = i == (newList.Count - 1); ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!FileHelper.Same(a1.From, a2.From)) { a1.Operation = ActionCopyMoveRename.Op.move; } } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.move; } } } foreach (Item i in toRemove) { ActionList.Remove(i); } foreach (Item i in newList) { ActionList.Add(i); } }
public override void Check(SetProgressDelegate prog, int startpct, int totPct) { prog.Invoke(0); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = 0; foreach (string s in this.mDoc.SearchFolders) { fileCount += DirCache.CountFiles(s, true); } int c = 0; DirCache dirCache = new DirCache(); foreach (String s in this.mDoc.SearchFolders) { if (this.ActionCancel) { return; } c = dirCache.AddFolder(prog, c, fileCount, s, true); } c = 0; int totalN = this.TheActionList.Count; foreach (Item action1 in this.TheActionList) { if (this.ActionCancel) { return; } prog.Invoke(50 + 50 * (++c) / (totalN + 1)); // second 50% of progress bar if (action1 is ItemMissing) { if (this.FindMissingEp(dirCache, (ItemMissing)(action1), newList, ActionCopyMoveRename.Op.Copy)) { toRemove.Add(action1); } } } if (TVSettings.Instance.KeepTogether) { this.KeepTogether(newList); } prog.Invoke(100); if (!TVSettings.Instance.LeaveOriginals) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) { continue; } bool last = i == (newList.Count - 1); ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!FileHelper.Same(a1.From, a2.From)) { a1.Operation = ActionCopyMoveRename.Op.Move; } } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.Move; } } } foreach (Item i in toRemove) { this.TheActionList.Remove(i); } foreach (Item i in newList) { this.TheActionList.Add(i); } // if (Settings->ExportFOXML) // ExportFOXML(Settings->ExportFOXMLTo); }