LzmaProgressCallback.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace SevenZip
  2. {
  3. using System;
  4. using SevenZip.Sdk;
  5. /// <summary>
  6. /// Callback to implement the ICodeProgress interface
  7. /// </summary>
  8. internal sealed class LzmaProgressCallback : ICodeProgress
  9. {
  10. private readonly long _inSize;
  11. private float _oldPercentDone;
  12. /// <summary>
  13. /// Initializes a new instance of the LzmaProgressCallback class
  14. /// </summary>
  15. /// <param name="inSize">The input size</param>
  16. /// <param name="working">Progress event handler</param>
  17. public LzmaProgressCallback(long inSize, EventHandler<ProgressEventArgs> working)
  18. {
  19. _inSize = inSize;
  20. Working += working;
  21. }
  22. #region ICodeProgress Members
  23. /// <summary>
  24. /// Sets the progress
  25. /// </summary>
  26. /// <param name="inSize">The processed input size</param>
  27. /// <param name="outSize">The processed output size</param>
  28. public void SetProgress(long inSize, long outSize)
  29. {
  30. if (Working != null)
  31. {
  32. float newPercentDone = (inSize + 0.0f) / _inSize;
  33. float delta = newPercentDone - _oldPercentDone;
  34. if (delta * 100 < 1.0)
  35. {
  36. delta = 0;
  37. }
  38. else
  39. {
  40. _oldPercentDone = newPercentDone;
  41. }
  42. Working(this, new ProgressEventArgs(
  43. PercentDoneEventArgs.ProducePercentDone(newPercentDone),
  44. delta > 0 ? PercentDoneEventArgs.ProducePercentDone(delta) : (byte)0));
  45. }
  46. }
  47. #endregion
  48. public event EventHandler<ProgressEventArgs> Working;
  49. }
  50. }