diff --git a/src/Forms/GetTesseractDictionaries.cs b/src/Forms/GetTesseractDictionaries.cs index 1647ecbb5..b4fd52181 100644 --- a/src/Forms/GetTesseractDictionaries.cs +++ b/src/Forms/GetTesseractDictionaries.cs @@ -149,13 +149,14 @@ namespace Nikse.SubtitleEdit.Forms } fs.Close(); - var tr = new TarReader(tempFileName); - foreach (TarHeader th in tr.Files) + using (var tr = new TarReader(tempFileName)) { - string fn = Path.Combine(dictionaryFolder, Path.GetFileName(th.FileName.Trim())); - th.WriteData(fn); + foreach (var th in tr.Files) + { + string fn = Path.Combine(dictionaryFolder, Path.GetFileName(th.FileName.Trim())); + th.WriteData(fn); + } } - tr.Close(); File.Delete(tempFileName); Cursor = Cursors.Default; diff --git a/src/Logic/TarReader.cs b/src/Logic/TarReader.cs index f89c12903..31b0c4224 100644 --- a/src/Logic/TarReader.cs +++ b/src/Logic/TarReader.cs @@ -1,9 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; namespace Nikse.SubtitleEdit.Logic { - public class TarReader + public class TarReader : IDisposable { public List Files { get; private set; } @@ -11,7 +12,7 @@ namespace Nikse.SubtitleEdit.Logic public TarReader(string fileName) { - FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); OpenTarFile(fs); } @@ -29,7 +30,6 @@ namespace Nikse.SubtitleEdit.Logic stream.Position = 0; while (pos + 512 < length) { - stream.Seek(pos, SeekOrigin.Begin); var th = new TarHeader(stream); if (th.FileSizeInBytes > 0) @@ -45,5 +45,14 @@ namespace Nikse.SubtitleEdit.Logic _stream.Close(); } + public void Dispose() + { + if (_stream != null) + { + _stream.Dispose(); + _stream = null; + } + } + } } \ No newline at end of file