diff --git a/src/Forms/BatchConvert.cs b/src/Forms/BatchConvert.cs index 0912223e7..29e26d888 100644 --- a/src/Forms/BatchConvert.cs +++ b/src/Forms/BatchConvert.cs @@ -923,9 +923,11 @@ namespace Nikse.SubtitleEdit.Forms { try { - var form = new MultipleReplace(); - form.Initialize(p.Subtitle); - p.Subtitle = form.FixedSubtitle; + using (var form = new MultipleReplace()) + { + form.Initialize(p.Subtitle); + p.Subtitle = form.FixedSubtitle; + } } catch (Exception exception) { @@ -1030,20 +1032,24 @@ namespace Nikse.SubtitleEdit.Forms if (comboBoxSubtitleFormats.Text == new AdvancedSubStationAlpha().Name) { var sub = new Subtitle(); - var form = new SubStationAlphaStyles(sub, new AdvancedSubStationAlpha()); - form.MakeOnlyOneStyle(); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new SubStationAlphaStyles(sub, new AdvancedSubStationAlpha())) { - _assStyle = form.Header; + form.MakeOnlyOneStyle(); + if (form.ShowDialog(this) == DialogResult.OK) + { + _assStyle = form.Header; + } } } else if (comboBoxSubtitleFormats.Text == new SubStationAlpha().Name) { var sub = new Subtitle(); - var form = new SubStationAlphaStyles(sub, new SubStationAlpha()); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new SubStationAlphaStyles(sub, new SubStationAlpha())) { - _ssaStyle = form.Header; + if (form.ShowDialog(this) == DialogResult.OK) + { + _ssaStyle = form.Header; + } } } } @@ -1095,10 +1101,12 @@ namespace Nikse.SubtitleEdit.Forms private void buttonFixCommonErrorSettings_Click(object sender, EventArgs e) { - var form = new FixCommonErrors(); - form.RunBatchSettings(new Subtitle(), GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage); - form.ShowDialog(this); - Configuration.Settings.Tools.BatchConvertLanguage = form.Language; + using (var form = new FixCommonErrors()) + { + form.RunBatchSettings(new Subtitle(), GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage); + form.ShowDialog(this); + Configuration.Settings.Tools.BatchConvertLanguage = form.Language; + } } private void BatchConvert_FormClosing(object sender, FormClosingEventArgs e) @@ -1124,9 +1132,11 @@ namespace Nikse.SubtitleEdit.Forms private void buttonMultipleReplaceSettings_Click(object sender, EventArgs e) { - var form = new MultipleReplace(); - form.Initialize(new Subtitle()); - form.ShowDialog(this); + using (var form = new MultipleReplace()) + { + form.Initialize(new Subtitle()); + form.ShowDialog(this); + } } private void checkBoxOverwriteOriginalFiles_CheckedChanged(object sender, EventArgs e) @@ -1300,9 +1310,11 @@ namespace Nikse.SubtitleEdit.Forms private void buttonRemoveTextForHiSettings_Click(object sender, EventArgs e) { - var form = new FormRemoveTextForHearImpaired(); - form.InitializeSettingsOnly(); - form.ShowDialog(this); + using (var form = new FormRemoveTextForHearImpaired()) + { + form.InitializeSettingsOnly(); + form.ShowDialog(this); + } } } diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 02032226d..2326d74d4 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -10225,85 +10225,86 @@ namespace Nikse.SubtitleEdit.Forms if (IsSubtitleLoaded) { SaveSubtitleListviewIndexes(); - var changeCasing = new ChangeCasing(); - _formPositionsAndSizes.SetPositionAndSize(changeCasing); - if (onlySelectedLines) - changeCasing.Text += " - " + _language.SelectedLines; - ReloadFromSourceView(); - if (changeCasing.ShowDialog(this) == DialogResult.OK) + using (var changeCasing = new ChangeCasing()) { - MakeHistoryForUndo(_language.BeforeChangeCasing); - - Cursor.Current = Cursors.WaitCursor; - var selectedLines = new Subtitle(); - selectedLines.WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers; + _formPositionsAndSizes.SetPositionAndSize(changeCasing); if (onlySelectedLines) + changeCasing.Text += " - " + _language.SelectedLines; + ReloadFromSourceView(); + if (changeCasing.ShowDialog(this) == DialogResult.OK) { - foreach (int index in SubtitleListview1.SelectedIndices) - selectedLines.Paragraphs.Add(new Paragraph(_subtitle.Paragraphs[index])); - } - else - { - foreach (Paragraph p in _subtitle.Paragraphs) - selectedLines.Paragraphs.Add(new Paragraph(p)); - } + MakeHistoryForUndo(_language.BeforeChangeCasing); - bool saveChangeCaseChanges = true; - changeCasing.FixCasing(selectedLines, Utilities.AutoDetectLanguageName(Configuration.Settings.General.SpellCheckLanguage, _subtitle)); - var changeCasingNames = new ChangeCasingNames(); - if (changeCasing.ChangeNamesToo) - { - changeCasingNames.Initialize(selectedLines); - if (changeCasingNames.ShowDialog(this) == DialogResult.OK) - { - changeCasingNames.FixCasing(); - - if (changeCasing.LinesChanged == 0) - ShowStatus(string.Format(_language.CasingCompleteMessageOnlyNames, changeCasingNames.LinesChanged, _subtitle.Paragraphs.Count)); - else - ShowStatus(string.Format(_language.CasingCompleteMessage, changeCasing.LinesChanged, _subtitle.Paragraphs.Count, changeCasingNames.LinesChanged)); - } - else - { - saveChangeCaseChanges = false; - } - } - else - { - ShowStatus(string.Format(_language.CasingCompleteMessageNoNames, changeCasing.LinesChanged, _subtitle.Paragraphs.Count)); - } - - if (saveChangeCaseChanges) - { + Cursor.Current = Cursors.WaitCursor; + var selectedLines = new Subtitle(); + selectedLines.WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers; if (onlySelectedLines) { - int i = 0; foreach (int index in SubtitleListview1.SelectedIndices) + selectedLines.Paragraphs.Add(new Paragraph(_subtitle.Paragraphs[index])); + } + else + { + foreach (Paragraph p in _subtitle.Paragraphs) + selectedLines.Paragraphs.Add(new Paragraph(p)); + } + + bool saveChangeCaseChanges = true; + changeCasing.FixCasing(selectedLines, Utilities.AutoDetectLanguageName(Configuration.Settings.General.SpellCheckLanguage, _subtitle)); + var changeCasingNames = new ChangeCasingNames(); + if (changeCasing.ChangeNamesToo) + { + changeCasingNames.Initialize(selectedLines); + if (changeCasingNames.ShowDialog(this) == DialogResult.OK) { - _subtitle.Paragraphs[index].Text = selectedLines.Paragraphs[i].Text; - i++; + changeCasingNames.FixCasing(); + + if (changeCasing.LinesChanged == 0) + ShowStatus(string.Format(_language.CasingCompleteMessageOnlyNames, changeCasingNames.LinesChanged, _subtitle.Paragraphs.Count)); + else + ShowStatus(string.Format(_language.CasingCompleteMessage, changeCasing.LinesChanged, _subtitle.Paragraphs.Count, changeCasingNames.LinesChanged)); + } + else + { + saveChangeCaseChanges = false; } } else { - for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + ShowStatus(string.Format(_language.CasingCompleteMessageNoNames, changeCasing.LinesChanged, _subtitle.Paragraphs.Count)); + } + + if (saveChangeCaseChanges) + { + if (onlySelectedLines) { - _subtitle.Paragraphs[i].Text = selectedLines.Paragraphs[i].Text; + int i = 0; + foreach (int index in SubtitleListview1.SelectedIndices) + { + _subtitle.Paragraphs[index].Text = selectedLines.Paragraphs[i].Text; + i++; + } + } + else + { + for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + { + _subtitle.Paragraphs[i].Text = selectedLines.Paragraphs[i].Text; + } + } + ShowSource(); + SubtitleListview1.Fill(_subtitle, _subtitleAlternate); + if (changeCasing.LinesChanged > 0 || changeCasingNames.LinesChanged > 0) + { + _subtitleListViewIndex = -1; + RestoreSubtitleListviewIndexes(); + UpdateSourceView(); } } - ShowSource(); - SubtitleListview1.Fill(_subtitle, _subtitleAlternate); - if (changeCasing.LinesChanged > 0 || changeCasingNames.LinesChanged > 0) - { - _subtitleListViewIndex = -1; - RestoreSubtitleListviewIndexes(); - UpdateSourceView(); - } + Cursor.Current = Cursors.Default; } - Cursor.Current = Cursors.Default; + _formPositionsAndSizes.SavePositionAndSize(changeCasing); } - _formPositionsAndSizes.SavePositionAndSize(changeCasing); - changeCasing.Dispose(); } else { diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index 62877dd80..2fe0d63c2 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -6770,32 +6770,35 @@ namespace Nikse.SubtitleEdit.Forms public DialogResult EditImageCompareCharacters(string name, string text) { - var formVobSubEditCharacters = new VobSubEditCharacters(comboBoxCharacterDatabase.SelectedItem.ToString(), null, _binaryOcrDb); - formVobSubEditCharacters.Initialize(name, text); - DialogResult result = formVobSubEditCharacters.ShowDialog(); - if (result == DialogResult.OK) + using (var formVobSubEditCharacters = new VobSubEditCharacters(comboBoxCharacterDatabase.SelectedItem.ToString(), null, _binaryOcrDb)) { - if (_binaryOcrDb != null) + + formVobSubEditCharacters.Initialize(name, text); + DialogResult result = formVobSubEditCharacters.ShowDialog(); + if (result == DialogResult.OK) { - _binaryOcrDb.Save(); - } - else - { - _compareDoc = formVobSubEditCharacters.ImageCompareDocument; - string path = Configuration.VobSubCompareFolder + comboBoxCharacterDatabase.SelectedItem + Path.DirectorySeparatorChar; - _compareDoc.Save(path + "Images.xml"); - Cursor = Cursors.WaitCursor; - if (formVobSubEditCharacters.ChangesMade) - _binaryOcrDb.LoadCompareImages(); - Cursor = Cursors.Default; + if (_binaryOcrDb != null) + { + _binaryOcrDb.Save(); + } + else + { + _compareDoc = formVobSubEditCharacters.ImageCompareDocument; + string path = Configuration.VobSubCompareFolder + comboBoxCharacterDatabase.SelectedItem + Path.DirectorySeparatorChar; + _compareDoc.Save(path + "Images.xml"); + Cursor = Cursors.WaitCursor; + if (formVobSubEditCharacters.ChangesMade) + _binaryOcrDb.LoadCompareImages(); + Cursor = Cursors.Default; + } + return result; } + Cursor = Cursors.WaitCursor; + if (formVobSubEditCharacters.ChangesMade) + _binaryOcrDb.LoadCompareImages(); + Cursor = Cursors.Default; return result; } - Cursor = Cursors.WaitCursor; - if (formVobSubEditCharacters.ChangesMade) - _binaryOcrDb.LoadCompareImages(); - Cursor = Cursors.Default; - return result; } private void VobSubOcr_KeyDown(object sender, KeyEventArgs e) @@ -7934,18 +7937,19 @@ namespace Nikse.SubtitleEdit.Forms comboBoxDictionaries_SelectedIndexChanged(null, null); text = text.Substring(text.IndexOf(':') + 1).Trim(); - var form = new AddToNamesList(); - form.Initialize(_subtitle, comboBoxDictionaries.Text, text); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new AddToNamesList()) { - comboBoxDictionaries_SelectedIndexChanged(null, null); - ShowStatus(string.Format(Configuration.Settings.Language.Main.NameXAddedToNamesEtcList, form.NewName)); + form.Initialize(_subtitle, comboBoxDictionaries.Text, text); + if (form.ShowDialog(this) == DialogResult.OK) + { + comboBoxDictionaries_SelectedIndexChanged(null, null); + ShowStatus(string.Format(Configuration.Settings.Language.Main.NameXAddedToNamesEtcList, form.NewName)); + } + else if (!string.IsNullOrEmpty(form.NewName)) + { + MessageBox.Show(string.Format(Configuration.Settings.Language.Main.NameXNotAddedToNamesEtcList, form.NewName)); + } } - else if (!string.IsNullOrEmpty(form.NewName)) - { - MessageBox.Show(string.Format(Configuration.Settings.Language.Main.NameXNotAddedToNamesEtcList, form.NewName)); - } - form.Dispose(); } } } @@ -7958,18 +7962,19 @@ namespace Nikse.SubtitleEdit.Forms if (text.Contains(':')) { text = text.Substring(text.IndexOf(':') + 1).Trim().ToLower(); - var form = new AddToUserDic(); - form.Initialize(comboBoxDictionaries.Text, text); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new AddToUserDic()) { - comboBoxDictionaries_SelectedIndexChanged(null, null); - ShowStatus(string.Format(Configuration.Settings.Language.Main.WordXAddedToUserDic, form.NewWord)); + form.Initialize(comboBoxDictionaries.Text, text); + if (form.ShowDialog(this) == DialogResult.OK) + { + comboBoxDictionaries_SelectedIndexChanged(null, null); + ShowStatus(string.Format(Configuration.Settings.Language.Main.WordXAddedToUserDic, form.NewWord)); + } + else if (!string.IsNullOrEmpty(form.NewWord)) + { + MessageBox.Show(string.Format(Configuration.Settings.Language.Main.WordXNotAddedToUserDic, form.NewWord)); + } } - else if (!string.IsNullOrEmpty(form.NewWord)) - { - MessageBox.Show(string.Format(Configuration.Settings.Language.Main.WordXNotAddedToUserDic, form.NewWord)); - } - form.Dispose(); } } } @@ -7982,16 +7987,18 @@ namespace Nikse.SubtitleEdit.Forms if (text.Contains(':')) { text = text.Substring(text.IndexOf(':') + 1).Trim().ToLower(); - var form = new AddToOcrReplaceList(); - form.Initialize(_languageId, comboBoxDictionaries.Text, text); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new AddToOcrReplaceList()) { - comboBoxDictionaries_SelectedIndexChanged(null, null); - ShowStatus(string.Format(Configuration.Settings.Language.Main.OcrReplacePairXAdded, form.NewSource, form.NewTarget)); - } - else - { - MessageBox.Show(string.Format(Configuration.Settings.Language.Main.OcrReplacePairXNotAdded, form.NewSource, form.NewTarget)); + form.Initialize(_languageId, comboBoxDictionaries.Text, text); + if (form.ShowDialog(this) == DialogResult.OK) + { + comboBoxDictionaries_SelectedIndexChanged(null, null); + ShowStatus(string.Format(Configuration.Settings.Language.Main.OcrReplacePairXAdded, form.NewSource, form.NewTarget)); + } + else + { + MessageBox.Show(string.Format(Configuration.Settings.Language.Main.OcrReplacePairXNotAdded, form.NewSource, form.NewTarget)); + } } } } @@ -8031,9 +8038,11 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemSetUnItalicFactor_Click(object sender, EventArgs e) { - var form = new VobSubOcrSetItalicFactor(GetSubtitleBitmap(_selectedIndex), _unItalicFactor); - form.ShowDialog(this); - _unItalicFactor = form.GetUnItalicFactor(); + using (var form = new VobSubOcrSetItalicFactor(GetSubtitleBitmap(_selectedIndex), _unItalicFactor)) + { + form.ShowDialog(this); + _unItalicFactor = form.GetUnItalicFactor(); + } } private void vobSubToolStripMenuItem_Click(object sender, EventArgs e) @@ -8126,14 +8135,16 @@ namespace Nikse.SubtitleEdit.Forms LoadNOcrWithCurrentLanguage(); } - var form = new VobSubNOcrEdit(_nOcrDb.OcrCharacters, null); - if (form.ShowDialog(this) == DialogResult.OK) + using (var form = new VobSubNOcrEdit(_nOcrDb.OcrCharacters, null)) { - SaveNOcrWithCurrentLanguage(); - } - else - { - LoadNOcrWithCurrentLanguage(); + if (form.ShowDialog(this) == DialogResult.OK) + { + SaveNOcrWithCurrentLanguage(); + } + else + { + LoadNOcrWithCurrentLanguage(); + } } } @@ -8334,9 +8345,11 @@ namespace Nikse.SubtitleEdit.Forms private void nOcrTrainingToolStripMenuItem_Click(object sender, EventArgs e) { - VobSubNOcrTrain form = new VobSubNOcrTrain(); - form.Initialize(_nOcrDb); - form.Show(this); + using (var form = new VobSubNOcrTrain()) + { + form.Initialize(_nOcrDb); + form.Show(this); + } } private OcrFixEngine.AutoGuessLevel GetAutoGuessLevel() diff --git a/src/Logic/SubtitleFormats/Pac.cs b/src/Logic/SubtitleFormats/Pac.cs index 643efd229..9cbf1f9ac 100644 --- a/src/Logic/SubtitleFormats/Pac.cs +++ b/src/Logic/SubtitleFormats/Pac.cs @@ -1217,9 +1217,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats count++; if (count == 2) { - index = start; _codePage = 0; - bool allOK = true; + bool allOk = true; StringBuilder sb = new StringBuilder(); for (int i = 0; i < LatinLetters.Count; i++) sb.Append(LatinLetters[i]); @@ -1227,27 +1226,27 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats foreach (char ch in Utilities.RemoveHtmlTags(p.Text, true)) { if (!latinLetters.Contains(ch)) - allOK = false; + allOk = false; } - if (allOK) + if (allOk) return 0; // Latin index = start; _codePage = 1; p = GetPacParagraph(ref index, buffer); - allOK = true; + allOk = true; foreach (char ch in Utilities.RemoveHtmlTags(p.Text, true)) { if (!"AαBβΓγΔδEϵεZζHηΘθIιKκΛλMμNνΞξOοΠπPρΣσςTτΥυΦϕφXχΨψΩω(1234567890, .!?-\r\n'\")".Contains(ch)) - allOK = false; + allOk = false; } - if (allOK) + if (allOk) return 1; // Greek index = start; _codePage = 3; p = GetPacParagraph(ref index, buffer); - allOK = true; + allOk = true; sb = new StringBuilder(); for (int i = 0; i < ArabicLetters.Count; i++) sb.Append(ArabicLetters[i]); @@ -1255,15 +1254,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats foreach (char ch in Utilities.RemoveHtmlTags(p.Text, true)) { if (!arabicLetters.Contains(ch)) - allOK = false; + allOk = false; } - if (allOK) + if (allOk) return 3; // Arabic index = start; _codePage = 4; p = GetPacParagraph(ref index, buffer); - allOK = true; + allOk = true; sb = new StringBuilder(); for (int i = 0; i < HebrewLetters.Count; i++) sb.Append(HebrewLetters[i]); @@ -1271,15 +1270,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats foreach (char ch in Utilities.RemoveHtmlTags(p.Text, true)) { if (!hebrewLetters.Contains(ch)) - allOK = false; + allOk = false; } - if (allOK) + if (allOk) return 4; // Hebrew index = start; _codePage = 4; p = GetPacParagraph(ref index, buffer); - allOK = true; + allOk = true; sb = new StringBuilder(); for (int i = 0; i < CyrillicLetters.Count; i++) sb.Append(CyrillicLetters[i]); @@ -1287,9 +1286,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats foreach (char ch in Utilities.RemoveHtmlTags(p.Text, true)) { if (!cyrillicLetters.Contains(ch)) - allOK = false; + allOk = false; } - if (allOK) + if (allOk) return 6; // Cyrillic return 0; // Latin @@ -1343,22 +1342,24 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats previewBuffer[i] = textSample[i]; } - var pacEncoding = new PacEncoding(previewBuffer, _fileName); - if (pacEncoding.ShowDialog() == System.Windows.Forms.DialogResult.OK) + using (var pacEncoding = new PacEncoding(previewBuffer, _fileName)) { - _codePage = pacEncoding.CodePageIndex; - Configuration.Settings.General.LastPacCodePage = _codePage; - } - else - { - _codePage = -2; + if (pacEncoding.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + _codePage = pacEncoding.CodePageIndex; + Configuration.Settings.General.LastPacCodePage = _codePage; + } + else + { + _codePage = -2; + } } } private static byte[] GetLatinBytes(Encoding encoding, string text, byte alignment) { int i = 0; - byte[] buffer = new byte[text.Length * 2]; + var buffer = new byte[text.Length * 2]; int extra = 0; while (i < text.Length) { @@ -1562,8 +1563,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats if (b > 13) return encoding.GetString(buffer, index, 1); - else - return string.Empty; + return string.Empty; } public static string GetCyrillicString(byte[] buffer, ref int index) diff --git a/src/Test/Logic/VideoFormats/MatroskaTest.cs b/src/Test/Logic/VideoFormats/MatroskaTest.cs index ba3eff42f..9960c2441 100644 --- a/src/Test/Logic/VideoFormats/MatroskaTest.cs +++ b/src/Test/Logic/VideoFormats/MatroskaTest.cs @@ -1,7 +1,6 @@ -using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using System.IO; -using System.Runtime.Remoting; -using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Test.Logic.VideoFormats { @@ -9,83 +8,83 @@ namespace Test.Logic.VideoFormats [DeploymentItem("Files")] public class MatroskaTest { + [TestMethod] public void MatroskaTestValid() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); - - Assert.IsTrue(parser.IsValid); - parser.Dispose(); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + Assert.IsTrue(parser.IsValid); + } } [TestMethod] public void MatroskaTestInvalid() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_TS_with_graphics.ts"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); - - Assert.IsFalse(parser.IsValid); - parser.Dispose(); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + Assert.IsFalse(parser.IsValid); + } } [TestMethod] public void MatroskaTestIsSrt() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); - - bool isValid; - var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); - Assert.IsTrue(tracks[0].CodecId == "S_TEXT/UTF8"); - parser.Dispose(); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + bool isValid; + var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); + Assert.IsTrue(tracks[0].CodecId == "S_TEXT/UTF8"); + } } [TestMethod] public void MatroskaTestSrtContent() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); - - bool isValid; - var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); - var subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[0].TrackNumber), out isValid, null); - Assert.IsTrue(subtitles.Count == 2); - Assert.IsTrue(subtitles[0].Text == "Line 1"); - Assert.IsTrue(subtitles[1].Text == "Line 2"); - parser.Dispose(); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + bool isValid; + var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); + var subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[0].TrackNumber), out isValid, null); + Assert.IsTrue(subtitles.Count == 2); + Assert.IsTrue(subtitles[0].Text == "Line 1"); + Assert.IsTrue(subtitles[1].Text == "Line 2"); + } } [TestMethod] public void MatroskaTestVobSubPgs() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); - - bool isValid; - var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); - Assert.IsTrue(tracks[0].CodecId == "S_VOBSUB"); - Assert.IsTrue(tracks[1].CodecId == "S_HDMV/PGS"); - parser.Dispose(); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + bool isValid; + var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); + Assert.IsTrue(tracks[0].CodecId == "S_VOBSUB"); + Assert.IsTrue(tracks[1].CodecId == "S_HDMV/PGS"); + } } [TestMethod] public void MatroskaTestVobSubPgsContent() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv"); - var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName); + using (var parser = new Nikse.SubtitleEdit.Logic.VideoFormats.Matroska(fileName)) + { + bool isValid; + var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); + var subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[0].TrackNumber), out isValid, null); + Assert.IsTrue(subtitles.Count == 2); + //TODO: check bitmaps - bool isValid; - var tracks = parser.GetMatroskaSubtitleTracks(fileName, out isValid); - var subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[0].TrackNumber), out isValid, null); - Assert.IsTrue(subtitles.Count == 2); - //TODO: check bitmaps - - //subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[1].TrackNumber), out isValid, null); - //Assert.IsTrue(subtitles.Count == 2); - //check bitmaps - - parser.Dispose(); + //subtitles = parser.GetMatroskaSubtitle(fileName, Convert.ToInt32(tracks[1].TrackNumber), out isValid, null); + //Assert.IsTrue(subtitles.Count == 2); + //check bitmaps + } } } diff --git a/src/Test/Logic/VobSub/VobSubTest.cs b/src/Test/Logic/VobSub/VobSubTest.cs index cecdb01a8..22273cc72 100644 --- a/src/Test/Logic/VobSub/VobSubTest.cs +++ b/src/Test/Logic/VobSub/VobSubTest.cs @@ -13,12 +13,13 @@ namespace Test.Logic.VobSub public void VobSubWriteAndReadTwoBitmaps() { string fileName = Guid.NewGuid() + ".sub"; - var writer = new VobSubWriter(fileName, 800, 600, 10, 32, Color.White, Color.Black, true, "English", "en"); - var p1 = new Paragraph("Line1", 0, 1000); - var p2 = new Paragraph("Line2", 2000, 3000); - writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter); - writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter); - writer.Dispose(); + using (var writer = new VobSubWriter(fileName, 800, 600, 10, 32, Color.White, Color.Black, true, "English", "en")) + { + var p1 = new Paragraph("Line1", 0, 1000); + var p2 = new Paragraph("Line2", 2000, 3000); + writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter); + writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter); + } var reader = new VobSubParser(true); reader.Open(fileName);