From 8d5218fc68eecae0f04a4e648469478aa32d218d Mon Sep 17 00:00:00 2001 From: Ivandro Ismael Date: Wed, 27 Feb 2019 21:50:57 +0000 Subject: [PATCH] Compare: Update advanced format detection --- src/Forms/Compare.cs | 87 ++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 59 deletions(-) diff --git a/src/Forms/Compare.cs b/src/Forms/Compare.cs index 9fd569ec9..9e6fcf63d 100644 --- a/src/Forms/Compare.cs +++ b/src/Forms/Compare.cs @@ -120,70 +120,25 @@ namespace Nikse.SubtitleEdit.Forms return; } _subtitle1 = new Subtitle(); - var format = _subtitle1.LoadSubtitle(openFileDialog1.FileName, out _, null); + SubtitleFormat format = _subtitle1.LoadSubtitle(openFileDialog1.FileName, out _, null); if (format == null) { - var pac = new Pac(); - if (pac.IsMine(null, openFileDialog1.FileName)) + // try advanced format (non-text base formats) + foreach (SubtitleFormat advancedFormat in GetAdvancedFormats()) { - pac.BatchMode = true; - pac.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = pac; - } - } - if (format == null) - { - var cavena890 = new Cavena890(); - if (cavena890.IsMine(null, openFileDialog1.FileName)) - { - cavena890.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = cavena890; - } - } - if (format == null) - { - var spt = new Spt(); - if (spt.IsMine(null, openFileDialog1.FileName)) - { - spt.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = spt; - } - } - if (format == null) - { - var cheetahCaption = new CheetahCaption(); - if (cheetahCaption.IsMine(null, openFileDialog1.FileName)) - { - cheetahCaption.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = cheetahCaption; - } - } - if (format == null) - { - var chk = new Chk(); - if (chk.IsMine(null, openFileDialog1.FileName)) - { - chk.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = chk; - } - } - if (format == null) - { - var asc = new TimeLineAscii(); - if (asc.IsMine(null, openFileDialog1.FileName)) - { - asc.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); - format = asc; - } - } - if (format == null) - { - var asc = new TimeLineFootageAscii(); - if (asc.IsMine(null, openFileDialog1.FileName)) - { - asc.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); + if (!advancedFormat.IsMine(null, openFileDialog1.FileName)) + { + continue; + } + if (advancedFormat is Pac pacFormat) + { + pacFormat.BatchMode = true; + } + advancedFormat.LoadSubtitle(_subtitle1, null, openFileDialog1.FileName); + break; // format found, exit the loop } } + subtitleListView1.Fill(_subtitle1); subtitleListView1.SelectIndexAndEnsureVisible(0); subtitleListView2.SelectIndexAndEnsureVisible(0); @@ -196,6 +151,20 @@ namespace Nikse.SubtitleEdit.Forms } } + /// + /// Get advanced subtitle formats (These formats are not include in SubtitleFormat.AllSubtitleFormats) + /// + private static IEnumerable GetAdvancedFormats() + { + yield return new Pac(); + yield return new Cavena890(); + yield return new Spt(); + yield return new CheetahCaption(); + yield return new Chk(); + yield return new TimeLineAscii(); + yield return new TimeLineFootageAscii(); + } + private void ButtonOpenSubtitle2Click(object sender, EventArgs e) { openFileDialog1.FileName = string.Empty;