public void ProcessNestedArchives()

in src/managed/DiffGen/ArchiveUtility/ArchiveTokenization.cs [309:387]


        public void ProcessNestedArchives(Stream stream, ArchiveUseCase useCase)
        {
            // Not useful to get detailed view of nested items if we can't reconstruct this archive from them
            if ((useCase == ArchiveUseCase.DiffTarget) && !ForwardRecipes.ContainsKey(ArchiveItem))
            {
                return;
            }

            List<Tuple<ItemDefinition, string, string>> potentialNestedArchives = new();

            foreach (var payloadEntry in PayloadCatalog.Entries)
            {
                Payload payload = payloadEntry.Key;

                if (!payload.ArchiveItem.Equals(ArchiveItem))
                {
                    continue;
                }

                var payloadName = payload.Name;

                foreach (var extInfo in ArchiveExtensions)
                {
                    var ext = extInfo[0];
                    var archiveType = extInfo[1];
                    if (payloadName.EndsWith(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        var payloadItems = payloadEntry.Value;
                        foreach (var item in payloadItems)
                        {
                            potentialNestedArchives.Add(new(item, payloadName, archiveType));
                            break;
                        }
                    }
                }
            }

            using (FileFromStream file = new FileFromStream(stream, WorkingFolder))
            {
                string archivePath = file.Name;

                if (!TryExtractItems(ArchiveLoaderContext.DefaultLogger, archivePath, potentialNestedArchives.Select(n => n.Item1)))
                {
                    throw new Exception($"Couldn't extract items for nested archives for: {archivePath}");
                }
            }

            foreach (var nested in potentialNestedArchives)
            {
                var (nestedItem, payloadName, type) = nested;

                var archiveFile = nestedItem.GetExtractionPath(ItemFolder);

                using var archiveStream = File.OpenRead(archiveFile);

                ArchiveLoaderContext context = new(archiveStream, WorkingFolder, ArchiveLoaderContext.DefaultLogger, LogLevel.None)
                {
                    UseCase = useCase,
                };

                context.OriginalArchiveFileName = payloadName;

                if (ArchiveLoader.TryLoadArchive(context, out ArchiveTokenization tokens, type))
                {
                    context.Logger?.LogInformation("Loaded nested archive of type: {type}", type);

                    string nestedJson = tokens.ArchiveItem.GetExtractionPath(context.WorkingFolder) + $".{type}.json";

                    context.Logger?.LogInformation("Writing nested json to {NestedJson}", nestedJson);

                    using (var nestedJsonStream = File.OpenWrite(nestedJson))
                    {
                        tokens.WriteJson(nestedJsonStream, true);
                    }

                    ImportArchive(context.Logger, tokens);
                }
            }
        }