This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from erri120/extraction-progress
Show code and decode progress
- Loading branch information
Showing
22 changed files
with
3,448 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
|
||
namespace OMODFramework.Example | ||
{ | ||
public class Progress : ICodeProgress | ||
{ | ||
private long _total; | ||
private bool _compressing; | ||
|
||
public void Init(long totalSize, bool compressing) | ||
{ | ||
_total = totalSize; | ||
_compressing = compressing; | ||
} | ||
|
||
public void SetProgress(long inSize, long outSize) | ||
{ | ||
if (_compressing) | ||
{ | ||
Console.WriteLine($"Compressing: {outSize} of {_total}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Decompressing: {inSize} of {_total}"); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Common/CRC.cs | ||
|
||
namespace SevenZip | ||
{ | ||
class CRC | ||
{ | ||
public static readonly uint[] Table; | ||
|
||
static CRC() | ||
{ | ||
Table = new uint[256]; | ||
const uint kPoly = 0xEDB88320; | ||
for (uint i = 0; i < 256; i++) | ||
{ | ||
uint r = i; | ||
for (int j = 0; j < 8; j++) | ||
if ((r & 1) != 0) | ||
r = (r >> 1) ^ kPoly; | ||
else | ||
r >>= 1; | ||
Table[i] = r; | ||
} | ||
} | ||
|
||
uint _value = 0xFFFFFFFF; | ||
|
||
public void Init() { _value = 0xFFFFFFFF; } | ||
|
||
public void UpdateByte(byte b) | ||
{ | ||
_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); | ||
} | ||
|
||
public void Update(byte[] data, uint offset, uint size) | ||
{ | ||
for (uint i = 0; i < size; i++) | ||
_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); | ||
} | ||
|
||
public uint GetDigest() { return _value ^ 0xFFFFFFFF; } | ||
|
||
static uint CalculateDigest(byte[] data, uint offset, uint size) | ||
{ | ||
CRC crc = new CRC(); | ||
// crc.Init(); | ||
crc.Update(data, offset, size); | ||
return crc.GetDigest(); | ||
} | ||
|
||
static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) | ||
{ | ||
return (CalculateDigest(data, offset, size) == digest); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// InBuffer.cs | ||
|
||
namespace SevenZip.Buffer | ||
{ | ||
internal class InBuffer | ||
{ | ||
byte[] m_Buffer; | ||
uint m_Pos; | ||
uint m_Limit; | ||
uint m_BufferSize; | ||
System.IO.Stream m_Stream; | ||
bool m_StreamWasExhausted; | ||
ulong m_ProcessedSize; | ||
|
||
public InBuffer(uint bufferSize) | ||
{ | ||
m_Buffer = new byte[bufferSize]; | ||
m_BufferSize = bufferSize; | ||
} | ||
|
||
public void Init(System.IO.Stream stream) | ||
{ | ||
m_Stream = stream; | ||
m_ProcessedSize = 0; | ||
m_Limit = 0; | ||
m_Pos = 0; | ||
m_StreamWasExhausted = false; | ||
} | ||
|
||
public bool ReadBlock() | ||
{ | ||
if (m_StreamWasExhausted) | ||
return false; | ||
m_ProcessedSize += m_Pos; | ||
int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize); | ||
m_Pos = 0; | ||
m_Limit = (uint)aNumProcessedBytes; | ||
m_StreamWasExhausted = (aNumProcessedBytes == 0); | ||
return (!m_StreamWasExhausted); | ||
} | ||
|
||
|
||
public void ReleaseStream() | ||
{ | ||
// m_Stream.Close(); | ||
m_Stream = null; | ||
} | ||
|
||
public bool ReadByte(byte b) // check it | ||
{ | ||
if (m_Pos >= m_Limit) | ||
if (!ReadBlock()) | ||
return false; | ||
b = m_Buffer[m_Pos++]; | ||
return true; | ||
} | ||
|
||
public byte ReadByte() | ||
{ | ||
// return (byte)m_Stream.ReadByte(); | ||
if (m_Pos >= m_Limit) | ||
if (!ReadBlock()) | ||
return 0xFF; | ||
return m_Buffer[m_Pos++]; | ||
} | ||
|
||
public ulong GetProcessedSize() | ||
{ | ||
return m_ProcessedSize + m_Pos; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// OutBuffer.cs | ||
|
||
namespace SevenZip.Buffer | ||
{ | ||
internal class OutBuffer | ||
{ | ||
byte[] m_Buffer; | ||
uint m_Pos; | ||
uint m_BufferSize; | ||
System.IO.Stream m_Stream; | ||
ulong m_ProcessedSize; | ||
|
||
public OutBuffer(uint bufferSize) | ||
{ | ||
m_Buffer = new byte[bufferSize]; | ||
m_BufferSize = bufferSize; | ||
} | ||
|
||
public void SetStream(System.IO.Stream stream) { m_Stream = stream; } | ||
public void FlushStream() { m_Stream.Flush(); } | ||
public void CloseStream() { m_Stream.Close(); } | ||
public void ReleaseStream() { m_Stream = null; } | ||
|
||
public void Init() | ||
{ | ||
m_ProcessedSize = 0; | ||
m_Pos = 0; | ||
} | ||
|
||
public void WriteByte(byte b) | ||
{ | ||
m_Buffer[m_Pos++] = b; | ||
if (m_Pos >= m_BufferSize) | ||
FlushData(); | ||
} | ||
|
||
public void FlushData() | ||
{ | ||
if (m_Pos == 0) | ||
return; | ||
m_Stream.Write(m_Buffer, 0, (int)m_Pos); | ||
m_Pos = 0; | ||
} | ||
|
||
public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// IMatchFinder.cs | ||
|
||
using System; | ||
|
||
namespace SevenZip.Compression.LZ | ||
{ | ||
interface IInWindowStream | ||
{ | ||
void SetStream(System.IO.Stream inStream); | ||
void Init(); | ||
void ReleaseStream(); | ||
Byte GetIndexByte(Int32 index); | ||
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit); | ||
UInt32 GetNumAvailableBytes(); | ||
} | ||
|
||
interface IMatchFinder : IInWindowStream | ||
{ | ||
void Create(UInt32 historySize, UInt32 keepAddBufferBefore, | ||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter); | ||
UInt32 GetMatches(UInt32[] distances); | ||
void Skip(UInt32 num); | ||
} | ||
} |
Oops, something went wrong.