Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to check for new release #51

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/DCSInsight/DCSInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<AssemblyName>dcs-insight</AssemblyName>
<Version>1.0.0</Version>
<AssemblyVersion>1.8.0</AssemblyVersion>
<AssemblyVersion>1.7.0</AssemblyVersion>
<ApplicationIcon>Images\Magnifier_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
Expand All @@ -25,6 +25,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.4" />
<PackageReference Include="Octokit" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\clear_search_result.png" />
Expand Down
3 changes: 2 additions & 1 deletion src/client/DCSInsight/DCSInsight.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=consolas/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DCSAPI/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=defs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SENDAPI/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SENDAPI/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Skunkworks/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
3 changes: 3 additions & 0 deletions src/client/DCSInsight/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave">
<TextBlock Name="TextBlockAppWiki" MouseDown="TextBlockAppWiki_OnMouseDown">wiki</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave">
<TextBlock Name="TextBlockCheckNewVersion" MouseDown="TextBlockCheckNewVersion_OnMouseDown">check version</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right">
<TextBlock Name="TextBlockMessage" ></TextBlock>
</StatusBarItem>
Expand Down
50 changes: 50 additions & 0 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using DCSInsight.Events;
Expand All @@ -19,6 +20,8 @@
using System.Windows.Media.Imaging;
using DCSInsight.Communication;
using DCSInsight.Windows;
using Octokit;
using ProductHeaderValue = System.Net.Http.Headers.ProductHeaderValue;

namespace DCSInsight
{
Expand Down Expand Up @@ -530,5 +533,52 @@ private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Arrow;
}

private async void TextBlockCheckNewVersion_OnMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
await CheckForNewVersion();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

private async Task CheckForNewVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
if (string.IsNullOrEmpty(fileVersionInfo.FileVersion)) return;

var thisVersion = new Version(fileVersionInfo.FileVersion);

try
{
var client = new GitHubClient(new Octokit.ProductHeaderValue("dcs-insight"));
var lastRelease = await client.Repository.Release.GetLatest("DCS-Skunkworks", "dcs-insight");
var githubVersion = new Version(lastRelease.TagName.Replace("v.", "").Replace("v",""));
if (githubVersion.CompareTo(thisVersion) > 0)
{
if (MessageBox.Show(this, $"Newer version can be downloaded ({lastRelease.TagName}).\nGo to download page?", "New Version Available", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
{
Process.Start(new ProcessStartInfo
{
FileName = "https://github.com/DCS-Skunkworks/dcs-insight/releases",
UseShellExecute = true
});
}
}
else if (githubVersion.CompareTo(thisVersion) == 0)
{
MessageBox.Show(this, $"You have the latest version.", "", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
catch (Exception ex)
{
Logger.Error(ex, "Error checking for newer releases.");
}
}
}
}