예제 #1
0
        private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            EpisodeEntry entry = episodes[e.RowIndex] as EpisodeEntry;

            if (entry == null)
            {
                return;
            }

            // Determine whether the cell should be painted
            // with the custom foreground.
            if ((entry.GetEntryType() != EpisodeEntry.EntryType.None) && !entry.Enabled)
            {
                // Calculate the bounds of the row.
                Rectangle rowBounds = new Rectangle(
                    0,
                    e.RowBounds.Top,
                    dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dataGridView.HorizontalScrollingOffset + 1,
                    e.RowBounds.Height);

                Color c1 = Color.FromArgb(160, Color.Gray);
                Color c2 = Color.FromArgb(200, Color.Gray);
                Brush br = new HatchBrush(HatchStyle.Weave, c2, c1);
                e.Graphics.FillRectangle(br, rowBounds);
            }
        }
예제 #2
0
        // dataGridView
        private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            EpisodeEntry entry = episodes[e.RowIndex] as EpisodeEntry;

            if (entry == null)
            {
                return;
            }

            e.PaintParts &= ~DataGridViewPaintParts.Background;

            // Determine whether the cell should be painted
            // with the custom background.
            if (entry.GetEntryType() != EpisodeEntry.EntryType.None)
            {
                // Calculate the bounds of the row.
                Rectangle rowBounds = new Rectangle(
                    0,
                    e.RowBounds.Top,
                    dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dataGridView.HorizontalScrollingOffset + 1,
                    e.RowBounds.Height);

                // Paint the custom background.
                Color color;
                switch (entry.GetEntryType())
                {
                case EpisodeEntry.EntryType.Green:
                    color = Color.Green;
                    break;

                case EpisodeEntry.EntryType.Red:
                    color = Color.Red;
                    break;

                case EpisodeEntry.EntryType.Yellow:
                    color = Color.Yellow;
                    dataGridView.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Red;
                    break;

                case EpisodeEntry.EntryType.Gray:
                    color = Color.LightGray;
                    break;

                case EpisodeEntry.EntryType.Blue:
                    color = Color.LightBlue;
                    break;

                default:
                    color = Color.Cyan;
                    break;
                }

                e.Graphics.FillRectangle(new SolidBrush(color), rowBounds);
            }
        }
예제 #3
0
        bool ReadFiles(string path)
        {
            Trace.WriteLine("ReadFiles called: " + path);
            string[] files;

            try {
                files = Directory.GetFiles(path);
                Array.Sort <string>(files);
                folderName = Path.GetFileName(Path.GetFullPath(path));
            } catch (Exception ex) {
                Trace.WriteLine("Exception (" + ex.GetType() + ") in ReadFiles: list directory.");
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);

                return(false);
            }
            Trace.Indent();
            Trace.WriteLine("Directory Listing successful, number of files: " + files.Length);

            foreach (string item in files)
            {
                if (Path.GetExtension(item) != "")
                {
                    // Filter unwanted extensions
                    if (Array.Exists <Regex>(blacklistFilters, (Regex r) => r.IsMatch(item)))
                    {
                        continue;
                    }
                    // Filter sample files, if activated
                    string name = Path.GetFileName(item);
                    if (chkIgnoreSample.Checked && sample.IsMatch(name))
                    {
                        ignoredFiles.AddLast(name);
                        continue;
                    }

                    Trace.WriteLine(item);
                    Trace.Indent();

                    EpisodeEntry ep = new EpisodeEntry(item);
                    Trace.WriteLine("Series: " + ep.Series);
                    Trace.WriteLine("EpisodeNumber: " + ep.EpisodeNumber);

                    Trace.Unindent();
                    episodes.Add(ep);
                }
            }

            Trace.WriteLine("ReadFiles finished.");
            Trace.Unindent();
            btnReadNames.Enabled    = true;
            linkShowIgnored.Visible = (ignoredFiles.First != null);
            return(true);
        }
