Beispiel #1
0
        private void ProcessFile()
        {
            string[] allLines = File.ReadAllLines(FilePath);

            var   i            = 0;
            Regex indexRegex   = new Regex(@"(\d+)");
            Regex timingsRegex = new Regex(@"(\d+):(\d+):(\d+),*(\d*)\s*-->\s*(\d+):(\d+):(\d+),*(\d*)");

            while (i < allLines.Length)
            {
                if (!string.IsNullOrEmpty(allLines[i]))
                {
                    SubtitlePart part = new SubtitlePart(this);

                    //Read Index
                    Match indexMatch = indexRegex.Match(allLines[i]);
                    if (indexMatch != null && indexMatch.Success)
                    {
                        if (indexMatch.Groups.Count > 0)
                        {
                            if (indexMatch.Groups[0].Success)
                            {
                                part.Index = indexMatch.Groups[0].Value;
                            }
                        }
                    }

                    i++;

                    //Read Timings
                    if (!string.IsNullOrEmpty(allLines[i]))
                    {
                        Match timingsMatch = timingsRegex.Match(allLines[i]);

                        if (timingsMatch != null && timingsMatch.Success)
                        {
                            if (timingsMatch.Groups.Count >= 9)
                            {
                                part.PopulateTiming(timingsMatch.Groups);
                            }
                        }
                    }

                    i++;


                    //Read Content (multiple lines)

                    while (i < allLines.Length && !string.IsNullOrEmpty(allLines[i]))
                    {
                        var line = allLines[i].TrimEnd();
                        part.AddContentLine(MainWindowVM.ReplaceProfanePhrases(line));
                        i++;
                    }

                    part.SerialNumber = AllParts.Count + 1;

                    //Add the part
                    AllParts.Add(part);
                }

                i++; //Added for empty lines
            }
        }
 public void ShowEditSubtitleFlyout(SubtitlePart part)
 {
     //SubtitleEditorFlyout.DataContext = part;
     SubtitleEditorFlyout.IsOpen = true;
 }