From 792b299037f54ed3e29b6eaffa28d25a938abd17 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 16 May 2015 00:33:31 +0400 Subject: [PATCH] reworked GarExtract disposal logic. --- GarExtract.cs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/GarExtract.cs b/GarExtract.cs index 3ffe8f43..3b39fe39 100644 --- a/GarExtract.cs +++ b/GarExtract.cs @@ -51,6 +51,7 @@ namespace GARbro.GUI SetStatusText (guiStrings.MsgChooseFiles); return; } + GarExtract extractor = null; try { if (!ViewModel.IsArchive) @@ -63,21 +64,19 @@ namespace GARbro.GUI // extract into directory named after archive if (!string.IsNullOrEmpty (Path.GetExtension (entry.Name))) destination = Path.GetFileNameWithoutExtension (source); - using (var extractor = new GarExtract (this, source)) - extractor.ExtractAll (destination); + extractor = new GarExtract (this, source); + extractor.ExtractAll (destination); } } else if (null != m_app.CurrentArchive) { var vm = ViewModel as ArchiveViewModel; string destination = Path.GetDirectoryName (vm.Path); - using (var extractor = new GarExtract (this, vm.Path, m_app.CurrentArchive)) - { - if (null == entry || (entry.Name == ".." && vm.SubDir == "")) // root entry - extractor.ExtractAll (destination); - else - extractor.Extract (entry, destination); - } + extractor = new GarExtract (this, vm.Path, m_app.CurrentArchive); + if (null == entry || (entry.Name == ".." && vm.SubDir == "")) // root entry + extractor.ExtractAll (destination); + else + extractor.Extract (entry, destination); } } catch (OperationCanceledException X) @@ -88,6 +87,11 @@ namespace GARbro.GUI { PopupError (X.Message, guiStrings.MsgErrorExtracting); } + finally + { + if (null != extractor && !extractor.IsActive) + extractor.Dispose(); + } } } @@ -110,6 +114,8 @@ namespace GARbro.GUI public static readonly HashSet CommonAudioFormats = new HashSet { "wav", "mp3", "ogg" }; + public bool IsActive { get { return m_extract_in_progress; } } + public GarExtract (MainWindow parent, string source) { m_main = parent; @@ -367,16 +373,13 @@ namespace GARbro.GUI public void Dispose () { - if (!m_extract_in_progress) + if (!disposed) { - if (!disposed) - { - if (m_should_dispose) - m_arc.Dispose(); - disposed = true; - } - GC.SuppressFinalize (this); + if (m_should_dispose) + m_arc.Dispose(); + disposed = true; } + GC.SuppressFinalize (this); } ~GarExtract ()