Exemplo n.º 1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            string language      = UserSettings.PlayerConfig.HunterPie.Language.Split('\\').LastOrDefault().Replace(".xml", "");
            string changelogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Changelog\\changelog-{language}.md");

            if (!File.Exists(changelogPath))
            {
                changelogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Changelog\\changelog-en-us.md");
            }

            if (!File.Exists(changelogPath))
            {
                return;
            }

            string markdown = File.ReadAllText(changelogPath);
            string xaml     = Markdown.ToXaml(markdown, BuildPipeline());

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
            {
                using (var reader = new XamlXmlReader(stream, new MyXamlSchemaContext()))
                {
                    if (XamlReader.Load(reader) is FlowDocument document)
                    {
                        Viewer.Document = document;
                    }
                }
            }
        }
        //Event handlers

        /**
         * Sets the mod description to a markdown formatted document
         */
        private void SetModDetails(object sender, SelectionChangedEventArgs e)
        {
            Mod mod = (Mod)((DataGrid)sender).SelectedItem;

            if (mod.LogoURL == "")
            {
                LogoImage.Source = (ImageSource) new ImageSourceConverter().ConvertFrom(Properties.Resources.NotFound);
            }
            else
            {
                LogoImage.Source = new BitmapImage(new Uri(mod.LogoURL));
            }

            DownloadButton.IsEnabled = true;

            //Source: https://github.com/Kryptos-FR/markdig.wpf/blob/master/src/Markdig.Xaml.SampleApp/MainWindow.xaml.cs#L36
            //Sets the mod details view with the markdown rendered content
            using MemoryStream stream =
                      new MemoryStream(Encoding.UTF8.GetBytes(
                                           Markdown.ToXaml(mod.FullDescription, new MarkdownPipelineBuilder().UseSupportedExtensions().Build())));
            using XamlXmlReader reader = new XamlXmlReader(stream, new XamlSchemaContext());
            if (XamlReader.Load(reader) is FlowDocument document)
            {
                ModDescription.Document = document;
            }
        }