Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from erri120/extraction-progress
Browse files Browse the repository at this point in the history
Show code and decode progress
  • Loading branch information
erri120 authored Nov 30, 2019
2 parents a2255b7 + 08cc648 commit 78ee3d2
Show file tree
Hide file tree
Showing 22 changed files with 3,448 additions and 7 deletions.
1 change: 1 addition & 0 deletions OMODFramework.Example/OMODFramework.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Progress.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptFunctions.cs" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions OMODFramework.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private static void Main(string[] args)
Framework.OblivionINIFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Oblivion.ini");

Framework.CodeProgress = new Progress();

if(Directory.Exists(Framework.TempDir))
Framework.CleanTempDir();

Expand Down
28 changes: 28 additions & 0 deletions OMODFramework.Example/Progress.cs
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}");
}
}
}
}
55 changes: 55 additions & 0 deletions OMODFramework/7zip/Common/CRC.cs
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);
}
}
}
72 changes: 72 additions & 0 deletions OMODFramework/7zip/Common/InBuffer.cs
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;
}
}
}
47 changes: 47 additions & 0 deletions OMODFramework/7zip/Common/OutBuffer.cs
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; }
}
}
24 changes: 24 additions & 0 deletions OMODFramework/7zip/Compress/LZ/IMatchFinder.cs
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);
}
}
Loading

0 comments on commit 78ee3d2

Please sign in to comment.