Example #1
0
        /// <summary>
        /// Get a list with the inactive lines removed from each episode.
        /// </summary>
        public List <List <InfoCombined> > removeInactiveLines(WorkerVars workerVars, DialogProgress dialogProgress,
                                                               bool dontRemoveContextLines)
        {
            int totalLines   = 0;
            int progessCount = 0;
            List <List <InfoCombined> > activeLines = new List <List <InfoCombined> >();

            bool subs1ContainsVobsubs = UtilsSubs.filePatternContainsVobsubs(Settings.Instance.Subs[0].FilePattern);
            bool subs2ContainsVobsubs = UtilsSubs.filePatternContainsVobsubs(Settings.Instance.Subs[1].FilePattern);

            foreach (List <InfoCombined> combArray in workerVars.CombinedAll)
            {
                totalLines += combArray.Count;
            }

            // For each episode
            foreach (List <InfoCombined> combArray in workerVars.CombinedAll)
            {
                List <InfoCombined> currentEpisodeActiveLines = new List <InfoCombined>();

                // For each line in episode
                foreach (InfoCombined comb in combArray)
                {
                    progessCount++;

                    if (comb.Active || dontRemoveContextLines && comb.OnlyNeededForContext)
                    {
                        currentEpisodeActiveLines.Add(comb);
                    }
                    else
                    {
                        if (subs1ContainsVobsubs)
                        {
                            try
                            {
                                // Multiple vobsub images can be shown in a single line, so extract each image and delete it
                                List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(comb.Subs1.Text);

                                foreach (string vobsubImage in vobsubImages)
                                {
                                    File.Delete(workerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                                }
                            }
                            catch
                            {
                                // Don't care
                            }
                        }

                        if (subs2ContainsVobsubs)
                        {
                            try
                            {
                                // Multiple vobsub image can be shown in a single line, so extract each image and delete it
                                List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(comb.Subs2.Text);

                                foreach (string vobsubImage in vobsubImages)
                                {
                                    File.Delete(workerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                                }
                            }
                            catch
                            {
                                // Don't care
                            }
                        }
                    }

                    string progressText =
                        $"Remove inactive lines: {Convert.ToInt32(progessCount * (100.0 / totalLines))}%";

                    int progress = Convert.ToInt32(progessCount * (100.0 / totalLines));

                    DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText);

                    if (dialogProgress.Cancel)
                    {
                        return(null);
                    }
                }

                activeLines.Add(currentEpisodeActiveLines);
            }

            return(activeLines);
        }
Example #2
0
        /// <summary>
        /// Update the Subs1 and Subs2 text boxes with the provided combined info.
        /// </summary>
        private void updateTextPreview(InfoCombined selectedComb)
        {
            if (selectedComb == null)
            {
                return;
            }

            if (selectedComb.Active)
            {
                this.textBoxSubs1.BackColor    = activeColor;
                this.textBoxSubs2.BackColor    = activeColor;
                this.pictureBoxSubs1.BackColor = activeColor;
                this.pictureBoxSubs2.BackColor = activeColor;
                this.panelSubs1.BackColor      = activeColor;
                this.panelSubs2.BackColor      = activeColor;
            }
            else
            {
                this.textBoxSubs1.BackColor    = inactiveColor;
                this.textBoxSubs2.BackColor    = inactiveColor;
                this.pictureBoxSubs1.BackColor = inactiveColor;
                this.pictureBoxSubs2.BackColor = inactiveColor;
                this.panelSubs1.BackColor      = inactiveColor;
                this.panelSubs2.BackColor      = inactiveColor;
            }

            // Disable subs2 textbox if there aren't any subs2 files
            this.textBoxSubs2.Enabled    = (Settings.Instance.Subs[1].Files.Length != 0);
            this.pictureBoxSubs2.Enabled = (Settings.Instance.Subs[1].Files.Length != 0);
            this.panelSubs2.Enabled      = (Settings.Instance.Subs[1].Files.Length != 0);

            if (selectedComb.Subs1.Text.EndsWith("png" + ConstantSettings.SrsVobsubFilenameSuffix))
            {
                this.textBoxSubs1.Visible    = false;
                this.pictureBoxSubs1.Visible = true;

                try
                {
                    // Multiple vobsub image can be shown in a single line, so extract each image
                    // and concatenate them before displaying.
                    List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(selectedComb.Subs1.Text);
                    List <Image>  vobSubImages = new List <Image>();

                    foreach (string vobsubImage in vobsubImages)
                    {
                        Image image = UtilsSnapshot.getImageFromFile(previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                        vobSubImages.Add(image);
                    }

                    if (vobSubImages.Count != 0)
                    {
                        Image image;

                        if (vobSubImages.Count == 0)
                        {
                            image = vobSubImages[0];
                        }
                        else
                        {
                            image = UtilsSnapshot.concatImages(vobSubImages);
                        }

                        this.pictureBoxSubs1.Image = image;
                    }
                }
                catch
                {
                    // Don't care
                }
            }
            else
            {
                this.textBoxSubs1.Visible    = true;
                this.pictureBoxSubs1.Visible = false;
                this.textBoxSubs1.Text       = selectedComb.Subs1.Text;
            }

            if (Settings.Instance.Subs[1].Files.Length != 0)
            {
                if (selectedComb.Subs2.Text.EndsWith("png" + ConstantSettings.SrsVobsubFilenameSuffix))
                {
                    this.textBoxSubs2.Visible    = false;
                    this.pictureBoxSubs2.Visible = true;

                    try
                    {
                        // Multiple vobsub image can be shown in a single line, so extract each image
                        // and concatenate them before displaying.
                        List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(selectedComb.Subs2.Text);
                        List <Image>  vobSubImages = new List <Image>();

                        foreach (string vobsubImage in vobsubImages)
                        {
                            Image image = UtilsSnapshot.getImageFromFile(previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                            vobSubImages.Add(image);
                        }

                        if (vobSubImages.Count != 0)
                        {
                            Image image;

                            if (vobSubImages.Count == 0)
                            {
                                image = vobSubImages[0];
                            }
                            else
                            {
                                image = UtilsSnapshot.concatImages(vobSubImages);
                            }

                            this.pictureBoxSubs2.Image = image;
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    this.textBoxSubs2.Visible    = true;
                    this.pictureBoxSubs2.Visible = false;
                    this.textBoxSubs2.Text       = selectedComb.Subs2.Text;
                }
            }
            else
            {
                this.textBoxSubs2.Visible    = true;
                this.pictureBoxSubs2.Visible = false;
                this.textBoxSubs2.Text       = "";
            }
        }
Example #3
0
        /// <summary>
        /// Copy the Vobsub image files from the temporary preview directory to the media directory.
        /// </summary>
        public bool copyVobsubsFromPreviewDirToMediaDir(WorkerVars workerVars, DialogProgress dialogProgress)
        {
            int totalLines   = 0;
            int progessCount = 0;

            bool   subs1ContainsVobsubs = UtilsSubs.filePatternContainsVobsubs(Settings.Instance.Subs[0].FilePattern);
            bool   subs2ContainsVobsubs = UtilsSubs.filePatternContainsVobsubs(Settings.Instance.Subs[1].FilePattern);
            string tempPreviewDir       = Path.GetTempPath() + ConstantSettings.TempPreviewDirName;

            foreach (List <InfoCombined> combArray in workerVars.CombinedAll)
            {
                totalLines += combArray.Count;
            }

            // For each episode
            foreach (List <InfoCombined> combArray in workerVars.CombinedAll)
            {
                // For each line in episode
                foreach (InfoCombined comb in combArray)
                {
                    progessCount++;

                    if (subs1ContainsVobsubs)
                    {
                        try
                        {
                            // Multiple vobsub image can be shown in a single line, so copy each of them
                            List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(comb.Subs1.Text);

                            foreach (string vobsubImage in vobsubImages)
                            {
                                File.Copy(tempPreviewDir + Path.DirectorySeparatorChar + vobsubImage,
                                          workerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                            }
                        }
                        catch
                        {
                            // Don't care
                        }
                    }

                    if (subs2ContainsVobsubs)
                    {
                        try
                        {
                            // Multiple vobsub image can be shown in a single line, so copy each of them
                            List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(comb.Subs2.Text);

                            foreach (string vobsubImage in vobsubImages)
                            {
                                File.Copy(tempPreviewDir + Path.DirectorySeparatorChar + vobsubImage,
                                          workerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                            }
                        }
                        catch
                        {
                            // Don't care
                        }
                    }

                    string progressText =
                        $"Copying vobsubs to .media directory: {Convert.ToInt32(progessCount * (100.0 / totalLines))}%";

                    int progress = Convert.ToInt32(progessCount * (100.0 / totalLines));

                    DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText);

                    if (dialogProgress.Cancel)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }