Skip to content

Commit

Permalink
* Binding settings
Browse files Browse the repository at this point in the history
* Bumped version number
* Minor design changes
* Added a message in case the product key could not be retrieved
* Border thickness changes can now be previewed
  • Loading branch information
CodeDead committed Mar 17, 2019
1 parent 25f2980 commit 409c755
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 51 deletions.
2 changes: 1 addition & 1 deletion PK Finder/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<value>True</value>
</setting>
<setting name="WindowOpacity" serializeAs="String">
<value>1</value>
<value>100</value>
</setting>
<setting name="WindowResizeBorder" serializeAs="String">
<value>3</value>
Expand Down
3 changes: 2 additions & 1 deletion PK Finder/Classes/KeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private static string DecodeProductKeyWin8AndUp(IList<byte> digitalProductId)
digitalProductId[66] = (byte)((digitalProductId[66] & 0xf7) | (isWin8 & 2) * 4);

const string digits = "BCDFGHJKMPQRTVWXY2346789";
const string insert = "N";

int last = 0;
for (int i = 24; i >= 0; i--)
{
Expand All @@ -63,7 +65,6 @@ private static string DecodeProductKeyWin8AndUp(IList<byte> digitalProductId)
key = digits[current] + key;
}
string keyPart = key.Substring(1, last);
const string insert = "N";
key = key.Substring(1).Replace(keyPart, keyPart + insert);
if (last == 0) key = insert + key;
for (int i = 5; i < key.Length; i += 6)
Expand Down
31 changes: 31 additions & 0 deletions PK Finder/Classes/SettingsBinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Windows.Data;

namespace PK_Finder.Classes
{
/// <inheritdoc />
/// <summary>
/// Internal logic for binding settings to controls
/// </summary>
internal sealed class SettingsBinder : Binding
{

/// <inheritdoc />
/// <summary>
/// Initialize a new SettingsBinder
/// </summary>
/// <param name="path">The path that can be used to bind</param>
public SettingsBinder(string path): base(path)
{
Initialize();
}

/// <summary>
/// Initialize the SettingsBinder by applying a binding source and binding mode
/// </summary>
public void Initialize()
{
Source = Properties.Settings.Default;
Mode = BindingMode.TwoWay;
}
}
}
2 changes: 1 addition & 1 deletion PK Finder/Classes/StyleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static void ChangeStyle(DependencyObject o)
if (!(o is ChromelessWindow window)) return;
window.BorderThickness = new Thickness(Properties.Settings.Default.BorderThickness);
window.CornerRadius = new CornerRadius(0, 0, 0, 0);
window.Opacity = Properties.Settings.Default.WindowOpacity;
window.Opacity = Properties.Settings.Default.WindowOpacity / 100;
window.ResizeBorderThickness = new Thickness(Properties.Settings.Default.WindowResizeBorder);
}
catch (Exception ex)
Expand Down
1 change: 1 addition & 0 deletions PK Finder/PK Finder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="Classes\ExportManager.cs" />
<Compile Include="Classes\KeyInfo.cs" />
<Compile Include="Classes\KeyManager.cs" />
<Compile Include="Classes\SettingsBinder.cs" />
<Compile Include="Classes\StyleManager.cs" />
<Compile Include="Windows\AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
Expand Down
8 changes: 3 additions & 5 deletions PK Finder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

