/* This file is part of SevenZipSharp.
SevenZipSharp is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SevenZipSharp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SevenZipSharp. If not, see .
*/
using System;
using SevenZip.Sdk;
namespace SevenZip
{
///
/// Callback to implement the ICodeProgress interface
///
internal sealed class LzmaProgressCallback : ICodeProgress
{
private readonly long _inSize;
private float _oldPercentDone;
///
/// Initializes a new instance of the LzmaProgressCallback class
///
/// The input size
/// Progress event handler
public LzmaProgressCallback(long inSize, EventHandler working)
{
_inSize = inSize;
Working += working;
}
#region ICodeProgress Members
///
/// Sets the progress
///
/// The processed input size
/// The processed output size
public void SetProgress(long inSize, long outSize)
{
if (Working != null)
{
float newPercentDone = (inSize + 0.0f) / _inSize;
float delta = newPercentDone - _oldPercentDone;
if (delta * 100 < 1.0)
{
delta = 0;
}
else
{
_oldPercentDone = newPercentDone;
}
Working(this, new ProgressEventArgs(
PercentDoneEventArgs.ProducePercentDone(newPercentDone),
delta > 0 ? PercentDoneEventArgs.ProducePercentDone(delta) : (byte)0));
}
}
#endregion
public event EventHandler Working;
}
}