Minor refact using TarReader

This commit is contained in:
niksedk 2014-10-04 20:48:50 +02:00
parent 3d463eecec
commit 2bf6aa120c
2 changed files with 19 additions and 9 deletions

View File

@ -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;

View File

@ -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<TarHeader> 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;
}
}
}
}