private void ScanWorker(object o) { try { ScanSettings settings = (ScanSettings)o; //When doing a full scan the show list is null indicating that all shows should be checked List <ShowItem> specific = settings.Shows ?? Library.Values.ToList(); while (!Args.Hide && Environment.UserInteractive && ((scanProgDlg is null) || (!scanProgDlg.Ready))) { Thread.Sleep(10); // wait for thread to create the dialog } TheActionList = new ItemList(); SetProgressDelegate noProgress = NoProgress; if (!settings.Unattended && settings.Type != TVSettings.ScanType.SingleShow) { new FindNewShowsInDownloadFolders(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.AddNewProg, 0, 50, specific, settings); new FindNewShowsInLibrary(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.AddNewProg, 50, 100, specific, settings); } new CheckShows(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.MediaLibProg, specific, settings); new CleanDownloadDirectory(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.DownloadFolderProg, specific, settings); localFinders.Check((scanProgDlg is null) ? noProgress : scanProgDlg.LocalSearchProg, specific, settings); downloadFinders.Check((scanProgDlg is null) ? noProgress : scanProgDlg.DownloadingProg, specific, settings); searchFinders.Check((scanProgDlg is null)? noProgress : scanProgDlg.ToBeDownloadedProg, specific, settings); if (settings.Token.IsCancellationRequested) { TheActionList.Clear(); LastScanComplete = false; return; } // sort Action list by type TheActionList.Sort(new ActionItemSorter()); // was new ActionSorter() Stats().FindAndOrganisesDone++; lastScanType = settings.Type; LastScanComplete = true; } catch (TVRenameOperationInterruptedException) { Logger.Warn("Scan cancelled by user"); TheActionList.Clear(); LastScanComplete = false; } catch (Exception e) { Logger.Fatal(e, "Unhandled Exception in ScanWorker"); LastScanComplete = false; } finally { scanProgDlg?.Done(); } }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { returnActions.Clear(); showList = MDoc.TvLibrary.GetSortedShowItems(); //We ignore the current set of shows being scanned to be secrure that no files are deleted for unscanned shows movieList = MDoc.FilmLibrary.GetSortedMovies(); currentSettings = settings; //for each directory in settings directory //for each file in directory //for each saved show (order by recent) //is file already available? //if so add show to list of files to be removed int totalDownloadFolders = TVSettings.Instance.DownloadFolders.Count; int c = 0; foreach (string dirPath in TVSettings.Instance.DownloadFolders.ToList()) { UpdateStatus(c++, totalDownloadFolders, dirPath); if (!Directory.Exists(dirPath) || currentSettings.Token.IsCancellationRequested) { continue; } filesThatMayBeNeeded = new List <FileInfo>(); ReviewFilesInDownloadDirectory(dirPath, settings.Owner); ReviewDirsInDownloadDirectory(dirPath); } ItemList removeActions = new ItemList(); //Remove any missing items we are planning to resolve foreach (ActionCopyMoveRename acmr in returnActions.OfType <ActionCopyMoveRename>()) { removeActions.AddRange(MDoc.TheActionList.MissingEpisodes.Where(missingItem => missingItem.Episode == acmr.Episode)); removeActions.AddRange(MDoc.TheActionList.MissingMovies.Where(missingItem => missingItem.Movie == acmr.Movie)); } MDoc.TheActionList.Replace(removeActions, returnActions); }