コード例 #1
0
        protected override void DoLoad(string file)
        {
            //using (FileStream fs = new FileStream(_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (StreamReader sr = new StreamReader(_file, Encoding.Default, true))
            {
                while (!sr.EndOfStream)
                {
                    lineIndex = 0;
                    SubtitleElement se = new SubtitleElement();
                    _sub.Elements.Add(se);

                    try
                    {
                        for (; ; )
                        {
                            try
                            {
                                string s = sr.ReadLine();
                                if (ProcessLine(se, s))
                                    break;
                            }
                            catch (IOException)
                            {
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
コード例 #2
0
        protected override void DoLoad(string file)
        {
            //using (FileStream fs = new FileStream(_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (StreamReader sr = new StreamReader(_file, Encoding.Default, true))
            {
                while (!sr.EndOfStream)
                {
                    lineIndex = 0;
                    SubtitleElement se = new SubtitleElement();
                    _sub.Elements.Add(se);

                    try
                    {
                        for (; ;)
                        {
                            try
                            {
                                string s = sr.ReadLine();
                                if (ProcessLine(se, s))
                                {
                                    break;
                                }
                            }
                            catch (IOException)
                            {
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
コード例 #3
0
        private bool ProcessLine(SubtitleElement se, string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }

            if (lineIndex == 0)
            {
                // Subtitles are numbered sequentially, starting at 1
                // If not, format is invalid
                int i = int.Parse(s);
            }
            else if (lineIndex == 1)
            {
                // The time format used is hours:minutes:seconds,milliseconds

                s = s.Replace("-->", "|");
                string[] fields = s.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (fields.Length != 2)
                {
                    throw new FormatException();
                }

                se.StartTime = TimeSpan.Parse(fields[0].Trim().Replace(",", "."));
                se.EndTime   = TimeSpan.Parse(fields[1].Trim().Replace(",", "."));

                if (_sub.VideoFileInfo != null && _sub.VideoFileInfo.IsValid)
                {
                    double fps = _sub.VideoFileInfo.FrameRate.GetValueOrDefault().Value;
                    se.StartFrames = (int)(fps * se.StartTime.TotalSeconds);
                    se.EndFrames   = (int)(fps * se.EndTime.TotalSeconds);
                }
            }
            else if (lineIndex > 1)
            {
                se.Lines.Add(StringUtils.FixDiacriticals(s));
            }

            lineIndex++;
            return(false);
        }
コード例 #4
0
        private bool ProcessLine(SubtitleElement se, string s)
        {
            if (string.IsNullOrEmpty(s))
                return true;

            if (lineIndex == 0)
            {
                // Subtitles are numbered sequentially, starting at 1
                // If not, format is invalid
                int i = int.Parse(s);
            }
            else if (lineIndex == 1)
            {
                // The time format used is hours:minutes:seconds,milliseconds

                s = s.Replace("-->", "|");
                string[] fields = s.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (fields.Length != 2)
                    throw new FormatException();

                se.StartTime = TimeSpan.Parse(fields[0].Trim().Replace(",", "."));
                se.EndTime = TimeSpan.Parse(fields[1].Trim().Replace(",", "."));

                if (_sub.VideoFileInfo != null && _sub.VideoFileInfo.IsValid)
                {
                    double fps = _sub.VideoFileInfo.FrameRate.GetValueOrDefault().Value;
                    se.StartFrames = (int)(fps * se.StartTime.TotalSeconds);
                    se.EndFrames = (int)(fps * se.EndTime.TotalSeconds);
                }
            }
            else if (lineIndex > 1)
            {
                se.Lines.Add(StringUtils.FixDiacriticals(s));
            }

            lineIndex++;
            return false;
        }
コード例 #5
0
ファイル: AddonPanel.cs プロジェクト: rraguso/protone-suite
        public override void ShowProperties(List<string> strItems, object additionalData)
        {
            Translator.TranslateControl(this, DesignMode);

            try
            {
                tbContents.TextChanged -= new EventHandler(OnContentsChanged);
                tpStartTime.OnValueChanged -= new EventHandler(OnStartTimeChanged);
                tpEndTime.OnValueChanged -= new EventHandler(OnEndTimeChanged);
                tpDuration.OnValueChanged -= new EventHandler(OnDurationChanged);

                _elem = additionalData as SubtitleElement;
                if (_elem != null)
                {
                    tpStartTime.Value = _elem.StartTime;
                    tpEndTime.Value = _elem.EndTime;
                    tpDuration.Value = (_elem.EndTime.Subtract(_elem.StartTime));

                    string rtf = _elem.RtfDisplay;
                    try
                    {
                        rtbContents.Rtf = rtf;
                    }
                    catch
                    {
                        rtbContents.Text = rtf;
                    }

                    tbContents.Lines = _elem.Lines.ToArray();
                }
            }
            finally
            {
                tbContents.TextChanged += new EventHandler(OnContentsChanged);
                tpStartTime.OnValueChanged += new EventHandler(OnStartTimeChanged);
                tpEndTime.OnValueChanged += new EventHandler(OnEndTimeChanged);
                tpDuration.OnValueChanged += new EventHandler(OnDurationChanged);

                base.Modified = false;
                btnSave.Enabled = btnUndo.Enabled = false;
            }
        }