private void CheckMovieFolder(MovieConfiguration si, DirFilesCache dfc, TVDoc.ScanSettings settings, string folder) { if (settings.Token.IsCancellationRequested) { return; } FileInfo[] files = dfc.GetFiles(folder); bool renCheck = TVSettings.Instance.RenameCheck && si.DoRename && Directory.Exists(folder); // renaming check needs the folder to exist bool missCheck = TVSettings.Instance.MissingCheck && si.DoMissingCheck; if (!renCheck && !missCheck) { return; } FileInfo[] movieFiles = files.Where(f => f.IsMovieFile()).ToArray(); if (movieFiles.Length == 0) { FileIsMissing(si, folder, missCheck); return; } if (settings.Token.IsCancellationRequested) { return; } List <string> bases = movieFiles.Select(GetBase).Distinct().ToList(); string newBase = TVSettings.Instance.FilenameFriendly(CustomMovieName.NameFor(si, TVSettings.Instance.MovieFilenameFormat)); if (bases.Count == 1 && bases[0].Equals(newBase)) { //All Seems OK //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that //it has all the required files for that show Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, movieFiles.First(m => m.Name.StartsWith(newBase, StringComparison.Ordinal)))); return; } if (renCheck && bases.Count == 1 && !bases[0].Equals(newBase, StringComparison.CurrentCultureIgnoreCase)) { foreach (FileInfo fi in files) { if (settings.Token.IsCancellationRequested) { return; } string baseString = bases[0]; if (fi.Name.StartsWith(baseString, StringComparison.CurrentCultureIgnoreCase)) { string newName = fi.Name.Replace(baseString, newBase); FileInfo newFile = FileHelper.FileInFolder(folder, newName); // rename updates the filename if (newFile.IsMovieFile()) { //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that //it has all the required files for that show Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, newFile)); } if (newFile.FullName != fi.FullName) { //Check that the file does not already exist //if (FileHelper.FileExistsCaseSensitive(newFile.FullName)) if (FileHelper.FileExistsCaseSensitive(files, newFile)) { LOGGER.Warn( $"Identified that {fi.FullName} should be renamed to {newName}, but it already exists."); } else { LOGGER.Info($"Identified that {fi.FullName} should be renamed to {newName}."); Doc.TheActionList.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.rename, fi, newFile, si, false, null, Doc)); //The following section informs the DownloadIdentifers that we already plan to //copy a file in the appropriate place and they do not need to worry about downloading //one for that purpose downloadIdentifiers.NotifyComplete(newFile); } } else { if (fi.IsMovieFile()) { //File is correct name LOGGER.Debug($"Identified that {fi.FullName} is in the right place. Marking it as 'seen'."); //Record this movie as seen TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si); if (TVSettings.Instance.IgnorePreviouslySeenMovies) { Doc.SetDirty(); } } } } } // foreach file in folder } else { if (movieFiles.First().IsMovieFile()) { //File is correct name LOGGER.Debug($"Identified that {movieFiles.First().FullName} is in the right place. Marking it as 'seen'."); //Record this movie as seen TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si); if (TVSettings.Instance.IgnorePreviouslySeenMovies) { Doc.SetDirty(); } } } }
protected bool ReviewFile(MovieItemMissing me, ItemList addTo, FileInfo dce, TVDoc.ScanSettings settings, bool preventMove, bool doExtraFiles, bool useFullPath) { if (settings.Token.IsCancellationRequested) { return(false); } bool matched = false; try { if (dce.IgnoreFile() || me.Movie is null) { return(false); } //do any of the possible names for the cachedSeries match the filename? matched = me.Show.NameMatch(dce, useFullPath); if (!matched) { return(false); } if (me.Show.LengthNameMatch(dce, useFullPath) != MDoc.FilmLibrary.Movies.MaxOrDefault(m => m.LengthNameMatch(dce, useFullPath), 0)) { int c = 1; return(false); } FileInfo fi = FinderHelper.GenerateTargetName(me, dce); if (preventMove) { //We do not want to move the file, just rename it fi = new FileInfo(dce.DirectoryName.EnsureEndsWithSeparator() + me.Filename + dce.Extension); } if (dce.FullName != fi.FullName && !FindExistingActionFor(addTo, dce)) { // don't remove the base search folders bool doTidyup = !TVSettings.Instance.DownloadFolders.Any(folder => folder.SameDirectoryLocation(fi.Directory.FullName)); addTo.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.copy, dce, fi, me.Movie, doTidyup, me, MDoc)); } if (doExtraFiles) { DownloadIdentifiersController di = new DownloadIdentifiersController(); // if we're copying/moving a file across, we might also want to make a thumbnail or NFO for it addTo.Add(di.ProcessMovie(me.MovieConfig, fi)); } return(true); } catch (PathTooLongException e) { WarnPathTooLong(me, dce, e, matched); } return(false); }