From a244c8384b87d714d676873d55929cd6236f2fdb Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 5 Jun 2012 12:11:10 +0000 Subject: [PATCH] Display errors in SubRip files after loading (if there were any) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1232 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Controls/VideoPlayerContainer.cs | 7 +++++-- src/Forms/Main.cs | 19 ++++++++++++++++--- src/Logic/Language.cs | 2 ++ src/Logic/LanguageStructure.cs | 3 +++ src/Logic/SubtitleFormats/SubRip.cs | 27 +++++++++++++++++++-------- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/Controls/VideoPlayerContainer.cs b/src/Controls/VideoPlayerContainer.cs index da4bca560..16a07408b 100644 --- a/src/Controls/VideoPlayerContainer.cs +++ b/src/Controls/VideoPlayerContainer.cs @@ -238,8 +238,11 @@ namespace Nikse.SubtitleEdit.Controls { _subtitleText = value; - bool alignLeft = _subtitleText.StartsWith("{\\a1}") || _subtitleText.StartsWith("{\\a5}") || _subtitleText.StartsWith("{\\a9}"); - bool alignRight = _subtitleText.StartsWith("{\\a3}") || _subtitleText.StartsWith("{\\a7}") || _subtitleText.StartsWith("{\\a11}"); + bool alignLeft = _subtitleText.StartsWith("{\\a1}") || _subtitleText.StartsWith("{\\a5}") || _subtitleText.StartsWith("{\\a9}") || // sub station alpha + _subtitleText.StartsWith("{\\an1}") || _subtitleText.StartsWith("{\\an4}") || _subtitleText.StartsWith("{\\an7}"); // advanced sub station alpha + + bool alignRight = _subtitleText.StartsWith("{\\a3}") || _subtitleText.StartsWith("{\\a7}") || _subtitleText.StartsWith("{\\a11}") || // sub station alpha + _subtitleText.StartsWith("{\\an3}") || _subtitleText.StartsWith("{\\an6}") || _subtitleText.StartsWith("{\\an9}"); // advanced sub station alpha // remove styles for display text (except italic) string text = RemoveSubStationAlphaFormatting(_subtitleText); diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 5edabbfb1..67ab771dd 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -2131,7 +2131,13 @@ namespace Nikse.SubtitleEdit.Forms { string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header); if (!string.IsNullOrEmpty(errors)) - MessageBox.Show(errors); + MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + else if (format.GetType() == typeof(SubRip)) + { + string errors = (format as SubRip).Errors; + if (!string.IsNullOrEmpty(errors)) + MessageBox.Show((format as SubRip).Errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else @@ -3570,12 +3576,19 @@ namespace Nikse.SubtitleEdit.Forms index++; } - if (format.FriendlyName == new AdvancedSubStationAlpha().FriendlyName || format.FriendlyName == new SubStationAlpha().FriendlyName) + if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha)) { string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header); if (!string.IsNullOrEmpty(errors)) - MessageBox.Show(errors); + MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } + else if (format.GetType() == typeof(SubRip)) + { + string errors = (format as SubRip).Errors; + if (!string.IsNullOrEmpty(errors)) + MessageBox.Show((format as SubRip).Errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } } else diff --git a/src/Logic/Language.cs b/src/Logic/Language.cs index f68b9e9d2..b0fde9d57 100644 --- a/src/Logic/Language.cs +++ b/src/Logic/Language.cs @@ -781,6 +781,8 @@ namespace Nikse.SubtitleEdit.Logic TextFiles = "Text files", ExportPlainTextAs = "Export plain text as", SubtitleExported = "Subtitle exported", + LineNumberXErrorReadingTimeCodeFromSourceLineY = "Line {0} - error reading time code: {1}", + LineNumberXExpectedNumberFromSourceLineY = "Line {0} - expected subtitle number: {1}", Menu = new LanguageStructure.Main.MainMenu { diff --git a/src/Logic/LanguageStructure.cs b/src/Logic/LanguageStructure.cs index d718d253b..fc55b2236 100644 --- a/src/Logic/LanguageStructure.cs +++ b/src/Logic/LanguageStructure.cs @@ -721,6 +721,9 @@ public string ExportPlainTextAs { get; set; } public string TextFiles { get; set; } public string SubtitleExported { get; set; } + public string LineNumberXErrorReadingTimeCodeFromSourceLineY { get; set; } + public string LineNumberXExpectedNumberFromSourceLineY { get; set; } + public class MainMenu { diff --git a/src/Logic/SubtitleFormats/SubRip.cs b/src/Logic/SubtitleFormats/SubRip.cs index 3769105cf..ca3cc71dc 100644 --- a/src/Logic/SubtitleFormats/SubRip.cs +++ b/src/Logic/SubtitleFormats/SubRip.cs @@ -7,6 +7,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats { public class SubRip : SubtitleFormat { + public string Errors { get; private set; } + private StringBuilder _errors; + private int _lineNumber; + enum ExpectingLine { Number, @@ -63,6 +67,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { bool doRenum = false; + _errors = new StringBuilder(); + _lineNumber = 0; _paragraph = new Paragraph(); _expecting = ExpectingLine.Number; @@ -71,6 +77,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats subtitle.Paragraphs.Clear(); for (int i=0; i 0) { + if (_errors.Length < 2000) + _errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXExpectedNumberFromSourceLineY, _lineNumber, line)); _errorCount++; } break; @@ -126,6 +137,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats } else if (line.Trim().Length > 0) { + if (_errors.Length < 2000) + _errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXErrorReadingTimeCodeFromSourceLineY, _lineNumber, line)); _errorCount++; _expecting = ExpectingLine.Number ; // lets go to next paragraph } @@ -180,20 +193,13 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats private string RemoveBadChars(string line) { line = line.Replace("\0", " "); - return line; } private bool TryReadTimeCodesLine(string line, Paragraph paragraph) - { + { line = line.Replace("،", ","); - line = line.Trim(); - line = line.Replace(": ", ":"); // I've seen this - line = line.Replace(" :", ":"); - line = line.Replace(" ,", ","); - line = line.Replace(", ", ","); - // Fix some badly formatted separator sequences - anything can happen if you manually edit ;) line = line.Replace(" -> ", " --> "); // I've seen this line = line.Replace(" - > ", " --> "); @@ -201,12 +207,17 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats line = line.Replace(" -- > ", " --> "); line = line.Replace(" - -> ", " --> "); line = line.Replace(" -->> ", " --> "); + line = line.Replace(" ---> ", " --> "); // Removed stuff after timecodes - like subtitle position // - example of position info: 00:02:26,407 --> 00:02:31,356 X1:100 X2:100 Y1:100 Y2:100 if (line.Length > 30 && line[30] == ' ') line = line.Substring(0, 29); + // removes all extra spaces + line = line.Replace(" ", string.Empty).Replace("-->", " --> "); + line = line.Trim(); + // Fix a few more cases of wrong time codes, seen this: 00.00.02,000 --> 00.00.04,000 line = line.Replace('.', ':'); if (line.Length >= 29 && ":;".Contains(line[8].ToString()))