System.Collections.Generic.HashSet.Add(WindowsImageIndex)

Here are the examples of the csharp api System.Collections.Generic.HashSet.Add(WindowsImageIndex) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : MediaHandler.cs
with MIT License
from gus33000

private static WindowsImageIndex[] IdentifyWindowsNTFromWim(Stream wimstream, bool includePe)
        {
            HashSet<WindowsImageIndex> results = new();

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


            using ArchiveFile archiveFile = new(wimstream, SevenZipFormat.Wim);
            string xml = ExtractWimXml(archiveFile);

            Console.WriteLine("Parsing WIM information XML file");
            WIMXml.WIM wim = GetWimClreplacedFromXml(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 != null && x.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
                                  (wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0);

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

            WimInstallProviderInterface provider = new(archiveFile);

            foreach (WIMXml.IMAGE 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 != null && image.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION != null && image.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION != null && image.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION != null && image.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
                                     (image.DESCRIPTION != null && image.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0);

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

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

                string index = wim.IMAGE.Length == 1 ? null : image.INDEX;

                bool workaroundForWimFormatBug = false;

                if (index != null && wim.IMAGE[0].INDEX == "0")
                {
                    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}");

                provider.SetIndex(index);

                WindowsImage report = DetectionHandler.IdentifyWindowsNT(provider);

                // 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()
                {
                    Name = image.NAME,
                    Description = image.DESCRIPTION
                };

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

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

                imageIndex.WindowsImage = report;

                results.Add(imageIndex);
            }

            provider.Close();

            return results.ToArray();
        }