129 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			129 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Diagnostics;
 | |
| using System.IO;
 | |
| using System.Reflection;
 | |
| using System.Text;
 | |
| using System.Windows;
 | |
| using System.Windows.Documents;
 | |
| using System.Xaml;
 | |
| using DerpingDrivers.Util;
 | |
| using MahApps.Metro.Controls;
 | |
| using Markdig;
 | |
| using Markdig.Wpf;
 | |
| using Markdown = Markdig.Wpf.Markdown;
 | |
| using XamlReader = System.Windows.Markup.XamlReader;
 | |
| 
 | |
| namespace DerpingDrivers
 | |
| {
 | |
|     /// <summary>
 | |
|     ///     Interaction logic for MainWindow.xaml
 | |
|     /// </summary>
 | |
|     public partial class MainWindow : MetroWindow
 | |
|     {
 | |
|         public MainWindow()
 | |
|         {
 | |
|             InitializeComponent();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Operating System Architecture display name.
 | |
|         /// </summary>
 | |
|         public string OsArchitecture =>
 | |
|             OsVersionInfo.OsBits == OsVersionInfo.SoftwareArchitecture.Bit64 ? "64-bit" : "32-bit";
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Operating System display name.
 | |
|         /// </summary>
 | |
|         public string OsVersionName => OsVersionInfo.Name;
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Operating System edition name.
 | |
|         /// </summary>
 | |
|         public string OsEditionName => string.IsNullOrEmpty(OsVersionInfo.Edition) ? "None" : OsVersionInfo.Edition;
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Operating System build number.
 | |
|         /// </summary>
 | |
|         public string OsVersion => OsVersionInfo.VersionString;
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Boot mode (Legacy BIOS, UEFI).
 | |
|         /// </summary>
 | |
|         public string BootMode => UEFIHelper.IsRunningInUEFIMode ? "UEFI" : "Legacy BIOS";
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets Secure Boot status.
 | |
|         /// </summary>
 | |
|         public string SecureBootEnabled => UEFIHelper.IsRunningInUEFIMode
 | |
|             ? (UEFIHelper.IsSecureBootEnabled ? "Enabled" : "Disabled")
 | |
|             : "Not available";
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets OS upgrade status.
 | |
|         /// </summary>
 | |
|         public string OsUpgradeStatus =>
 | |
|             OsUpgradeDetection.IsGrandfathered ? "In-place upgraded" : "Clean installation";
 | |
| 
 | |
|         /// <summary>
 | |
|         ///     Gets test-mode status.
 | |
|         /// </summary>
 | |
|         public string TestSigningStatus => CodeIntegrityHelper.IsTestSignEnabled ? "Enabled" : "Disabled";
 | |
| 
 | |
|         public FlowDocument SummaryDocument
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 var markdown = "🔥 *None available*";
 | |
| 
 | |
|                 // Convert Markdown to XAML
 | |
|                 var xaml = Markdown.ToXaml(markdown, BuildPipeline());
 | |
| 
 | |
|                 // Render XAML for FlowDocument Control 
 | |
|                 using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
 | |
|                 {
 | |
|                     var reader = new XamlXmlReader(stream, new MyXamlSchemaContext());
 | |
| 
 | |
|                     if (XamlReader.Load(reader) is FlowDocument document) return document;
 | |
|                 }
 | |
| 
 | |
|                 return null;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private static MarkdownPipeline BuildPipeline()
 | |
|         {
 | |
|             return new MarkdownPipelineBuilder()
 | |
|                 .UseSupportedExtensions()
 | |
|                 .Build();
 | |
|         }
 | |
| 
 | |
|         private void Web_OnClick(object sender, RoutedEventArgs e)
 | |
|         {
 | |
|             Process.Start("https://vigem.org");
 | |
|         }
 | |
| 
 | |
|         private void Discord_OnClick(object sender, RoutedEventArgs e)
 | |
|         {
 | |
|             Process.Start("https://discord.vigem.org");
 | |
|         }
 | |
| 
 | |
|         private void Forums_OnClick(object sender, RoutedEventArgs e)
 | |
|         {
 | |
|             Process.Start("https://forums.vigem.org");
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     internal class MyXamlSchemaContext : XamlSchemaContext
 | |
|     {
 | |
|         public override bool TryGetCompatibleXamlNamespace(string xamlNamespace, out string compatibleNamespace)
 | |
|         {
 | |
|             if (xamlNamespace.Equals("clr-namespace:Markdig.Wpf"))
 | |
|             {
 | |
|                 compatibleNamespace =
 | |
|                     $"clr-namespace:Markdig.Wpf;assembly={Assembly.GetAssembly(typeof(Styles)).FullName}";
 | |
|                 return true;
 | |
|             }
 | |
| 
 | |
|             return base.TryGetCompatibleXamlNamespace(xamlNamespace, out compatibleNamespace);
 | |
|         }
 | |
|     }
 | |
| } |