Skip to content

Commit

Permalink
Merge pull request #18 from FlyTechVideos/new-bluescreens
Browse files Browse the repository at this point in the history
Added new bluescreens
  • Loading branch information
0xRoco authored Feb 26, 2019
2 parents 9d961b9 + d6f6bbc commit ffaea37
Show file tree
Hide file tree
Showing 38 changed files with 1,990 additions and 339 deletions.
3 changes: 3 additions & 0 deletions BluescreenSimulator/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BluescreenSimulator"
xmlns:converters="clr-namespace:BluescreenSimulator.Converters"
Startup="Application_Startup">
<Application.Resources>
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0,0" EndPoint="1,1">
Expand All @@ -13,5 +14,7 @@
<GradientStop Color="Blue" Offset="0.7"/>
<GradientStop Color="Purple" Offset="0.9"/>
</LinearGradientBrush>
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converters:EqualsVisibilityConverter x:Key="EqualsVisibilityConverter"/>
</Application.Resources>
</Application>
47 changes: 39 additions & 8 deletions BluescreenSimulator/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using BluescreenSimulator.ViewModels;
using BluescreenSimulator.Views;
using static BluescreenSimulator.Views.MainWindow;
using Color = System.Windows.Media.Color;
using ColorConverter = System.Windows.Media.ColorConverter;

namespace BluescreenSimulator
{
public partial class App : Application
Expand All @@ -23,11 +26,20 @@ public partial class App : Application

private void Application_Startup(object sender, EventArgs e)
{

DispatcherUnhandledException += (o, eventArgs) =>
{
ShowErrorMessage(eventArgs.Exception);
eventArgs.Handled = true;
};
AppDomain.CurrentDomain.UnhandledException +=
delegate (object o, UnhandledExceptionEventArgs eventArgs)
{
ShowErrorMessage(eventArgs.ExceptionObject as Exception);
};
var args = Environment.GetCommandLineArgs();
if (args.Length > 1) // #0 is file path
{
var bluescreenData = new BluescreenDataViewModel();
var bluescreenData = new Windows10BluescreenViewModel();
var showHelp = false;
var enableUnsafe = false;

Expand All @@ -40,8 +52,8 @@ private void Application_Startup(object sender, EventArgs e)
{ "mi|moreinfo=", "{Text} for More Info", t => bluescreenData.MoreInfo = t },
{ "s|supportperson=", "{Text} for Support Person", t => bluescreenData.SupportPerson = t },
{ "sc|stopcode=", "{Text} for Stop code", t => bluescreenData.StopCode = t },
{ "b|background=", "Background color in rgb {value} hex format (#FFFFFF)", r => bluescreenData.BackgroundColor = (Color)(ColorConverter.ConvertFromString(r) ?? bluescreenData.BackgroundColor) },
{ "f|foreground=", "Foreground (text) in rgb {value} hex format (#FFFFFF)", r => bluescreenData.ForegroundColor = (Color)(ColorConverter.ConvertFromString(r) ?? bluescreenData.ForegroundColor) },
{ "b|background=", "Background color in rgb {value} hex format (#FFFFFF)", r => bluescreenData.BackgroundColor = TryGetColor(r, bluescreenData.BackgroundColor) },
{ "f|foreground=", "Foreground (text) in rgb {value} hex format (#FFFFFF)", r => bluescreenData.ForegroundColor = TryGetColor(r, bluescreenData.ForegroundColor) },
{ "oq|origqr", "Use original QR code", o => bluescreenData.UseOriginalQR = o != null },
{ "hq|hideqr", "Hides the QR code", h => bluescreenData.HideQR = h != null },
{ "d|delay=", "Bluescreen Delay {duration} in seconds (0-86400)", (int d) => {
Expand Down Expand Up @@ -90,8 +102,7 @@ private void Application_Startup(object sender, EventArgs e)
}
else
{
void Act() => ShowBluescreenWindow(bluescreenData);
bluescreenData.ExecuteCommand.Execute((Action) Act);
bluescreenData.ShowView();
}
}
else
Expand All @@ -100,6 +111,26 @@ private void Application_Startup(object sender, EventArgs e)
}
}

private static MessageBoxResult ShowErrorMessage(Exception ex)
{
return MessageBox.Show($"Sorry, some error occured, {ex}", "Oops",
MessageBoxButton.OK, MessageBoxImage.Error);
}

private static Color TryGetColor(string c, Color defaultValue)
{
if (!c.StartsWith("#")) c = $"#{c}";
try
{
var color = ColorConverter.ConvertFromString(c) as Color?;
return color ?? defaultValue;
}
catch (FormatException e)
{
MessageBox.Show($"Something bad occured when parsing the color: {c}, \n {e}");
}
return defaultValue;
}
private void RunGui(bool enableUnsafe)
{
var mainWindow = new MainWindow(enableUnsafe);
Expand Down
57 changes: 55 additions & 2 deletions BluescreenSimulator/BluescreenSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,45 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="BluescreenViewAttribute.cs" />
<Compile Include="CmdParameterAttribute.cs" />
<Compile Include="Controls\ColorPickerForm.xaml.cs">
<DependentUpon>ColorPickerForm.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\EqualsVisibilityConverter.cs" />
<Compile Include="Converters\NotConverter.cs" />
<Compile Include="DelegateCommand.cs" />
<Compile Include="ViewModels\BluescreenDataViewModel.cs" />
<Compile Include="Models\BluescreenBase.cs" />
<Compile Include="Models\Windows7Bluescreen.cs" />
<Compile Include="Models\Windows9xBluescreen.cs" />
<Compile Include="Properties\Windows10BluescreenResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Windows10BluescreenResources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Windows7BluescreenResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Windows7BluescreenResources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Windows9xBluescreenResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Windows9xBluescreenResources.resx</DependentUpon>
</Compile>
<Compile Include="Resolution.cs" />
<Compile Include="ViewModels\BluescreenViewModelBase.cs" />
<Compile Include="ViewModels\IBluescreenViewModel.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="ViewModels\Windows10BluescreenViewModel.cs" />
<Compile Include="ViewModels\Windows9xBluescreenViewModel.cs" />
<Compile Include="Views\BluescreenWindow9x.xaml.cs">
<DependentUpon>BluescreenWindow9x.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\Windows7BluescreenViewModel.cs" />
<Compile Include="Views\BluescreenWindowWin7.xaml.cs">
<DependentUpon>BluescreenWindowWin7.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ColorChooserWindow.xaml.cs">
<DependentUpon>ColorChooserWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -138,10 +170,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\BluescreenWindowWin7.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\BluescreenWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\BluescreenWindow9x.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ColorChooserWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -164,7 +204,7 @@
<Compile Include="Views\BluescreenWindow.xaml.cs">
<DependentUpon>BluescreenWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Models\BluescreenData.cs" />
<Compile Include="Models\Windows10Bluescreen.cs" />
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand All @@ -190,6 +230,18 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Windows10BluescreenResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Windows10BluescreenResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Windows7BluescreenResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Windows7BluescreenResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Windows9xBluescreenResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Windows9xBluescreenResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="BluescreenSimulator Key.pfx" />
<None Include="BluescreenSimulator_TemporaryKey.pfx" />
<None Include="Properties\app.manifest" />
Expand All @@ -198,6 +250,7 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<Resource Include="Resources\Perfect DOS VGA 437 Win.ttf" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
38 changes: 38 additions & 0 deletions BluescreenSimulator/BluescreenViewAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Reflection;
using System.Windows;
using BluescreenSimulator.ViewModels;

namespace BluescreenSimulator
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class BluescreenViewAttribute : Attribute
{
public Type WindowType { get; set; }
public BluescreenViewAttribute(Type windowType)
{
WindowType = windowType;
}
}

public static class BluescreenExtensions
{
public static void ShowView(this IBluescreenViewModel bluescreen)
{
var attribute = bluescreen.GetType().GetCustomAttribute<BluescreenViewAttribute>();
if (attribute is null) throw new InvalidOperationException("No BluescreenViewAttribute has been found");
var type = attribute.WindowType;

void DispatcherWindowShow()
{
Application.Current.Dispatcher.Invoke(() =>
{
var window = (Window) Activator.CreateInstance(type, bluescreen);
window.Show();
return window;
});
}
bluescreen.ExecuteCommand.Execute((Action)DispatcherWindowShow);
}
}
}
20 changes: 20 additions & 0 deletions BluescreenSimulator/Converters/EqualsVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace BluescreenSimulator.Converters
{
public class EqualsVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == parameter ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != parameter ? Visibility.Visible : Visibility.Collapsed;
}
}
}
18 changes: 18 additions & 0 deletions BluescreenSimulator/Models/BluescreenBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows.Media;

