Skip to content

Commit 52de324

Browse files
committed
ModApi.Updater: use System.IO.Compression instead of ZipStorer
1 parent c752be2 commit 52de324

File tree

3 files changed

+23
-799
lines changed

3 files changed

+23
-799
lines changed

Updater/ModApi.Updater/MainWindow.xaml.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.IO.Compression;
45
using System.Windows;
56
using System.Windows.Input;
67

@@ -39,19 +40,33 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
3940
{
4041
using (MemoryStream unmStream = new MemoryStream(ModApi.Updater.Properties.Resources.ModApiUpdate))
4142
{
42-
using (ZipStorer archive = ZipStorer.Open(unmStream, FileAccess.Read, true))
43+
string unm = Environment.ExpandEnvironmentVariables(@"%appdata%\ModAPITemp.zip");
44+
if (File.Exists(unm))
45+
File.Delete(unm);
46+
47+
using (var file = File.Create(unm))
48+
{
49+
unmStream.Seek(0, SeekOrigin.Begin);
50+
unmStream.CopyTo(file);
51+
}
52+
53+
using (ZipArchive archive = ZipFile.Open(unm, ZipArchiveMode.Update))
4354
{
44-
InstallProgressBar.Maximum = archive.ReadCentralDir().Count;
55+
InstallProgressBar.Maximum = archive.Entries.Count;
4556

46-
foreach (ZipStorer.ZipFileEntry s in archive.ReadCentralDir())
57+
foreach (var s in archive.Entries)
4758
{
48-
string fileOutPath = Path.Combine(path, s.FilenameInZip);
59+
string fileOutPath = Path.Combine(path, s.FullName);
4960

5061
if (File.Exists(fileOutPath))
5162
File.Delete(fileOutPath);
5263

53-
if (IsPathNotPartOfConfiguration(fileOutPath))
54-
archive.ExtractFile(s, fileOutPath);
64+
if (!s.FullName.EndsWith("/") &&
65+
!s.FullName.EndsWith("\\") &&
66+
IsPathNotPartOfConfiguration(fileOutPath))
67+
{
68+
s.ExtractToFile(fileOutPath);
69+
}
5570

5671
if (InstallProgressBar.Value < InstallProgressBar.Maximum)
5772
InstallProgressBar.Value++;

Updater/ModApi.Updater/ModApi.Updater.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
<Reference Include="System" />
6161
<Reference Include="System.Data" />
6262
<Reference Include="System.Drawing" />
63+
<Reference Include="System.IO.Compression" />
64+
<Reference Include="System.IO.Compression.FileSystem" />
6365
<Reference Include="System.Windows.Forms" />
6466
<Reference Include="System.Xml" />
6567
<Reference Include="Microsoft.CSharp" />
@@ -80,7 +82,6 @@
8082
</ApplicationDefinition>
8183
<Compile Include="EmbeddedAssembly.cs" />
8284
<Compile Include="Permissions.cs" />
83-
<Compile Include="ZipStorer.cs" />
8485
<Page Include="MainWindow.xaml">
8586
<Generator>MSBuild:Compile</Generator>
8687
<SubType>Designer</SubType>

0 commit comments

Comments
 (0)