/// <summary>
        /// Path definition to catch known name clashes for instance
        /// </summary>
        private static void PatchDefinition(YamlDefinition yamlDefinition, string folder, string file)
        {
            if (file == "10_ping.yaml")
            {
                yamlDefinition.Suites.First().Description = "Ping returns true";
            }
            if (file == "55_parent_with_routing.yaml")
            {
                yamlDefinition.Suites.First().Description = "Parent with routing";
            }
            if (file == "10_info.yaml")
            {
                yamlDefinition.Suites.First().Description = "Info returns body";
            }
            if (file == "20_fields_pre_0.90.3.yaml")
            {
                yamlDefinition.Suites.First().Description = "Fields Pre 0.90.3";
            }

            var setupRoutine = yamlDefinition.Suites
                               .FirstOrDefault(s => s.Description.Contains("setup"));

            if (setupRoutine != null)
            {
                yamlDefinition.SetupSuite = setupRoutine;
                foreach (var suite in yamlDefinition.Suites)
                {
                    suite.HasSetup = true;
                }
                yamlDefinition.Suites = yamlDefinition.Suites.Where(s => !s.Description.Contains("setup"));
            }
        }
示例#2
0
        // ReSharper disable once MemberCanBeMadeStatic.Local
        private YamlDefinition CreateFromExe(string filePath)
        {
            var fileVersionInfo = FileVersionInfo.GetVersionInfo(filePath);
            var yamlDefinition  = new YamlDefinition
            {
                Name        = fileVersionInfo.ProductName?.Trim(),
                Version     = fileVersionInfo.ProductVersion?.Trim(),
                Publisher   = fileVersionInfo.CompanyName?.Trim(),
                Description = fileVersionInfo.FileDescription?.Trim(),
                License     = fileVersionInfo.LegalCopyright ?? fileVersionInfo.LegalTrademarks,
                Installers  = new List <YamlInstaller>
                {
                    new YamlInstaller
                    {
                        InstallerType = YamlInstallerType.exe
                    }
                }
            };

            if (yamlDefinition.License != null)
            {
                yamlDefinition.License = yamlDefinition.License.Trim();
                if (string.IsNullOrWhiteSpace(yamlDefinition.License))
                {
                    yamlDefinition.License = null;
                }
            }

            using (var fs = File.OpenRead(filePath))
            {
                using (var binaryReader = new BinaryReader(fs))
                {
                    var mz = binaryReader.ReadUInt16();
                    if (mz == 0x5a4d)     // check if it's a valid image ("MZ")
                    {
                        fs.Position = 60; // this location contains the offset for the PE header
                        var offset = binaryReader.ReadUInt32();

                        fs.Position = offset + sizeof(uint); // contains the architecture
                        var machine = binaryReader.ReadUInt16();

                        if (machine == 0x8664) // IMAGE_FILE_MACHINE_AMD64
                        {
                            yamlDefinition.Installers[0].Arch = YamlArchitecture.x64;
                        }
                        else if (machine == 0x014c) // IMAGE_FILE_MACHINE_I386
                        {
                            yamlDefinition.Installers[0].Arch = YamlArchitecture.x86;
                        }
                        else if (machine == 0x0200) // IMAGE_FILE_MACHINE_IA64
                        {
                            yamlDefinition.Installers[0].Arch = YamlArchitecture.x64;
                        }
                    }
                }
            }

            return(yamlDefinition);
        }