namespace BluescreenSimulator
{
public class BluescreenBase
{
public string CmdCommand { get; set; } = null;

public virtual Color BackgroundColor { get; set; } = Color.FromRgb(10, 112, 169);

public virtual Color ForegroundColor { get; set; } = Colors.White;

public int Delay { get; set; } = 0;
public bool EnableUnsafe { get; set; } = false;

public bool RainbowMode { get; set; } = false;
}
}
37 changes: 0 additions & 37 deletions BluescreenSimulator/Models/BluescreenData.cs

This file was deleted.

25 changes: 25 additions & 0 deletions BluescreenSimulator/Models/Windows10Bluescreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Windows.Media;
using Strings = BluescreenSimulator.Properties.Windows10BluescreenResources;
namespace BluescreenSimulator
{
public class Windows10Bluescreen : BluescreenBase
{
public string Emoticon { get; set; } = Strings.Emoticon;

public string MainText1 { get; set; } = Strings.MainText1;

public string MainText2 { get; set; } = Strings.MainText2;

public string Complete { get; set; } = Strings.Complete;

public string MoreInfo { get; set; } = Strings.MoreInfo;

public string SupportPerson { get; set; } = Strings.SupportPerson;

public string StopCode { get; set; } = Strings.StopCode;

public bool HideQR { get; set; } = false;

public bool UseOriginalQR { get; set; }
}
}
26 changes: 26 additions & 0 deletions BluescreenSimulator/Models/Windows7Bluescreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Windows.Media;
using Strings = BluescreenSimulator.Properties.Windows7BluescreenResources;
namespace BluescreenSimulator
{
public class Windows7Bluescreen : BluescreenBase
{
public string Header { get; set; } = Strings.Header;

public string ErrorCode { get; set; } = Strings.ErrorCode;

public string StepsHeader { get; set; } = Strings.StepsHeader;

public string Steps { get; set; } = Strings.Steps;

public string TechnicalInfoHeader { get; set; } = Strings.TechnicalInfoHeader;
public string StopCode { get; set; } = Strings.StopCode;
public string DumpStart { get; set; } = Strings.DumpStart;

public string DumpProgress { get; set; } = Strings.DumpProgress;

public string DumpComplete { get; set; } = Strings.DumpComplete;


public override Color BackgroundColor { get; set; } = Colors.DarkBlue;
}
}
Loading

0 comments on commit ffaea37

Please sign in to comment.