예제 #4
0
        void ExtractEpisodeInformation(string line, out int season, out int episode, out string name)
        {
            season  = -1;
            episode = -1;
            name    = "";

            // Matches IMDb syntax
            if (Regex.IsMatch(line, @"Season [0-9]+, Episode [0-9]+.*", EpisodeEntry.DefaultRegexOptions))
            {
                Match mSeason  = Regex.Match(line, @"(?<=Season )[0-9]+", EpisodeEntry.DefaultRegexOptions);
                Match mEpisode = Regex.Match(line, @"(?<=Episode )[0-9]+", EpisodeEntry.DefaultRegexOptions);

                if (mSeason.Success && mEpisode.Success)
                {
                    try {
                        season  = int.Parse(mSeason.Value);
                        episode = int.Parse(mEpisode.Value);
                    } catch (FormatException ex) {
                        Trace.WriteLine("FormatException in ExtractEpisodeInformation: IMDb syntax season and episode match.");
                        Trace.WriteLine(ex.Message);

                        season  = -1;
                        episode = -1;
                    }
                }

                Match m = Regex.Match(line, "(?<=: ).*");
                if (m.Success)
                {
                    name = m.Value;
                }
            }             // Matches TheTVDB syntax
            else if (Regex.IsMatch(line, @"^[0-9]+ x [0-9]+\t.*", EpisodeEntry.DefaultRegexOptions))
            {
                Match mSeason  = Regex.Match(line, @"^[0-9]+", EpisodeEntry.DefaultRegexOptions);
                Match mEpisode = Regex.Match(line, @"(?<= x )[0-9]+", EpisodeEntry.DefaultRegexOptions);

                if (mSeason.Success && mEpisode.Success)
                {
                    try {
                        season  = int.Parse(mSeason.Value);
                        episode = int.Parse(mEpisode.Value);
                    } catch (FormatException ex) {
                        Trace.WriteLine("FormatException in ExtractEpisodeInformation: TheTVDB syntax season and episode match.");
                        Trace.WriteLine(ex.Message);

                        season  = -1;
                        episode = -1;
                    }
                }

                Match m = Regex.Match(line, @"(?<=[0-9]+ x [0-9]+\t)[^\t\n]+");
                if (m.Success)
                {
                    name = m.Value;
                }
            }             // Matches old TheTVDB syntax
            else if (Regex.IsMatch(line, @"^[0-9]+ - [0-9]+\t.*", EpisodeEntry.DefaultRegexOptions))
            {
                Match mSeason  = Regex.Match(line, @"^[0-9]+", EpisodeEntry.DefaultRegexOptions);
                Match mEpisode = Regex.Match(line, @"(?<= - )[0-9]+", EpisodeEntry.DefaultRegexOptions);

                if (mSeason.Success && mEpisode.Success)
                {
                    try {
                        season  = int.Parse(mSeason.Value);
                        episode = int.Parse(mEpisode.Value);
                    } catch (FormatException ex) {
                        Trace.WriteLine("FormatException in ExtractEpisodeInformation: old TheTVDB syntax season and episode match.");
                        Trace.WriteLine(ex.Message);

                        season  = -1;
                        episode = -1;
                    }
                }

                Match m = Regex.Match(line, @"(?<=[0-9]+ - [0-9]+\t)[^\t\n]+");
                if (m.Success)
                {
                    name = m.Value;
                }
            }             // Matches generic syntax
            else
            {
                Match m = Regex.Match(line, EpisodeEntry.RegexEpisodeNumberMatchString, EpisodeEntry.DefaultRegexOptions);

                if (m.Success)
                {
                    // If episode information is found, extract it
                    Point p = EpisodeEntry.GetEpisodeInfo(m.Value);
                    season  = p.X;
                    episode = p.Y;

                    if (m.Index + m.Length < line.Length)
                    {
                        name = line.Substring(m.Index + m.Length);
                    }
                    else if (line.Length - m.Length > 0)
                    {
                        name = line.Substring(0, line.Length - m.Length);
                    }
                    else
                    {
                        name = "";
                    }
                }
                else
                {
                    // No episode information found, so use the whole line as name and guess the numbers
                    name = line;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Matches the episode names in <paramref name="lines"/> to <see cref="EpisodeEntry"/> objects in <see cref="episodes"/>
        /// </summary>
        /// <param name="lines">The lines to match</param>
        /// <returns><value>false</value> in case <paramref name="lines"/> is <value>null</value> or empty, otherwise true.</returns>
        bool ReadNames(string[] lines)
        {
            int count = 0;

            if ((lines == null) || (lines.Length < 1))
            {
                return(false);
            }

            Regex post = null;

            if (chkPostReplace.Checked)
            {
                try {
                    post = new Regex(txtSearch.Text, chkIgnoreCase.Checked ? RegexOptions.IgnoreCase : RegexOptions.None);
                } catch (ArgumentException ex) {
                    Trace.WriteLine("ArgumentException in ReadNames: Regex constructor");
                    Trace.WriteLine(ex.Message);

                    post = null;
                }
            }

            foreach (string line in lines)
            {
                int    season;
                int    episode;
                string name;

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                if (count >= episodes.Count)
                {
                    break;
                }

                // Extract season number, episode number and episode name from line
                ExtractEpisodeInformation(line, out season, out episode, out name);

                // No name, continue with next line
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                // Either IMDb or generic syntax matched the line and at least an episode name could be extracted
                // so search for the corresponding EpisodeEntry and save the data

                EpisodeEntry e = null;
                Point        p;

                // Only episode name
                if (season < 0 || episode < 0)
                {
                    // No episode numbers, so take the next element in the list
                    e = (EpisodeEntry)episodes[count];

                    // If the episode information is set in the EpisodEentry object, take that one, otherwise guess
                    p = new Point(
                        e.EpisodeNumber.X,
                        e.EpisodeNumber.Y < 0 ? count : e.EpisodeNumber.Y);
                }                 // Episode name and numbers
                else
                {
                    p = new Point(season, episode);

                    // Find the EpisodeEntry corresponding to the episode number extracted
                    foreach (object o in episodes)
                    {
                        EpisodeEntry tmp = (EpisodeEntry)o;

                        if (tmp.EpisodeNumber == p)
                        {
                            e = tmp;
                            break;
                        }
                    }

                    // Episode not found, continue with next line
                    if (e == null)
                    {
                        continue;
                    }
                }

                if (chkUseFolderName.Checked)
                {
                    e.Series = folderName;
                }
                else
                {
                    e.ResetSeries();
                }

                e.NewNameString = line.Trim();
                e.NewFilename   = EpisodeEntry.FormatFilename(e.Series, p, name, Path.GetExtension(e.OldFilename));

                try {
                    if (post != null)
                    {
                        e.NewFilename = post.Replace(e.NewFilename, txtReplace.Text);
                    }
                } catch (Exception ex) {
                    Trace.WriteLine("Exception (" + ex.GetType() + ") in ReadNames: regex replace.");
                    Trace.WriteLine(ex.Message);
                    Trace.WriteLine(ex.StackTrace);

                    post = null;
                }

                e.Enabled = (e.GetEntryType() != EpisodeEntry.EntryType.Yellow);
                count++;
            }

            UpdateGridView();
            return(count > 0);
        }