示例#3
0
        public async Task <YamlDefinition> CreateFromFile(string filePath, CancellationToken cancellationToken = default)
        {
            var detector = new InstallerTypeDetector();
            var detected = await detector.DetectSetupType(filePath, cancellationToken).ConfigureAwait(false);

            YamlDefinition yaml;

            switch (detected)
            {
            case YamlInstallerType.msi:
                yaml = await Task.Run(() => this.CreateFromMsi(filePath), cancellationToken).ConfigureAwait(false);

                break;

            case YamlInstallerType.none:
            case YamlInstallerType.exe:
            case YamlInstallerType.inno:
            case YamlInstallerType.nullsoft:
            case YamlInstallerType.wix:
                yaml = await Task.Run(() => this.CreateFromExe(filePath), cancellationToken).ConfigureAwait(false);

                yaml.Installers[0].InstallerType = detected;
                break;

            case YamlInstallerType.msix:
            case YamlInstallerType.appx:
                yaml = await this.CreateFromMsix(filePath, cancellationToken).ConfigureAwait(false);

                yaml.Installers[0].InstallerType = detected;
                yaml.MinOperatingSystemVersion   = Version.Parse("10.0.0");
                break;

            default:
                yaml = new YamlDefinition
                {
                    Installers = new List <YamlInstaller>
                    {
                        new YamlInstaller()
                    }
                };
                break;
            }

            yaml.Id = (yaml.Publisher + "." + yaml.Name).Replace(" ", string.Empty);
            yaml.Installers[0].Sha256 = await this.CalculateHashAsync(new FileInfo(filePath), cancellationToken).ConfigureAwait(false);

            if (yaml.License != null && yaml.License.IndexOf("Copy", StringComparison.OrdinalIgnoreCase) == -1 && yaml.License.IndexOf("(C)", StringComparison.OrdinalIgnoreCase) == -1 && yaml.License.IndexOf("http", StringComparison.OrdinalIgnoreCase) == -1)
            {
                yaml.License = "Copyright (C) " + yaml.License;
            }

            return(yaml);
        }
示例#4
0
        /// <summary>
        /// Writes the given YAML definition to a text writer.
        /// </summary>
        /// <param name="definition">The YAML definition.</param>
        /// <param name="textWriter">The text writer where the content will be written.</param>
        public void Write(YamlDefinition definition, TextWriter textWriter)
        {
            var serializer    = new Serializer();
            var stringBuilder = new StringBuilder();

            using (var stringWriter = new StringWriter(stringBuilder))
            {
                serializer.Serialize(stringWriter, definition);
            }

            stringBuilder.AppendLine();
            stringBuilder.AppendLine("# Edited with MSIX Hero");

            var serialized = stringBuilder.ToString();

            serialized = Regex.Replace(serialized, @"[\r\n]{2,}", Environment.NewLine);

            textWriter.Write(serialized);
        }
        private static IList <YamlDefinition> GetFolderFiles(string folder, bool useCache = false)
        {
            var url        = useCache ? LocalUri(folder + ".html") : _listingUrl + "/" + folder;
            var folderHtml = new WebClient().DownloadString(url);

            if (!useCache)
            {
                File.WriteAllText(_cacheFolder + folder + ".html", folderHtml);
            }
            var files = (from a in CQ.Create(folderHtml)[".js-directory-link"]
                         let fileName = a.InnerText
                                        where fileName.EndsWith(".yaml")
                                        select fileName).ToList();

            var definitions = new ConcurrentBag <YamlDefinition>();
            var i           = 0;

            foreach (var file in files)
            {
                ++i;

                if (SkipTests.Contains(folder + "/" + file))
                {
                    continue;
                }

                var yaml           = GetYamlFile(folder, useCache, file);
                var parsed         = ParseYaml(yaml).ToList();
                var prefix         = Regex.Replace(file, @"^(\d+).*$", "$1");
                var yamlDefinition = new YamlDefinition
                {
                    Folder   = folder + i,
                    FileName = file,
                    Contents = yaml,
                    Suites   = parsed,
                    Suffix   = prefix
                };
                PatchDefinition(yamlDefinition, folder, file);
                definitions.Add(yamlDefinition);
            }
            return(definitions.ToList());
        }
示例#6
0
        /// <summary>
        /// Writes the given YAML definition to a given text writer and returns a task that represents the asynchronous operation.
        /// </summary>
        /// <param name="definition">The YAML definition.</param>
        /// <param name="textWriter">The text writer where the content will be written.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public async Task WriteAsync(YamlDefinition definition, TextWriter textWriter, CancellationToken cancellationToken = default)
        {
            var serializerBuilder = new SerializerBuilder().WithEmissionPhaseObjectGraphVisitor(args => new DefaultExclusiveObjectGraphVisitor(args.InnerVisitor));
            var serializer        = serializerBuilder.Build();

            var stringBuilder = new StringBuilder();

            using (var stringWriter = new StringWriter(stringBuilder))
            {
                serializer.Serialize(stringWriter, definition);
            }

            cancellationToken.ThrowIfCancellationRequested();

            stringBuilder.AppendLine();
            stringBuilder.AppendLine("# Edited with MSIX Hero");

            cancellationToken.ThrowIfCancellationRequested();
            var serialized = stringBuilder.ToString();

            serialized = Regex.Replace(serialized, @"[\r\n]{2,}", Environment.NewLine);
            await textWriter.WriteAsync(serialized).ConfigureAwait(false);
        }
