From b79038781542f646573f42c29603273b3ceec541 Mon Sep 17 00:00:00 2001
From: libgenapps <33476799+libgenapps@users.noreply.github.com>
Date: Wed, 21 Feb 2018 19:37:00 +0300
Subject: [PATCH] 7z reader fix
---
LibgenDesktop.Setup/Constants.cs | 2 +-
LibgenDesktop/Common/Constants.cs | 4 +-
LibgenDesktop/LibgenDesktop.csproj | 1 +
.../Models/SqlDump/PositioningStreamReader.cs | 58 +++++++++++++++++++
LibgenDesktop/Models/SqlDump/SqlDumpReader.cs | 2 +-
5 files changed, 63 insertions(+), 4 deletions(-)
create mode 100644 LibgenDesktop/Models/SqlDump/PositioningStreamReader.cs
diff --git a/LibgenDesktop.Setup/Constants.cs b/LibgenDesktop.Setup/Constants.cs
index 3f69d77..b8b7275 100644
--- a/LibgenDesktop.Setup/Constants.cs
+++ b/LibgenDesktop.Setup/Constants.cs
@@ -2,7 +2,7 @@
{
internal static class Constants
{
- public const string CURRENT_VERSION = "0.13.1";
+ public const string CURRENT_VERSION = "0.13.2";
public const string PRODUCT_TITLE_FORMAT = "Libgen Desktop " + CURRENT_VERSION + " ({0}-bit)";
public const string SHORTCUT_TITLE_FORMAT = "Libgen Desktop ({0}-bit)";
public const string PRODUCT_COMPANY = "Libgen Apps";
diff --git a/LibgenDesktop/Common/Constants.cs b/LibgenDesktop/Common/Constants.cs
index fa4e5e0..fb34c25 100644
--- a/LibgenDesktop/Common/Constants.cs
+++ b/LibgenDesktop/Common/Constants.cs
@@ -2,8 +2,8 @@
{
internal static class Constants
{
- public const string CURRENT_VERSION = "0.13.1";
- public const string CURRENT_GITHUB_RELEASE_NAME = "v0.13.1 alpha";
+ public const string CURRENT_VERSION = "0.13.2";
+ public const string CURRENT_GITHUB_RELEASE_NAME = "v0.13.2 alpha";
public const string CURRENT_DATABASE_VERSION = "0.7";
public const string APP_SETTINGS_FILE_NAME = "libgen.config";
diff --git a/LibgenDesktop/LibgenDesktop.csproj b/LibgenDesktop/LibgenDesktop.csproj
index f5c8de7..5b79ebe 100644
--- a/LibgenDesktop/LibgenDesktop.csproj
+++ b/LibgenDesktop/LibgenDesktop.csproj
@@ -211,6 +211,7 @@
+
diff --git a/LibgenDesktop/Models/SqlDump/PositioningStreamReader.cs b/LibgenDesktop/Models/SqlDump/PositioningStreamReader.cs
new file mode 100644
index 0000000..2ddac02
--- /dev/null
+++ b/LibgenDesktop/Models/SqlDump/PositioningStreamReader.cs
@@ -0,0 +1,58 @@
+using System;
+using System.IO;
+
+namespace LibgenDesktop.Models.SqlDump
+{
+ internal class PositioningStream : Stream
+ {
+ private readonly Stream baseStream;
+ private long position;
+
+ public PositioningStream(Stream baseStream)
+ {
+ this.baseStream = baseStream;
+ position = 0;
+ }
+
+ public override bool CanRead => true;
+ public override bool CanSeek => false;
+ public override bool CanWrite => false;
+ public override long Length => throw new NotImplementedException();
+
+ public override long Position
+ {
+ get => position;
+ set => throw new NotImplementedException();
+ }
+
+ public override void Flush()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ int result = baseStream.Read(buffer, offset, count);
+ if (result > 0)
+ {
+ position += result;
+ }
+ return result;
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/LibgenDesktop/Models/SqlDump/SqlDumpReader.cs b/LibgenDesktop/Models/SqlDump/SqlDumpReader.cs
index c4e762e..7e7a563 100644
--- a/LibgenDesktop/Models/SqlDump/SqlDumpReader.cs
+++ b/LibgenDesktop/Models/SqlDump/SqlDumpReader.cs
@@ -72,7 +72,7 @@ public SqlDumpReader(string filePath)
sevenZipArchive = SevenZipArchive.Open(filePath);
SevenZipArchiveEntry firstSevenZipArchiveEntry = sevenZipArchive.Entries.First();
FileSize = firstSevenZipArchiveEntry.Size;
- streamReader = new StreamReader(firstSevenZipArchiveEntry.OpenEntryStream());
+ streamReader = new StreamReader(new PositioningStream(firstSevenZipArchiveEntry.OpenEntryStream()));
break;
default:
FileSize = new FileInfo(filePath).Length;