Пример #1
0
 private void BtnClearCheckFilesRtb_Click(object sender, EventArgs e)
 {
     RtbCheckFiles.Clear();
 }
Пример #2
0
        private void BtnCheckFiles_Click(object sender, EventArgs e)
        {
            RtbCheckFiles.Clear();
            //will check 2 directories and their subdirectories

            string InvalidSeasonName  = null;
            bool   WasThereAnyInvalid = false;

            string root = @"D:\AN\Anime";

            string[] subdirectoryEntriesEntry = Directory.GetDirectories(root);

            // Loop through them to see if they have any other subdirectories
            foreach (string subdirectory in subdirectoryEntriesEntry)
            {
                LoadSubDirs(subdirectory);
            }

            // Get all subdirectories
            root = @"D:\AN\Anime not";
            subdirectoryEntriesEntry = Directory.GetDirectories(root);

            // Loop through them to see if they have any other subdirectories
            foreach (string subdirectory in subdirectoryEntriesEntry)
            {
                LoadSubDirs(subdirectory);
            }

            if (WasThereAnyInvalid)
            {
                AppendColoredTextToRtb(RtbCheckFiles, "\nProblem\n" + InvalidSeasonName + Environment.NewLine, alertColor);
            }
            else
            {
                AppendColoredTextToRtb(RtbCheckFiles, "\nEverything is ok\n", approveColor);
            }

            void LoadSubDirs(string dir)
            {
                RtbCheckFiles.AppendText(dir + Environment.NewLine);//display current location

                bool   IsfirstTime = true;
                string filterPath  = dir + '\\' + "Plex Versions";

                string[] subdirectoryEntries = Directory.GetDirectories(dir);

                /*
                 *      only check the episodes if it's the last folder inside a folder
                 *      and you can change to not enter the folder named "Plex Versions"
                 */

                if (subdirectoryEntries.Length < 1) // add || filterPath == subdirectoryEntries[0] to if to filter folder
                {
                    bool thisTrySucess = true;

                    DirectoryInfo directoryInfo = new DirectoryInfo(dir);
                    FileInfo[]    infos         = directoryInfo.GetFiles();

                    foreach (FileInfo fileInfo in infos)
                    {
                        string seriesName       = fileInfo.Directory.Parent.Name + " - ";
                        string inFileSeriesName = fileInfo.Name.Split(' ')[0] + " - ";

                        string[] seasonArray = fileInfo.Directory.Name.Split(' ');
                        string   season      = "random";//this will change if needed in the next if
                        if (seasonArray.Length > 1)
                        {
                            season = seasonArray[1];
                        }

                        if (!IsVaild(Path.GetFileNameWithoutExtension(fileInfo.FullName), fileInfo.Name, fileInfo.Extension, season, seriesName))
                        {
                            AppendColoredTextToRtb(RtbCheckFiles, "Found a problem at:" + fileInfo.DirectoryName + "problem name: " + fileInfo.Name + Environment.NewLine, alertColor);
                            WasThereAnyInvalid = true;
                            if (IsfirstTime)
                            {
                                IsfirstTime        = false;
                                InvalidSeasonName += fileInfo.DirectoryName + Environment.NewLine + Environment.NewLine;
                            }
                        }
                    }
                    if (thisTrySucess)
                    {
                        AppendColoredTextToRtb(RtbCheckFiles, "Passed\n", approveColor);
                    }
                }
                else
                {
                    // don't enter the "Plex Versions" folder
                    //if (filterPath != subdirectoryEntries[0]) <-- uncomment this to not enter "Plex Versions" folder
                    foreach (string subdirectory in subdirectoryEntries)
                    {
                        LoadSubDirs(subdirectory);
                    }
                }
            }

            bool IsVaild(string NameNoType, string name, string type, string Season, string SeriesName)
            {
                if (IsFileFilter(name))
                {
                    return(true);
                }

                int num = GetNumberOutOfString(name, type, false);

                //check if Season is a number
                bool bNum = int.TryParse(Season, out int i);

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

                //check if name format is correct like this --> SeriesName - S SeasonNumber E EpisodeNumber ---> example: SeriesName - S01E01
                if (Convert.ToInt32(Season) / 10 == 0)
                {
                    //episode is less then 10 -> there is a need for "0 helper"
                    if (num / 10 == 0)
                    {
                        return(IsFormatCorrect(NameNoType, SeriesName, Season, num, "E0"));
                    }

                    //episode is more then 10 -> there is no need for "0 helper"
                    else
                    {
                        return(IsFormatCorrect(NameNoType, SeriesName, Season, num, "E"));
                    }
                }
                else
                {
                    //episode is less then 10 -> there is a need for "0 helper"
                    //"0 helper" is the 0 before the episode or the season if needed
                    if (num / 10 == 0)
                    {
                        if (NameNoType == SeriesName + "S" + Season + "E0" + num)
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E0" + (num - 1) + "-" + "E0" + num)//more then 1 episode in a video
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E0" + num + " - part1")
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E0" + num + " - part2")
                        {
                            return(true);
                        }
                    }
                    //episode is more then 10 -> there is no need for "0 helper"
                    else
                    {
                        if (NameNoType == SeriesName + "S" + Season + "E" + num)
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E" + (num - 1) + "-" + "E" + num)//more then 1 episode in a video
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E" + num + " - part1")
                        {
                            return(true);
                        }
                        if (NameNoType == SeriesName + "S" + Season + "E" + num + " - part2")
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            bool IsFormatCorrect(string NameNoType, string SeriesName, String Season, int num, string EpisodeHolder)
            {
                if (Season == "00")
                {
                    if (NameNoType == SeriesName + "S" + Season + EpisodeHolder + num)
                    {
                        return(true);
                    }
                    if (NameNoType == SeriesName + "S" + Season + EpisodeHolder + num + "-" + EpisodeHolder + (num + 1))//more then 1 episode in a video
                    {
                        return(true);
                    }
                }
                if (NameNoType == SeriesName + "S0" + Season + EpisodeHolder + num)
                {
                    return(true);
                }
                if (NameNoType == SeriesName + "S0" + Season + EpisodeHolder + (num - 1) + "-" + EpisodeHolder + num)//more then 1 episode in a video
                {
                    return(true);
                }

                return(false);
            }
        }