-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FileProgressEventArgs, updated usage example.
- Loading branch information
Showing
2 changed files
with
96 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
// Unzip class usage example | ||
// Written by Alexey Yakovlev <[email protected]> | ||
// https://github.com/yallie/unzip | ||
|
||
using System; | ||
using System.Linq; | ||
|
||
namespace Internals | ||
{ | ||
internal struct Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
if (args.Length < 2) | ||
{ | ||
Console.WriteLine("Syntax: unzip Archive.zip TargetDirectory"); | ||
return; | ||
} | ||
|
||
var archiveName = args.First(); | ||
var outputDirectory = args.Last(); | ||
|
||
using (var unzip = new Unzip(archiveName)) | ||
{ | ||
ListFiles(unzip); | ||
|
||
unzip.ExtractToDirectory(outputDirectory); | ||
} | ||
} | ||
|
||
private static void ListFiles(Unzip unzip) | ||
{ | ||
var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty; | ||
|
||
foreach (var entry in unzip.Entries.OrderBy(e => e.Name)) | ||
{ | ||
if (entry.IsFile) | ||
{ | ||
Console.WriteLine(tab + "{0}: {1} -> {2}", entry.Name, entry.CompressedSize, entry.OriginalSize); | ||
} | ||
else if (entry.IsDirectory) | ||
// Unzip class usage example | ||
// Written by Alexey Yakovlev <[email protected]> | ||
// https://github.com/yallie/unzip | ||
|
||
using System; | ||
using System.Linq; | ||
|
||
namespace Internals | ||
{ | ||
internal struct Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
if (args.Length < 2) | ||
{ | ||
Console.WriteLine("Syntax: unzip Archive.zip TargetDirectory"); | ||
return; | ||
} | ||
|
||
var archiveName = args.First(); | ||
var outputDirectory = args.Last(); | ||
|
||
using (var unzip = new Unzip(archiveName)) | ||
{ | ||
Console.WriteLine("Listing files in the archive:"); | ||
ListFiles(unzip); | ||
|
||
Console.WriteLine("Extracting files from the archive:"); | ||
unzip.ExtractProgress += (s, e) => Console.WriteLine("{0} of {1}: {2}", e.CurrentFile, e.TotalFiles, e.FileName); | ||
unzip.ExtractToDirectory(outputDirectory); | ||
} | ||
} | ||
|
||
private static void ListFiles(Unzip unzip) | ||
{ | ||
var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty; | ||
|
||
foreach (var entry in unzip.Entries.OrderBy(e => e.Name)) | ||
{ | ||
if (entry.IsFile) | ||
{ | ||
Console.WriteLine(entry.Name); | ||
Console.WriteLine(tab + "{0}: {1} -> {2}", entry.Name, entry.CompressedSize, entry.OriginalSize); | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine(entry.Name); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} |