Skip to content

Commit 4ad3816

Browse files
authored
Replace DotNetZip (#46)
Fixes #45 Replace DotNetZip and use System.IO.Compression instead. Recreated the Examples.zip file so that filenames are properly encoded.
1 parent cba4a1c commit 4ad3816

7 files changed

Lines changed: 23 additions & 23 deletions

File tree

Installer/Product.wxs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@
118118
</Component>
119119
</ComponentGroup>
120120
<ComponentGroup Id="ThirdPartyAssemblies" Directory="APPLICATIONFOLDER">
121-
<Component>
122-
<File Source="$(var.WordsLive.TargetDir)DotNetZip.dll" Name="DotNetZip.dll" KeyPath="yes" />
123-
</Component>
124121
<Component>
125122
<File Source="$(var.WordsLive.TargetDir)MonitoredUndo.dll" Name="MonitoredUndo.dll" KeyPath="yes" />
126123
</Component>

WordsLive/Data/Examples.zip

825 Bytes
Binary file not shown.

WordsLive/FirstStartWindow.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
using System;
2020
using System.ComponentModel;
2121
using System.IO;
22+
using System.IO.Compression;
2223
using System.Reflection;
2324
using System.Windows;
2425
using System.Xml.Linq;
25-
using Ionic.Zip;
2626
using WordsLive.Resources;
2727

2828
namespace WordsLive
@@ -152,8 +152,7 @@ private void Window_Closing(object sender, CancelEventArgs e)
152152
if (!songsExist && !backgroundsExist)
153153
{
154154
var appDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
155-
var examplesZip = ZipFile.Read(Path.Combine(appDir.FullName, "Data", "Examples.zip"));
156-
examplesZip.ExtractAll(actualDirectory);
155+
ZipFile.ExtractToDirectory(Path.Combine(appDir.FullName, "Data", "Examples.zip"), actualDirectory);
157156
}
158157
}
159158
}

WordsLive/Images/ImageInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
using System;
2020
using System.ComponentModel;
2121
using System.IO;
22+
using System.IO.Compression;
2223
using System.Linq;
2324
using System.Windows.Media.Imaging;
24-
using Ionic.Zip;
2525
using WordsLive.Utils.ImageLoader;
2626

2727
namespace WordsLive.Images
@@ -42,14 +42,14 @@ public Uri Uri
4242
}
4343
}
4444

45-
public ZipEntry ZipEntry
45+
public ZipArchiveEntry ZipEntry
4646
{
4747
get
4848
{
4949
if (sourceType != SourceType.ZipFile)
5050
throw new InvalidOperationException("Not loaded from a zip file.");
5151

52-
return (ZipEntry)source;
52+
return (ZipArchiveEntry)source;
5353
}
5454
}
5555

@@ -77,7 +77,7 @@ public string Title
7777
case SourceType.ExternalResource:
7878
return Uri.UnescapeDataString(Uri.Segments.Last());
7979
case SourceType.ZipFile:
80-
return ZipEntry.FileName;
80+
return ZipEntry.Name;
8181
default:
8282
return null;
8383
}
@@ -114,7 +114,7 @@ public ImageInfo(Uri uri)
114114
this.source = uri;
115115
}
116116

117-
public ImageInfo(ZipEntry entry)
117+
public ImageInfo(ZipArchiveEntry entry)
118118
{
119119
this.sourceType = SourceType.ZipFile;
120120
this.source = entry;

WordsLive/Images/ImagesMedia.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
using System.Collections.Generic;
2121
using System.Collections.ObjectModel;
2222
using System.IO;
23+
using System.IO.Compression;
2324
using System.Linq;
24-
using Ionic.Zip;
2525
using WordsLive.Core;
2626

2727
namespace WordsLive.Images
@@ -139,13 +139,15 @@ private IEnumerable<ImageInfo> LoadFromZip()
139139
if (!Uri.IsFile)
140140
throw new NotImplementedException("Loading slideshows from a remote source is not implemented.");
141141

142-
Stream stream = System.IO.File.OpenRead(Uri.LocalPath);
143-
using (var zip = ZipFile.Read(stream))
142+
var archive = ZipFile.OpenRead(Uri.LocalPath);
143+
foreach (var entry in archive.Entries)
144144
{
145-
foreach (var entry in zip.Entries)
145+
if (string.IsNullOrEmpty(entry.Name))
146146
{
147-
yield return new ImageInfo(entry);
147+
// skip directories
148+
continue;
148149
}
150+
yield return new ImageInfo(entry);
149151
}
150152

151153
// important: don't close stream directly, so ImageLoader can load the images

WordsLive/Utils/ImageLoader/Loaders/ZipLoader.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
using System;
2020
using System.IO;
21-
using Ionic.Zip;
21+
using System.IO.Compression;
2222

2323
namespace WordsLive.Utils.ImageLoader.Loaders
2424
{
@@ -28,13 +28,16 @@ internal class ZipLoader: ILoader
2828

2929
public Stream Load(object source)
3030
{
31-
if (source is ZipEntry)
31+
if (source is ZipArchiveEntry)
3232
{
33-
ZipEntry entry = source as ZipEntry;
33+
var entry = source as ZipArchiveEntry;
3434
lock(Lock)
3535
{
3636
MemoryStream stream = new MemoryStream();
37-
entry.Extract(stream);
37+
using (var entryStream = entry.Open())
38+
{
39+
entryStream.CopyTo(stream);
40+
}
3841
stream.Flush();
3942
stream.Seek(0, SeekOrigin.Begin);
4043
return stream;

WordsLive/WordsLive.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
</Reference>
8585
<Reference Include="System.Data" />
8686
<Reference Include="System.Drawing" />
87+
<Reference Include="System.IO.Compression" />
88+
<Reference Include="System.IO.Compression.FileSystem" />
8789
<Reference Include="System.Net" />
8890
<Reference Include="System.Runtime.Remoting" />
8991
<Reference Include="System.Windows.Forms" />
@@ -581,9 +583,6 @@
581583
<PackageReference Include="CefSharp.Wpf">
582584
<Version>139.0.280</Version>
583585
</PackageReference>
584-
<PackageReference Include="DotNetZip">
585-
<Version>1.16.0</Version>
586-
</PackageReference>
587586
<PackageReference Include="Extended.Wpf.Toolkit">
588587
<Version>4.0.2</Version>
589588
</PackageReference>

0 commit comments

Comments
 (0)