ied206/ManagedWimLib

Best way to get an overall % when ExtractImage

Closed this issue · 3 comments

Hello! First of all, thanks for this wonderful wrapper :)

I'm trying to report a % while the image is being extracted. I first thought that I could get it taking a look to the ProgressInfo_Extract propertires CurrentFileCount and EndFileCount, but I was wrong.

I'm no longer sure about how to calculate the global % of the progress. How can I do it?

Thanks in advance!

Wimlib takes 3 steps to apply the image, and each of the steps has it's own ProgressInfo_Extract.
In my case, I assigned a coefficient to each step to calculate global progress.

  1. ProgressMsg.EXTRACT_FILE_STRUCTURE : 0-10%
  2. ProgressMsg.EXTRACT_STREAMS : 10-90%
  3. ProgressMsg.EXTRACT_METADATA : 90-100%

Example

switch (msg)
{
  case ProgressMsg.EXTRACT_FILE_STRUCTURE:
    { // Used file count
      ProgressInfo_Extract m = (ProgressInfo_Extract)info;

      if (0 < m.EndFileCount)
      {
        ulong percentComplete = m.CurrentFileCount * 10 / m.EndFileCount;
        s.MainViewModel.BuildCommandProgressValue = percentComplete;
        s.MainViewModel.BuildCommandProgressText = $"[Stage 1] Creating files... ({percentComplete}%)";
      }
    }
    break;
  case ProgressMsg.EXTRACT_STREAMS:
    { // Used bytes
      ProgressInfo_Extract m = (ProgressInfo_Extract)info;

      if (0 < m.TotalBytes)
      {
        ulong percentComplete = 10 + m.CompletedBytes * 80 / m.TotalBytes;
        s.MainViewModel.BuildCommandProgressValue = percentComplete;
        s.MainViewModel.BuildCommandProgressText = $"[Stage 2] Extracting file data... ({percentComplete}%)";
      }
    }
    break;
  case ProgressMsg.EXTRACT_METADATA:
    { // Used count
      ProgressInfo_Extract m = (ProgressInfo_Extract)info;

      if (0 < m.EndFileCount)
      {
        ulong percentComplete = 90 + m.CurrentFileCount * 10 / m.EndFileCount;
        s.MainViewModel.BuildCommandProgressValue = percentComplete;
        s.MainViewModel.BuildCommandProgressText = $"[Stage 3] Applying metadata to files... ({percentComplete}%)";
      }
    }
    break;
}
return CallbackStatus.CONTINUE;

Thank you! I'm about to try it!

Closing the issue.