Skip to content

Commit

Permalink
+ Added automatic check for new versions on github (weekly check, can…
Browse files Browse the repository at this point in the history
… be disabled).
  • Loading branch information
cabal95 committed Jul 31, 2018
1 parent 6d91fe4 commit c6668ec
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 4 deletions.
6 changes: 6 additions & 0 deletions RockDevBooster/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<setting name="VisualStudioVersion" serializeAs="String">
<value />
</setting>
<setting name="LastUpdateCheck" serializeAs="String">
<value />
</setting>
<setting name="AutoUpdate" serializeAs="String">
<value>True</value>
</setting>
</com.blueboxmoon.RockDevBooster.Properties.Settings>
</userSettings>
</configuration>
42 changes: 42 additions & 0 deletions RockDevBooster/Dialogs/PendingUpdateDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Window x:Class="com.blueboxmoon.RockDevBooster.Dialogs.PendingUpdateDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:com.blueboxmoon.RockDevBooster.Dialogs"
mc:Ignorable="d"
Title="New Version Available"
Height="140"
Width="400"
ResizeMode="NoResize"
Icon="/RockDevBooster;component/resources/RockDevBooster.ico"
WindowStartupLocation="CenterOwner">
<Grid>
<Button x:Name="btnCancel"
Content="Cancel"
Margin="0,0,10,10"
HorizontalAlignment="Right"
Width="73"
Click="btnCancel_Click"
Style="{StaticResource buttonStyleIcon}" Height="36" VerticalAlignment="Bottom"/>

<Button Name="btnOK"
Content="Show Me"
Margin="0,0,88,10"
HorizontalAlignment="Right"
Width="90"
Click="btnOK_Click"
IsDefault="True"
Style="{StaticResource buttonStyleIconSuccess}"
Height="36"
VerticalAlignment="Bottom"/>
<TextBlock
HorizontalAlignment="Stretch"
Margin="10,10,10,0"
TextWrapping="WrapWithOverflow"
Text="A new version of RockDevBooster is available for download on github."
VerticalAlignment="Top"
Height="41"
/>
</Grid>
</Window>
51 changes: 51 additions & 0 deletions RockDevBooster/Dialogs/PendingUpdateDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace com.blueboxmoon.RockDevBooster.Dialogs
{
/// <summary>
/// Interaction logic for PendingUpdateDialog.xaml
/// </summary>
public partial class PendingUpdateDialog : Window
{
public PendingUpdateDialog()
{
InitializeComponent();
}

#region Events

/// <summary>
/// Handles the Click event of the btnCancel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
protected void btnCancel_Click( object sender, RoutedEventArgs e )
{
DialogResult = false;
}

/// <summary>
/// Handles the Click event of the btnOK control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
protected void btnOK_Click( object sender, RoutedEventArgs e )
{
DialogResult = true;
}

#endregion
}
}
23 changes: 23 additions & 0 deletions RockDevBooster/Properties/Settings.Designer.cs

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

6 changes: 6 additions & 0 deletions RockDevBooster/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
<Setting Name="VisualStudioVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="LastUpdateCheck" Type="System.DateTime" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AutoUpdate" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
7 changes: 7 additions & 0 deletions RockDevBooster/RockDevBooster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ConsoleApp.cs" />
<Compile Include="Dialogs\PendingUpdateDialog.xaml.cs">
<DependentUpon>PendingUpdateDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\TextInputDialog.xaml.cs">
<DependentUpon>TextInputDialog.xaml</DependentUpon>
</Compile>
Expand All @@ -106,6 +109,10 @@
</Compile>
<Compile Include="VisualStudioInstall.cs" />
<Compile Include="WindowPlacement.cs" />
<Page Include="Dialogs\PendingUpdateDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\TextInputDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
21 changes: 21 additions & 0 deletions RockDevBooster/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public MainWindow()
ActivateMenuSelection( btnMenuInstances );
}

/// <summary>
/// Activates a new menu button and switches the current view.
/// </summary>
/// <param name="button">The button.</param>
protected void ActivateMenuSelection( Button button )
{
string name = button.CommandParameter.ToString();
Expand All @@ -61,21 +65,38 @@ protected void ActivateMenuSelection( Button button )
}
}

#region Events

/// <summary>
/// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
/// </summary>
/// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
protected override void OnClosing( CancelEventArgs e )
{
Settings.Default.MainWindowPlacement = WindowPlacement.GetPlacement( new WindowInteropHelper( this ).Handle );
Settings.Default.Save();
}

/// <summary>
/// Raises the <see cref="E:System.Windows.Window.SourceInitialized" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
protected override void OnSourceInitialized( EventArgs e )
{
base.OnSourceInitialized( e );
WindowPlacement.SetPlacement( new WindowInteropHelper( this ).Handle, Settings.Default.MainWindowPlacement );
}

