private static WindowsImageIndex[] IdentifyWindowsNTFromRootFs(TxtSetupBridge fileSystem)
        {
            RootFsInstallProviderInterface provider = new RootFsInstallProviderInterface(fileSystem);

            var report = InstalledImage.DetectionHandler.IdentifyWindowsNT(provider);

            report.Sku = fileSystem.GetSkuFromTxtSetupMedia(report.BuildNumber);
            report     = InstalledImage.DetectionHandler.FixSkuNames(report, false);

            Common.DisplayReport(report);

            var index = new WindowsImageIndex()
            {
                WindowsImage = report
            };

            return(new WindowsImageIndex[] { index });
        }
        private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bool include_pe)
        {
            HashSet <WindowsImageIndex> results = new HashSet <WindowsImageIndex>();

            Console.WriteLine("Gathering WIM information XML file");

            string xml = ExtractWIMXml(wimstream);

            Console.WriteLine("Parsing WIM information XML file");
            XmlFormats.WIMXml.WIM wim = GetWIMClassFromXml(xml);

            Console.WriteLine($"Found {wim.IMAGE.Length} images in the wim according to the XML");

            Console.WriteLine("Evaluating relevant images in the WIM according to the XML");
            int irelevantcount2 = (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0);

            Console.WriteLine($"Found {irelevantcount2} irrelevant images in the wim according to the XML");

            foreach (var image in wim.IMAGE)
            {
                Console.WriteLine();
                Console.WriteLine($"Processing index {image.INDEX}");

                //
                // If what we're trying to identify isn't just a winpe, and we are accessing a winpe image
                // skip the image
                //
                int irelevantcount = (image.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0);

                Console.WriteLine($"Index contains {irelevantcount} flags indicating this is a preinstallation environment");

                if (!include_pe && irelevantcount != 0 && irelevantcount2 < wim.IMAGE.Length)
                {
                    Console.WriteLine("Skipping this image");
                    continue;
                }

                string index = wim.IMAGE.Count() == 1 ? null : image.INDEX;

                bool WorkaroundForWIMFormatBug = false;

                if (index != null && wim.IMAGE[0].INDEX == "0")
                {
                    using ArchiveFile archiveFile = new ArchiveFile(wimstream, SevenZipFormat.Wim);
                    if (!archiveFile.Entries.Any(x => x.FileName.StartsWith("0\\")))
                    {
                        WorkaroundForWIMFormatBug = true;
                    }
                }

                if (WorkaroundForWIMFormatBug)
                {
                    int t = int.Parse(index);
                    index = (++t).ToString();
                }

                Console.WriteLine($"Index value: {index}");

                var provider = new WIMInstallProviderInterface(wimstream, index);

                var report = InstalledImage.DetectionHandler.IdentifyWindowsNT(provider);

                provider.Close();

                // fallback
                if ((string.IsNullOrEmpty(report.Sku) || report.Sku == "TerminalServer") && !string.IsNullOrEmpty(image.FLAGS))
                {
                    Console.WriteLine("WARNING: Falling back to WIM XML for edition gathering");

                    report.Sku = image.FLAGS;

                    report.Types = new HashSet <Type>();

                    if ((report.Sku.Contains("server", StringComparison.InvariantCultureIgnoreCase) && report.Sku.EndsWith("hyperv", StringComparison.InvariantCultureIgnoreCase)) ||
                        (report.Sku.Contains("server", StringComparison.InvariantCultureIgnoreCase) && report.Sku.EndsWith("v", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        if (!report.Types.Contains(Type.ServerV))
                        {
                            report.Types.Add(Type.ServerV);
                        }
                    }
                    else if (report.Sku.Contains("server", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!report.Types.Contains(Type.Server))
                        {
                            report.Types.Add(Type.Server);
                        }
                    }
                    else
                    {
                        if (!report.Types.Contains(Type.Client))
                        {
                            report.Types.Add(Type.Client);
                        }
                    }
                }

                Common.DisplayReport(report);

                WindowsImageIndex imageIndex = new WindowsImageIndex();

                imageIndex.Name        = image.NAME;
                imageIndex.Description = image.DESCRIPTION;

                if (image.CREATIONTIME != null)
                {
                    var creationtime = Convert.ToInt32(image.CREATIONTIME.HIGHPART, 16) * 4294967296 + Convert.ToInt32(image.CREATIONTIME.LOWPART, 16);
                    var cTime        = DateTime.FromFileTimeUtc(creationtime);
                    imageIndex.CreationTime = cTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                }

                if (image.LASTMODIFICATIONTIME != null)
                {
                    var creationtime = Convert.ToInt32(image.LASTMODIFICATIONTIME.HIGHPART, 16) * 4294967296 + Convert.ToInt32(image.LASTMODIFICATIONTIME.LOWPART, 16);
                    var cTime        = DateTime.FromFileTimeUtc(creationtime);
                    imageIndex.LastModifiedTime = cTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                }

                imageIndex.WindowsImage = report;

                results.Add(imageIndex);
            }

            wimstream.Dispose();

            return(results.ToArray());
        }