public void ExtractItems()

in src/managed/DiffGen/ArchiveUtility/ArchiveTokenization.cs [656:728]


        public void ExtractItems(ILogger logger, string archivePath, IEnumerable<ItemDefinition> toExtract)
        {
            using var createSession = new DiffApi.DiffcSession();
            createSession.SetTarget(ArchiveItem);

            var extractionRoot = ItemFolder;

            int recipeCount = 0;
            foreach (var entry in RecipeCatalog.Entries)
            {
                var recipes = entry.Value;
                foreach (var recipe in recipes)
                {
                    recipeCount++;
                    createSession.AddRecipe(recipe);
                }
            }

            using var applySession = createSession.NewApplySession();

            logger?.LogInformation("Trying to extract {toExtractCount:N0} items from {archivePath} using {recipeCount:N0} recipes.", toExtract.Count(), archivePath, recipeCount);

            foreach (var item in toExtract)
            {
                var itemPath = item.GetExtractionPath(extractionRoot);
                applySession.RequestItem(item);
            }

            applySession.AddItemToPantry(archivePath);

            if (!applySession.ProcessRequestedItems())
            {
                var msg = $"Can't process items from: {archivePath}";
                logger?.LogError(msg);
                throw new Exception(msg);
            }

            applySession.ResumeSlicing();

            Directory.CreateDirectory(extractionRoot);

            foreach (var item in toExtract)
            {
                var hashString = item.GetSha256HashString();
                if (hashString == null)
                {
                    var msg = "Trying to extract an item without a sha256 hash.";
                    logger?.LogError(msg);
                    throw new Exception(msg);
                }

                var itemPath = item.GetExtractionPath(extractionRoot);
                applySession.ExtractItemToPath(item, itemPath);

                var fromFile = ItemDefinition.FromFile(itemPath);
            }

            applySession.CancelSlicing();

            foreach (var item in toExtract)
            {
                var itemPath = item.GetExtractionPath(extractionRoot);
                var fromFile = ItemDefinition.FromFile(itemPath);

                if (!item.Equals(fromFile))
                {
                    var msg = $"Extracted file {itemPath} mismatch from expected result. Expected: {item}, Actual: {fromFile}";
                    logger?.LogError(msg);
                    applySession.CancelSlicing();
                    throw new Exception(msg);
                }
            }
        }