示例#7
0
        public static void GenerateTestFileFromView(string targetFile, YamlDefinition model)
        {
            var source = _razorMachine.Execute(File.ReadAllText(_viewFolder + @"TestSuite.cshtml"), model).ToString();

            File.WriteAllText(targetFile, source);
        }
示例#8
0
 /// <summary>
 /// Writes the given YAML definition to a stream and returns an asynchronous task.
 /// </summary>
 /// <param name="definition">The YAML definition.</param>
 /// <param name="stream">The stream where to write the YAML content.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 public async Task WriteAsync(YamlDefinition definition, Stream stream, CancellationToken cancellationToken = default)
 {
     await using var textWriter = new StreamWriter(stream, leaveOpen: true);
     await this.WriteAsync(definition, textWriter, cancellationToken).ConfigureAwait(false);
 }
示例#9
0
        private async Task <YamlDefinition> CreateFromMsix(string filePath, CancellationToken cancellationToken = default)
        {
            var yamlDefinition = new YamlDefinition()
            {
                Installers = new List <YamlInstaller>
                {
                    new YamlInstaller
                    {
                        Scope         = YamlScope.user,
                        InstallerType = YamlInstallerType.msix
                    }
                }
            };

            IAppxFileReader reader;

            if (filePath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
            {
                reader = new FileInfoFileReaderAdapter(filePath);
            }
            else
            {
                reader = new ZipArchiveFileReaderAdapter(filePath);

                try
                {
                    yamlDefinition.Installers[0].SignatureSha256 = await this.CalculateSignatureHashAsync(new FileInfo(filePath), cancellationToken).ConfigureAwait(false);
                }
                catch (ArgumentException)
                {
                }
            }

            using (reader)
            {
                var manifestReader = new AppxManifestReader();
                var details        = await manifestReader.Read(reader, cancellationToken).ConfigureAwait(false);

                yamlDefinition.Name        = details.DisplayName;
                yamlDefinition.Publisher   = details.PublisherDisplayName;
                yamlDefinition.Version     = details.Version;
                yamlDefinition.Description = details.Description;

                if (details.Applications?.Any() == true)
                {
                    // Exclude some unrelated PSF stuff - they are not the right choice for the app moniker.
                    var candidateForAppMoniker = details.Applications.Select(a => a.Executable)
                                                 .FirstOrDefault(a =>
                                                                 !string.IsNullOrEmpty(a) && !a.StartsWith("psf", StringComparison.OrdinalIgnoreCase) &&
                                                                 !a.StartsWith("AI_stubs", StringComparison.OrdinalIgnoreCase) &&
                                                                 a.EndsWith(".exe", StringComparison.OrdinalIgnoreCase));

                    if (!string.IsNullOrEmpty(candidateForAppMoniker))
                    {
                        yamlDefinition.AppMoniker = candidateForAppMoniker.Substring(0, candidateForAppMoniker.Length - ".exe".Length).Split('\\', '/').Last();
                    }
                }

                switch (details.ProcessorArchitecture)
                {
                case AppxPackageArchitecture.Arm:
                    yamlDefinition.Installers[0].Arch = YamlArchitecture.arm;
                    break;

                case AppxPackageArchitecture.Neutral:
                    yamlDefinition.Installers[0].Arch = YamlArchitecture.Neutral;
                    break;

                case AppxPackageArchitecture.Arm64:
                    yamlDefinition.Installers[0].Arch = YamlArchitecture.arm64;
                    break;

                case AppxPackageArchitecture.x86:
                    yamlDefinition.Installers[0].Arch = YamlArchitecture.x86;
                    break;

                case AppxPackageArchitecture.x64:
                    yamlDefinition.Installers[0].Arch = YamlArchitecture.x64;
                    break;
                }
            }

            return(yamlDefinition);
        }