private void ReviewFilesInDownloadDirectory(string dirPath, IDialogParent owner)
        {
            try
            {
                foreach (string filePath in Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories).Where(File.Exists))
                {
                    if (currentSettings.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    FileInfo fi = new FileInfo(filePath);

                    if (fi.IgnoreFile())
                    {
                        continue;
                    }

                    List <ShowConfiguration> matchingShows        = showList.Where(si => si.NameMatch(fi, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();
                    List <ShowConfiguration> matchingShowsNoDupes = RemoveShortShows(matchingShows);
                    if (matchingShowsNoDupes.Any())
                    {
                        ReviewFileInDownloadDirectory(currentSettings.Unattended, fi, matchingShowsNoDupes, owner);
                    }

                    List <MovieConfiguration> matchingMovies        = movieList.Where(mi => mi.NameMatch(fi, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();
                    List <MovieConfiguration> matchingNoDupesMovies = RemoveShortShows(matchingMovies);
                    if (matchingNoDupesMovies.Any())
                    {
                        ReviewFileInDownloadDirectory(currentSettings.Unattended, fi, matchingNoDupesMovies, owner);
                    }
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                LOGGER.Warn(ex, $"Could not access files in {dirPath}");
            }
            catch (DirectoryNotFoundException ex)
            {
                LOGGER.Warn(ex, $"Could not access files in {dirPath}");
            }
            catch (IOException ex)
            {
                LOGGER.Warn(ex, $"Could not access files in {dirPath}");
            }
        }
Example #2
0
        // ReSharper disable once FunctionComplexityOverflow
        protected bool ReviewFile(ItemMissing me, ItemList addTo, FileInfo dce, TVDoc.ScanSettings settings, bool addMergeRules, bool preventMove, bool doExtraFiles, bool useFullPath)
        {
            if (settings.Token.IsCancellationRequested)
            {
                return(false);
            }

            bool matched = false;

            try
            {
                if (dce.IgnoreFile())
                {
                    return(false);
                }

                //do any of the possible names for the series match the filename?
                matched = me.Episode.Show.NameMatch(dce, useFullPath);

                if (!matched)
                {
                    return(false);
                }

                (bool identifySuccess, int seasF, int epF, int maxEp) = IdentifyFile(me, dce);

                if (!identifySuccess)
                {
                    return(false);
                }

                if (maxEp != -1 && addMergeRules)
                {
                    me = UpdateMissingItem(me, dce, epF, maxEp, seasF);
                }

                FileInfo fi = new FileInfo(me.TheFileNoExt + dce.Extension);

                if (preventMove)
                {
                    //We do not want to move the file, just rename it
                    fi = new FileInfo(dce.DirectoryName + Path.DirectorySeparatorChar + 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.Episode, 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.ProcessEpisode(me.Episode, fi));
                }

                return(true);
            }
            catch (PathTooLongException e)
            {
                WarnPathTooLong(me, dce, e, matched);
            }
            return(false);
        }
Example #3
0
        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);
        }