Exemplo n.º 1
0
        private void ImportAndOcrSpDvdSup(string fileName, bool showInTaskbar)
        {
            var spList = new List<SpHeader>();

            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var buffer = new byte[SpHeader.SpHeaderLength];
                int bytesRead = fs.Read(buffer, 0, buffer.Length);
                var header = new SpHeader(buffer);

                while (header.Identifier == "SP" && bytesRead > 0 && header.NextBlockPosition > 4)
                {
                    buffer = new byte[header.NextBlockPosition];
                    bytesRead = fs.Read(buffer, 0, buffer.Length);
                    if (bytesRead == buffer.Length)
                    {
                        header.AddPicture(buffer);
                        spList.Add(header);
                    }

                    buffer = new byte[SpHeader.SpHeaderLength];
                    bytesRead = fs.Read(buffer, 0, buffer.Length);
                    header = new SpHeader(buffer);
                }
            }

            using (var vobSubOcr = new VobSubOcr())
            {
                if (showInTaskbar)
                {
                    vobSubOcr.Icon = (Icon)this.Icon.Clone();
                    vobSubOcr.ShowInTaskbar = true;
                    vobSubOcr.ShowIcon = true;
                }
                vobSubOcr.Initialize(fileName, null, Configuration.Settings.VobSubOcr, spList);
                if (vobSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingVobSubFile);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in vobSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    _subtitleListViewIndex = -1;
                    SubtitleListview1.FirstVisibleIndex = -1;
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    _fileName = Path.ChangeExtension(vobSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;

                    Configuration.Settings.Save();
                }
            }
        }
Exemplo n.º 2
0
        public static bool IsSpDvdSup(string fileName)
        {
            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var buffer = new byte[SpHeader.SpHeaderLength];
                if (fs.Read(buffer, 0, buffer.Length) != buffer.Length)
                {
                    return false;
                }

                var header = new SpHeader(buffer);
                if (header.Identifier != "SP" || header.NextBlockPosition < 5)
                {
                    return false;
                }

                buffer = new byte[header.NextBlockPosition];
                if (fs.Read(buffer, 0, buffer.Length) != buffer.Length)
                {
                    return false;
                }

                buffer = new byte[SpHeader.SpHeaderLength];
                if (fs.Read(buffer, 0, buffer.Length) != buffer.Length)
                {
                    return false;
                }

                header = new SpHeader(buffer);
                return header.Identifier == "SP";
            }
        }