Expand All @@ -12,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CodeDead")]
[assembly: AssemblyProduct("PK Finder")]
[assembly: AssemblyCopyright("Copyright © CodeDead 2018")]
[assembly: AssemblyCopyright("Copyright © CodeDead 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -51,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
4 changes: 2 additions & 2 deletions PK Finder/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion PK Finder/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="WindowOpacity" Type="System.Double" Scope="User">
<Value Profile="(Default)">1</Value>
<Value Profile="(Default)">100</Value>
</Setting>
<Setting Name="WindowResizeBorder" Type="System.Double" Scope="User">
<Value Profile="(Default)">3</Value>
Expand Down
6 changes: 3 additions & 3 deletions PK Finder/Windows/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="PK_Finder.Windows.AboutWindow"
UseLayoutRounding="True" UseNativeChrome="True"
mc:Ignorable="d" AllowsTransparency="True" Width="300" Height="200" TitleTextAlignment="Center"
mc:Ignorable="d" AllowsTransparency="True" Width="350" Height="250" TitleTextAlignment="Center"
Title="PK Finder - About" WindowStartupLocation="CenterScreen" Icon="/PK Finder;component/pkfinder.ico">

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
Expand All @@ -26,9 +26,9 @@ PK Finder was created by DeadLine.<LineBreak></LineBreak>
<LineBreak></LineBreak>
Images: small-n-flat by paomedia<LineBreak></LineBreak>
Theme: Syncfusion<LineBreak></LineBreak>
Version: 1.5.0.0<LineBreak></LineBreak>
Version: 1.5.1.0<LineBreak></LineBreak>
<LineBreak></LineBreak>
Copyright © CodeDead 2018
Copyright © CodeDead 2019
</TextBlock>
</Grid>
<Grid Grid.Row="1">
Expand Down
2 changes: 1 addition & 1 deletion PK Finder/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Margin="2" Content="Product key:" />
<TextBox Margin="2" x:Name="TxtProductKey" Grid.Row="0" Grid.Column="1" IsReadOnly="True" MouseDoubleClick="TxtProductKey_MouseDoubleClick"></TextBox>
<TextBox Margin="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" x:Name="TxtProductKey" Grid.Row="0" Grid.Column="1" IsReadOnly="True" MouseDoubleClick="TxtProductKey_MouseDoubleClick"></TextBox>
<Button Margin="2" Grid.Column="2" Click="BtnCopy_OnClick">
<Button.ToolTip>
<ToolTip Content="Copy product key to clipboard." />
Expand Down
6 changes: 6 additions & 0 deletions PK Finder/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ private void RefreshProductKey()
{
_keyInfo = KeyManager.GetWindowsProductInformation();

if (_keyInfo == null)
{
MessageBox.Show("Unable to retrieve product key! Your registry might be corrupt or your version of Windows is not activated.", "PK Finder", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

LblInfo.Content = _keyInfo.GetProductName();
TxtProductKey.Text = _keyInfo.GetProductKey();
}
Expand Down
31 changes: 18 additions & 13 deletions PK Finder/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="PK_Finder.Windows.SettingsWindow"
xmlns:bind="clr-namespace:PK_Finder.Classes"
mc:Ignorable="d" TitleTextAlignment="Center" AllowsTransparency="True"
UseLayoutRounding="True" UseNativeChrome="True"
Closing="SettingsWindow_OnClosing"
Title="PK Finder - Settings" Height="300" Width="350" WindowStartupLocation="CenterScreen" Icon="/PK Finder;component/pkfinder.ico">

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
Expand All @@ -19,18 +20,17 @@
TabItemSize="ShrinkToFit" TabScrollButtonVisibility="Hidden">
<syncfusion:TabItemExt Header="General" Image="/PK Finder;component/Resources/Images/settings.png"
ImageWidth="16" ImageHeight="16">

<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Margin="3" x:Name="ChbAutoUpdate" Content="Automatically check for updates" />
<CheckBox Grid.Row="1" Margin="3" x:Name="ChbTextBoxCopy" Content="Copy data by double clicking" />
<CheckBox Grid.Row="2" Margin="3" x:Name="ChbCopyMessage" Content="Display message when data has been copied" />
<CheckBox Grid.Row="3" Margin="3" x:Name="ChbWindowDrag" Content="Window draggable" />
<CheckBox Grid.Row="0" Margin="3" Content="Automatically check for updates" IsChecked="{bind:SettingsBinder AutoUpdate}"/>
<CheckBox Grid.Row="1" Margin="3" Content="Copy data by double clicking" IsChecked="{bind:SettingsBinder DoubleClickCopy}"/>
<CheckBox Grid.Row="2" Margin="3" Content="Display message when data has been copied" IsChecked="{bind:SettingsBinder CopyMessage}" />
<CheckBox Grid.Row="3" Margin="3" Content="Window draggable" IsChecked="{bind:SettingsBinder WindowDraggable}"/>
</Grid>
</syncfusion:TabItemExt>

Expand All @@ -48,8 +48,9 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Label Margin="3" Content="Style:" />
<ComboBox Margin="3" x:Name="CboStyle" SelectedValuePath="Content" Grid.Row="0" Grid.Column="1" IsReadOnly="True">
<ComboBox Margin="3" SelectedValuePath="Content" SelectedValue="{bind:SettingsBinder VisualStyle}" Grid.Row="0" Grid.Column="1" IsReadOnly="True">
<ComboBoxItem>Metro</ComboBoxItem>
<ComboBoxItem>Blend</ComboBoxItem>
<ComboBoxItem>VS2010</ComboBoxItem>
Expand All @@ -66,14 +67,18 @@
<ComboBoxItem>Transparent</ComboBoxItem>
<ComboBoxItem>None</ComboBoxItem>
</ComboBox>

<Label Margin="3" Grid.Row="1" Grid.Column="0" Content="Metro brush:" />
<syncfusion:ColorPicker Margin="3" x:Name="CpMetroBrush" Grid.Row="1" Grid.Column="1" />
<syncfusion:ColorPicker Margin="3" Grid.Row="1" Grid.Column="1" Color="{bind:SettingsBinder MetroColor}" />

<Label Margin="3" Grid.Row="2" Grid.Column="0" Content="Border thickness:" />
<syncfusion:IntegerTextBox Margin="3" x:Name="IntBorderThickness" Grid.Row="2" Grid.Column="1" MinValue="0" />
<syncfusion:IntegerTextBox Margin="3" Grid.Row="2" Grid.Column="1" MinValue="0" ValueChanged="BorderThickness_OnValueChanged" Value="{bind:SettingsBinder BorderThickness}" />

<Label Margin="3" Grid.Row="3" Grid.Column="0" Content="Window opacity:" />
<Slider x:Name="SldOpacity" Margin="3" Grid.Row="3" Grid.Column="1" Minimum="30" Maximum="100" Width="180" ValueChanged="SldOpacity_OnValueChanged" />
<Slider Margin="3" Grid.Row="3" Grid.Column="1" Minimum="30" Maximum="100" Width="180" ValueChanged="SldOpacity_OnValueChanged" Value="{bind:SettingsBinder WindowOpacity}" />

<Label Margin="3" Grid.Row="4" Grid.Column="0" Content="Resize border:" />
<Slider x:Name="SldWindowResize" Margin="3" Grid.Row="4" Grid.Column="1" Minimum="2" Maximum="10" Width="180" ValueChanged="SldWindowResize_OnValueChanged" />
<Slider Margin="3" Grid.Row="4" Grid.Column="1" Minimum="2" Maximum="10" Width="180" ValueChanged="SldWindowResize_OnValueChanged" Value="{bind:SettingsBinder WindowResizeBorder}" />
</Grid>
</syncfusion:TabItemExt>
</syncfusion:TabControlExt>
Expand All @@ -84,8 +89,8 @@
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button MinHeight="25" Margin="5" x:Name="BtnReset" Content="Reset" Click="BtnReset_OnClick" />
<Button MinHeight="25" Grid.Column="1" Margin="5" x:Name="BtnSave" Content="Save" Click="BtnSave_OnClick" />
<Button MinHeight="25" Margin="5" Content="Reset" Click="BtnReset_OnClick" />
<Button MinHeight="25" Grid.Column="1" Margin="5" Content="Save" Click="BtnSave_OnClick" />
</Grid>
</Grid>
</Grid>
Expand Down
56 changes: 33 additions & 23 deletions PK Finder/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using PK_Finder.Classes;
using Syncfusion.Windows.Shared;

namespace PK_Finder.Windows
{
Expand Down Expand Up @@ -48,16 +51,6 @@ private void LoadSettings()
{
try
{
ChbAutoUpdate.IsChecked = Properties.Settings.Default.AutoUpdate;
ChbTextBoxCopy.IsChecked = Properties.Settings.Default.DoubleClickCopy;
ChbCopyMessage.IsChecked = Properties.Settings.Default.CopyMessage;
ChbWindowDrag.IsChecked = Properties.Settings.Default.WindowDraggable;
CboStyle.SelectedValue = Properties.Settings.Default.VisualStyle;
CpMetroBrush.Color = Properties.Settings.Default.MetroColor;
IntBorderThickness.Value = Properties.Settings.Default.BorderThickness;
SldOpacity.Value = Properties.Settings.Default.WindowOpacity * 100;
SldWindowResize.Value = Properties.Settings.Default.WindowResizeBorder;

if (Properties.Settings.Default.WindowDraggable)
{
// Prevent duplicate handlers
Expand Down Expand Up @@ -125,17 +118,6 @@ private void BtnSave_OnClick(object sender, RoutedEventArgs e)
{
try
{
if (ChbAutoUpdate.IsChecked != null) Properties.Settings.Default.AutoUpdate = ChbAutoUpdate.IsChecked.Value;
if (ChbTextBoxCopy.IsChecked != null) Properties.Settings.Default.DoubleClickCopy = ChbTextBoxCopy.IsChecked.Value;
if (ChbCopyMessage.IsChecked != null) Properties.Settings.Default.CopyMessage = ChbCopyMessage.IsChecked.Value;
if (ChbWindowDrag.IsChecked != null) Properties.Settings.Default.WindowDraggable = ChbWindowDrag.IsChecked.Value;
Properties.Settings.Default.VisualStyle = CboStyle.Text;

Properties.Settings.Default.MetroColor = CpMetroBrush.Color;
if (IntBorderThickness.Value != null) Properties.Settings.Default.BorderThickness = (int)IntBorderThickness.Value;
Properties.Settings.Default.WindowOpacity = SldOpacity.Value / 100;
Properties.Settings.Default.WindowResizeBorder = SldWindowResize.Value;

Properties.Settings.Default.Save();

_mw.LoadTheme();
Expand All @@ -159,7 +141,7 @@ private void BtnSave_OnClick(object sender, RoutedEventArgs e)
/// <param name="e">The RoutedPropertyChangedEventArgs</param>
private void SldOpacity_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Opacity = SldOpacity.Value / 100;
Opacity = ((Slider)sender).Value / 100;
}

/// <summary>
Expand All @@ -169,7 +151,35 @@ private void SldOpacity_OnValueChanged(object sender, RoutedPropertyChangedEvent
/// <param name="e">The RoutedPropertyChangedEventArgs</param>
private void SldWindowResize_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ResizeBorderThickness = new Thickness(SldWindowResize.Value);
ResizeBorderThickness = new Thickness(((Slider)sender).Value);
}

/// <summary>
/// Method that is called when the Window is closing
/// </summary>
/// <param name="sender">The object that called this method</param>
/// <param name="e">The CancelEventArgs</param>
private void SettingsWindow_OnClosing(object sender, CancelEventArgs e)
{
try
{
Properties.Settings.Default.Reload();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "PK Finder", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

/// <summary>
/// Method that is called when the BorderThickness should change dynamically
/// </summary>
/// <param name="d">The DependencyObject</param>
/// <param name="e">The DependencyPropertyChangedEventArgs</param>
private void BorderThickness_OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
long? value = ((IntegerTextBox) d).Value;
if (value != null) BorderThickness = new Thickness(value.Value);
}
}
}

0 comments on commit 409c755

Please sign in to comment.