示例#1
0
        public void RefreshFolder()
        {
            if (TB_FolderPath.Text == "")
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            ClearFiles();

            try
            {
                BlackList = NameExtractor.PreBlackList;
                if (File.Exists("RenamerBlackList.txt"))
                {
                    var pb = new List <string>();
                    foreach (var item in File.ReadAllLines("RenamerBlackList.txt"))
                    {
                        if (!BlackList.Contains(item))
                        {
                            pb.Add(Regex.Escape(item));
                        }
                    }
                    BlackList = FormatBlackList(BlackList.Union(pb).ToArray());
                }
                else
                {
                    File.WriteAllText("RenamerBlackList.txt", "");
                }
            }
            catch (Exception) { BlackList = FormatBlackList(NameExtractor.PreBlackList); }

            try
            {
                var Files      = new List <string>();
                var VideoFiles = new List <string>();

                foreach (var item in Directory.EnumerateFiles(TB_FolderPath.Text, "*.*", SearchOption.AllDirectories))
                {
                    if (IsVideoFile(item) && (MovieMode || Episode.PathIsValid(item)))
                    {
                        VideoFiles.Add(item);
                        if (VideoFiles.Count > 650)
                        {
                            throw new StackOverflowException("File Count exceeded Limit");
                        }
                    }
                    else
                    {
                        Files.Add(item);
                    }
                }

                if (MovieMode) // Movie Mode
                {
                    foreach (var Video in VideoFiles)
                    {
                        Movies.Add(new Movie(Video));
                    }

                    L_SeasonCount.Text = Movies.Count.ToString();

                    foreach (var Movie in Movies.OrderByDescending(x => x.Name))
                    {
                        Movie.Control = new MovieControl(Movie)
                        {
                            Dock = DockStyle.Top
                        };
                        Form1.reviewSubForm.P_Main.Controls.Add(Movie.Control);
                        Movie.Control.Show();
                    }
                }
                else // Series Mode
                {
                    var Episodes = new List <Episode>();
                    foreach (var item in VideoFiles)
                    {
                        Episodes.Add(new Episode(item));
                    }
                    foreach (var SNumber in Season.GetSeasons(Episodes))
                    {
                        Seasons.Add(new Season(SNumber, Episodes.Where(x => x.SeasonNumber == SNumber).ToList()));
                    }

                    L_SeasonCount.Text = Seasons.Count.ToString();
                    L_EpCount.Text     = Episodes.Count.ToString();

                    foreach (var Season in Seasons.OrderByDescending(x => x.SeasonNumber))
                    {
                        Season.Control = new SeasonControl(Season)
                        {
                            Dock = DockStyle.Top
                        };
                        Form1.reviewSubForm.P_Main.Controls.Add(Season.Control);
                        Season.Control.Show();
                    }
                }

                if (O_IncludeSubs)
                {
                    AddSubtitles();
                }

                JunkFiles = Files.Where(f => Movies.All(m => m.FilePath != f && m.Subs.All(s => s.FilePath != f)) &&
                                        Seasons.All(S => S.Episodes.All(e => e.FilePath != f && e.Subs.All(sub => sub.FilePath != f))) &&
                                        !(new FileInfo(f).Attributes.HasFlag(FileAttributes.Hidden))).ToList();

                if (!O_IncludeSubs)
                {
                    JunkFiles.RemoveAll(x => x.EndsWith(".srt"));
                }

                L_SeasonCount.ForeColor = L_EpCount.ForeColor = L_SubCount.ForeColor = FormState.N_Focused.Color;
                CurrentFormState        = GetFormState();
            }
            catch (Exception ex)
            {
                ClearFiles();
                Form1.ShowError(ex.Message);
                L_SeasonCount.Text      = L_EpCount.Text = L_SubCount.Text = "0";
                L_SeasonCount.ForeColor = L_EpCount.ForeColor = L_SubCount.ForeColor = Color.FromArgb(242, 60, 53);
                Clipboard.SetText(ex.ToString());
                CurrentFormState = FormState.Busy;
            }
            Cursor.Current = Cursors.Default;
        }