/// <summary>
/// Handles the Click event of the btnMenu control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void btnMenu_Click( object sender, RoutedEventArgs e )
{
ActivateMenuSelection( ( Button ) sender );
}

#endregion
}
}
24 changes: 20 additions & 4 deletions RockDevBooster/Views/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="93*"/>
</Grid.RowDefinitions>
<Label
HorizontalAlignment="Left"
Margin="10,10,0,0"
Expand All @@ -20,5 +16,25 @@
Style="{StaticResource labelStyleBold}" Grid.RowSpan="2"
/>
<ComboBox Name="cbVisualStudio" Margin="90,10,10,0" VerticalAlignment="Top" SelectionChanged="cbVisualStudio_SelectionChanged" Grid.RowSpan="2"/>

<CheckBox Name="cbAutoUpdate"
Style="{StaticResource checkboxStyle}"
Content="Auto Update"
Margin="90,37,10,0"
VerticalAlignment="Top"
Checked="cbAutoUpdate_Changed"
Unchecked="cbAutoUpdate_Changed"
/>

<Button Name="btnCheckForUpdates"
Content="Check For Updates"
Margin="0,0,10,10"
HorizontalAlignment="Right"
Width="130"
Click="btnCheckForUpdates_Click"
IsDefault="True"
Style="{StaticResource buttonStyleAction}"
Height="36"
VerticalAlignment="Bottom"/>
</Grid>
</UserControl>
105 changes: 105 additions & 0 deletions RockDevBooster/Views/PreferencesView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -15,6 +17,7 @@
using System.Windows.Shapes;

using com.blueboxmoon.RockDevBooster.Properties;
using Octokit;

namespace com.blueboxmoon.RockDevBooster.Views
{
Expand All @@ -39,9 +42,88 @@ public PreferencesView()
int selectedIndex = vsList.IndexOf( vsList.Where( v => v.Path == vs.Path ).FirstOrDefault() );
cbVisualStudio.SelectedIndex = selectedIndex;
}

cbAutoUpdate.IsChecked = Settings.Default.AutoUpdate;
}

CheckForUpdatesAndPromptUser();
}

#region Methods

/// <summary>
/// Checks for updates and prompt user.
/// </summary>
protected void CheckForUpdatesAndPromptUser( bool force = false )
{
if ( !force )
{
var lastCheck = Settings.Default.LastUpdateCheck;

//
// Only check once a week and if we are auto updating.
//
if ( lastCheck.AddDays( 7 ) >= DateTime.Now || !Settings.Default.AutoUpdate )
{
return;
}
}

CheckForUpdatesAsync().ContinueWith( ( t ) =>
{
Settings.Default.LastUpdateCheck = DateTime.Now;

if ( !t.IsFaulted && t.Result )
{
Dispatcher.Invoke( () =>
{
var response = new Dialogs.PendingUpdateDialog().ShowDialog();

if ( response.HasValue && response.Value )
{
Process.Start( "https://github.com/cabal95/RockDevBooster/releases" );
}
} );
}
} );
}

/// <summary>
/// Checks for updates.
/// </summary>
/// <returns></returns>
protected async Task<bool> CheckForUpdatesAsync()
{
try
{
var client = new GitHubClient( new ProductHeaderValue( "RockDevBooster" ) );
var release = await client.Repository.Release.GetLatest( "cabal95", "RockDevBooster" );

if ( release == null || !release.Name.StartsWith( "Version " ) )
{
return false;
}

var version = Version.Parse( release.Name.Substring( 8 ) );
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

return version > currentVersion;
}
catch
{
return false;
}
}

#endregion

#region Events

/// <summary>
/// Handles the SelectionChanged event of the cbVisualStudio control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
private void cbVisualStudio_SelectionChanged( object sender, SelectionChangedEventArgs e )
{
var vsList = cbVisualStudio.ItemsSource as List<VisualStudioInstall>;
Expand All @@ -50,5 +132,28 @@ private void cbVisualStudio_SelectionChanged( object sender, SelectionChangedEve
Settings.Default.VisualStudioVersion = vs.Path;
Settings.Default.Save();
}

/// <summary>
/// Handles the Click event of the btnCheckForUpdates control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void btnCheckForUpdates_Click( object sender, RoutedEventArgs e )
{
CheckForUpdatesAndPromptUser( true );
}

/// <summary>
/// Handles the Checked event of the cbAutoUpdate control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
private void cbAutoUpdate_Changed( object sender, RoutedEventArgs e )
{
Settings.Default.AutoUpdate = cbAutoUpdate.IsChecked.Value;
Settings.Default.Save();
}

#endregion
}
}

0 comments on commit c6668ec

Please sign in to comment.