Skip to content

Commit

Permalink
add release/newest version checking based on github tag
Browse files Browse the repository at this point in the history
- About tab: When a new release is available a new button allows you to visit the latest release and download the newest version.
  • Loading branch information
RiddleTime committed Apr 12, 2022
1 parent 292445c commit 16e10c4
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ACCSetupApp/ACC_Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Octokit, Version=0.50.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Octokit.0.50.0\lib\net46\Octokit.dll</HintPath>
</Reference>
<Reference Include="PaintDotNet.Base, Version=3.36.7079.22820, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DdsFileTypePlusHack.1.0.4\lib\net45\PaintDotNet.Base.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -274,6 +277,7 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down
14 changes: 14 additions & 0 deletions ACCSetupApp/Controls/About/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
Developed by Defragler (Reinier Klarenberg)
</TextBlock>
</StackPanel>

<StackPanel x:Name="ReleaseStackPanel" Orientation="Vertical" HorizontalAlignment="Left" Width="250" VerticalAlignment="Top" Margin="0,5,5,0">
</StackPanel>
<StackPanel Orientation="Vertical" HorizontalAlignment="Right" Width="100" VerticalAlignment="Top" Margin="0,5,5,0">
<Button x:Name="buttonDiscord" >
<Grid>
Expand Down Expand Up @@ -203,6 +206,17 @@
<StackPanel Margin="0,10,0,0">
<TextBlock
Style="{StaticResource MaterialDesignBody1TextBlock}"
HorizontalAlignment="Left" TextWrapping="Wrap" >
0.0.3.6:
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignDataGridTextColumnStyle}" HorizontalAlignment="Left" TextWrapping="WrapWithOverflow">
- About tab: When a new release is available a new button allows you to visit the latest release and download the newest version.
</TextBlock>
</StackPanel>

<StackPanel Margin="0,10,0,0">
<TextBlock
Style="{StaticResource MaterialDesignBody1TextBlock}"
HorizontalAlignment="Left" TextWrapping="Wrap" >
0.0.3.5:
</TextBlock>
Expand Down
59 changes: 57 additions & 2 deletions ACCSetupApp/Controls/About/About.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using ACCSetupApp.SetupParser;
using ACCSetupApp.Util;
using Octokit;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand All @@ -28,10 +33,12 @@ public About()
{
InitializeComponent();

SetCarConversionFeatures();

buttonDiscord.Click += (sender, e) => System.Diagnostics.Process.Start("https://discord.gg/26AAEW5mUq"); ;
buttonGithub.Click += (sender, e) => System.Diagnostics.Process.Start("https://github.com/RiddleTime/ACC-Manager");

SetCarConversionFeatures();

ThreadPool.QueueUserWorkItem(x => CheckNewestVersion());
}


Expand All @@ -48,5 +55,53 @@ private void SetCarConversionFeatures()
}
}
}

private async void CheckNewestVersion()
{
try
{
GitHubClient client = new GitHubClient(new ProductHeaderValue("ACC-Manager"), new Uri("https://github.com/RiddleTime/ACC-Manager.git"));
var allTags = await client.Repository.GetAllTags("RiddleTime", "ACC-Manager");


if (allTags != null && allTags.Count > 0)
{
RepositoryTag latest = allTags.First();
Debug.WriteLine($"Latest version: {latest.Name}");
if (!GetAssemblyFileVersion().Equals(latest.Name))
{
Release release = await client.Repository.Release.GetLatest("RiddleTime", "ACC-Manager");

if (release != null)
{
await Dispatcher.BeginInvoke(new Action(() =>
{
MainWindow.Instance.EnqueueSnackbarMessage($"A new version of ACC Manager is available: {latest.Name}");
Button openReleaseButton = new Button()
{
Margin = new Thickness(5, 0, 0, 0),
Content = $"Download {latest.Name} at GitHub",
ToolTip = $"Release notes:\n{release.Body}"
};
openReleaseButton.Click += (s, e) => Process.Start(release.HtmlUrl);
ReleaseStackPanel.Children.Add(openReleaseButton);
}));
}
}
}

}
catch (Exception ex)
{
LogWriter.WriteToLog(ex);
}
}

private static string GetAssemblyFileVersion()
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
return fileVersion.FileVersion;
}
}
}
9 changes: 9 additions & 0 deletions ACCSetupApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public void EnqueueSnackbarMessage(string message)
}));
}

public void EnqueueSnackbarWarning(string message)
{
Instance.snackbar.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(
delegate ()
{
Instance.snackbar.MessageQueue.Enqueue(message);
}));
}

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
Expand Down
4 changes: 2 additions & 2 deletions ACCSetupApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,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("0.0.3.5")]
[assembly: AssemblyFileVersion("0.0.3.5")]
[assembly: AssemblyVersion("0.0.3.6")]
[assembly: AssemblyFileVersion("0.0.3.6")]
1 change: 1 addition & 0 deletions ACCSetupApp/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net48" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
<package id="Octokit" version="0.50.0" targetFramework="net48" />
<package id="SharpCompress" version="0.31.0" targetFramework="net48" />
<package id="System.AppContext" version="4.3.0" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
Expand Down

0 comments on commit 16e10c4

Please sign in to comment.