diff --git a/SimpleZIP_UI/Application/Compression/Algorithm/CompressorAlgorithm.cs b/SimpleZIP_UI/Application/Compression/Algorithm/CompressorAlgorithm.cs
index 7c4fb15..3cddc56 100644
--- a/SimpleZIP_UI/Application/Compression/Algorithm/CompressorAlgorithm.cs
+++ b/SimpleZIP_UI/Application/Compression/Algorithm/CompressorAlgorithm.cs
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
@@ -38,9 +39,8 @@ namespace SimpleZIP_UI.Application.Compression.Algorithm
///
public abstract class CompressorAlgorithm : AbstractAlgorithm
{
- ///
- public override async Task Decompress(StorageFile archive, StorageFolder location,
- ReaderOptions options = null)
+ private async Task DecompressArchive(IStorageFile archive, IStorageFolder location,
+ IReadOnlyCollection entries, bool collectFileNames, ReaderOptions options = null)
{
if (archive == null || location == null) return Stream.Null;
@@ -68,7 +68,15 @@ public override async Task Decompress(StorageFile archive, StorageFolder
await outputStream.WriteAsync(bytes, 0, readBytes, Token);
}
}
+
await GZipOutputFileNameWorkaround(file, compressorStream);
+
+ // update file name of corresponding entry
+ if (collectFileNames && !entries.IsNullOrEmpty())
+ {
+ var entry = entries.ElementAt(0);
+ entry.FileName = file.Name;
+ }
}
finally
{
@@ -77,21 +85,33 @@ public override async Task Decompress(StorageFile archive, StorageFolder
compressorStream.Dispose();
}
}
+
return compressorStream;
}
///
+ public override async Task Decompress(StorageFile archive, StorageFolder location,
+ ReaderOptions options = null)
+ {
+ return await DecompressArchive(archive, location, null, false, options);
+ }
+
+ ///
+ /// Entries are not supported in non-archive formats,
+ /// but will be used if file names are to be collected.
public override async Task Decompress(StorageFile archive, StorageFolder location,
IReadOnlyList entries, bool collectFileNames, ReaderOptions options = null)
{
- return await Decompress(archive, location, options); // ignore entries as they are not supported
+ return await DecompressArchive(archive, location, entries, collectFileNames, options);
}
///
+ /// Entries are not supported in non-archive formats,
+ /// and hence will be ignored.
public sealed override async Task Decompress(StorageFile archive, StorageFolder location,
IReadOnlyList entries, ReaderOptions options = null)
{
- return await Decompress(archive, location, options); // ignore entries as they are not supported
+ return await DecompressArchive(archive, location, entries, false, options);
}
///
@@ -128,6 +148,7 @@ public override async Task Compress(IReadOnlyList files, St
compressorStream.Dispose();
}
}
+
return compressorStream;
}
@@ -149,6 +170,7 @@ await file.RenameAsync(gzipStream.FileName,
NameCollisionOption.GenerateUniqueName);
return true;
}
+
return false;
}