Update system implemented

This commit is contained in:
Théo Marchal 2022-11-06 15:44:53 +01:00
parent 529754934d
commit ccbb4525f3
11 changed files with 214 additions and 16 deletions

View File

@ -1,6 +1,6 @@
using System.Globalization;
using System.Windows;
using System.Windows;
using Hardcodet.Wpf.TaskbarNotification;
using unison.Handlers;
namespace unison
{
@ -10,12 +10,13 @@ namespace unison
private HotkeyHandler _hotkeys;
private SnapcastHandler _snapcast;
private MPDHandler _mpd;
private UpdateHandler _updater;
protected override void OnStartup(StartupEventArgs e)
{
//debug language
//unison.Resources.Resources.Culture = CultureInfo.GetCultureInfo("fr-FR");
//unison.Resources.Resources.Culture = CultureInfo.GetCultureInfo("es-ES");
//unison.Resources.Resources.Culture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
//unison.Resources.Resources.Culture = System.Globalization.CultureInfo.GetCultureInfo("es-ES");
base.OnStartup(e);
@ -29,6 +30,9 @@ namespace unison
_snapcast = new SnapcastHandler();
Current.Properties["snapcast"] = _snapcast;
_updater = new UpdateHandler();
Current.Properties["updater"] = _updater;
Current.MainWindow = new MainWindow();
_systray = (TaskbarIcon)FindResource("SystrayTaskbar");

49
Handlers/UpdateHandler.cs Normal file
View File

@ -0,0 +1,49 @@
using System.Windows;
using AutoUpdaterDotNET;
namespace unison.Handlers
{
internal class UpdateHandler
{
readonly string xmlFile = "https://raw.githubusercontent.com/ZetaKebab/unison/main/Installer/unison.xml";
private bool _UpdateAvailable = false;
public bool UpdateAvailable() => _UpdateAvailable;
public UpdateHandler()
{
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
Start();
}
public void Start()
{
AutoUpdater.Start(xmlFile);
}
private string CutVersionNumber(string number)
{
return number.Substring(0, number.LastIndexOf("."));
}
private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args.Error == null)
{
if (args.IsUpdateAvailable)
{
_UpdateAvailable = true;
string number = CutVersionNumber(args.CurrentVersion);
MainWindow MainWin = (MainWindow)Application.Current.MainWindow;
MainWin.UpdateUpdateStatus(number);
MessageBoxResult Result = MessageBox.Show($"{unison.Resources.Resources.Update_Message1} {number}.\n{unison.Resources.Resources.Update_Message2}",
"unison", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (Result == MessageBoxResult.Yes)
AutoUpdater.DownloadUpdate(args);
}
}
}
}
}

7
Installer/unison.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.3.1.0</version>
<url>https://github.com/ZetaKebab/unison/releases/download/v1.3.1/unison-v1.3.1.zip</url>
<changelog>https://raw.githubusercontent.com/ZetaKebab/unison/main/CHANGELOG.md</changelog>
<mandatory>false</mandatory>
</item>

View File

@ -19,7 +19,7 @@ namespace unison.Resources {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
@ -617,5 +617,59 @@ namespace unison.Resources {
return ResourceManager.GetString("StopSnapcast", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Check for updates.
/// </summary>
public static string Update_ButtonCheck {
get {
return ResourceManager.GetString("Update_ButtonCheck", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Start update.
/// </summary>
public static string Update_ButtonStart {
get {
return ResourceManager.GetString("Update_ButtonStart", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Update available! New version is.
/// </summary>
public static string Update_Message1 {
get {
return ResourceManager.GetString("Update_Message1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Install now?.
/// </summary>
public static string Update_Message2 {
get {
return ResourceManager.GetString("Update_Message2", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New version.
/// </summary>
public static string Update_String1 {
get {
return ResourceManager.GetString("Update_String1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to available!.
/// </summary>
public static string Update_String2 {
get {
return ResourceManager.GetString("Update_String2", resourceCulture);
}
}
}
}

View File

@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Exit" xml:space="preserve">
<value>Salir</value>
@ -303,4 +303,22 @@
<data name="StopSnapcast" xml:space="preserve">
<value>Parar Snapcast</value>
</data>
<data name="Update_ButtonCheck" xml:space="preserve">
<value>Buscar actualización</value>
</data>
<data name="Update_ButtonStart" xml:space="preserve">
<value>Actualizar</value>
</data>
<data name="Update_Message1" xml:space="preserve">
<value>¡Actualización disponible! La nueva versión es la</value>
</data>
<data name="Update_Message2" xml:space="preserve">
<value>¿Instalar ahora?</value>
</data>
<data name="Update_String1" xml:space="preserve">
<value>¡Nueva versión</value>
</data>
<data name="Update_String2" xml:space="preserve">
<value>disponible!</value>
</data>
</root>

View File

@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Exit" xml:space="preserve">
<value>Quitter</value>
@ -303,4 +303,22 @@
<data name="StopSnapcast" xml:space="preserve">
<value>Stopper Snapcast</value>
</data>
<data name="Update_ButtonCheck" xml:space="preserve">
<value>Chercher une mise à jour</value>
</data>
<data name="Update_ButtonStart" xml:space="preserve">
<value>Mettre à jour</value>
</data>
<data name="Update_Message1" xml:space="preserve">
<value>Mise à jour disponible ! La nouvelle version est la</value>
</data>
<data name="Update_Message2" xml:space="preserve">
<value>Installer maintenant ?</value>
</data>
<data name="Update_String1" xml:space="preserve">
<value>Nouvelle version</value>
</data>
<data name="Update_String2" xml:space="preserve">
<value>disponible !</value>
</data>
</root>

View File

@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Exit" xml:space="preserve">
<value>Exit</value>
@ -303,4 +303,22 @@
<data name="StopSnapcast" xml:space="preserve">
<value>Stop Snapcast</value>
</data>
<data name="Update_ButtonCheck" xml:space="preserve">
<value>Check for updates</value>
</data>
<data name="Update_ButtonStart" xml:space="preserve">
<value>Start update</value>
</data>
<data name="Update_Message1" xml:space="preserve">
<value>Update available! New version is</value>
</data>
<data name="Update_Message2" xml:space="preserve">
<value>Install now?</value>
</data>
<data name="Update_String1" xml:space="preserve">
<value>New version</value>
</data>
<data name="Update_String2" xml:space="preserve">
<value>available!</value>
</data>
</root>

View File

@ -271,6 +271,11 @@ namespace unison
slider.ToolTip = (int)slider.Value;
}
public void UpdateUpdateStatus(string version)
{
_settingsWin.UpdateUpdateStatus(version);
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

View File

@ -229,16 +229,23 @@
</GroupBox.Header>
<Grid VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" Margin="0,0,0,10" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top">
<Run Text="{x:Static properties:Resources.Settings_Version}"/>
<Run Text="{Binding GetVersion, Mode = OneWay}"/>
</TextBlock>
<TextBlock x:Name="UpdateText" TextWrapping="Wrap" VerticalAlignment="Top">
<Run x:Name="UpdateText2" Text="New version 1.3.2 available!" FontWeight="Bold"/>
</TextBlock>
<Button x:Name="UpdateButton" Content="{x:Static properties:Resources.Update_ButtonCheck}" Margin="0,3,0,10" Width="150" Click="CheckUpdates" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top">
<Run Text="{x:Static properties:Resources.Settings_AboutInfo}" /><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/Difegue/MpcNET" RequestNavigate="Hyperlink_RequestNavigate">MpcNET</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/hardcodet/wpf-notifyicon" RequestNavigate="Hyperlink_RequestNavigate">wpf-notifyicon</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/samhocevar/emoji.wpf" RequestNavigate="Hyperlink_RequestNavigate">Emoji.WPF</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/tof4/RadioBrowser" RequestNavigate="Hyperlink_RequestNavigate">RadioBrowser</Hyperlink>
※ <Hyperlink NavigateUri="https://github.com/tof4/RadioBrowser" RequestNavigate="Hyperlink_RequestNavigate">RadioBrowser</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/ravibpatel/AutoUpdater.NET" RequestNavigate="Hyperlink_RequestNavigate">AutoUpdater.NET</Hyperlink>
</TextBlock>
<TextBlock Margin="0,10,0,0">
<Run Text="{x:Static properties:Resources.Settings_SourceCode1}" />

View File

@ -5,11 +5,13 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Navigation;
using unison.Handlers;
namespace unison
{
@ -60,6 +62,8 @@ namespace unison
SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString();
VolumeOffset.Text = Properties.Settings.Default.volume_offset.ToString();
UpdateText.Visibility = Visibility.Collapsed;
InitializeShortcuts();
}
@ -115,7 +119,7 @@ namespace unison
ConnectionStatus.Text = unison.Resources.Resources.Settings_ConnectionStatusConnecting;
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
System.Threading.Tasks.Task.Run(async () => { await mpd.Initialize(); });
Task.Run(async () => { await mpd.Initialize(); });
}
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
@ -142,6 +146,19 @@ namespace unison
MPDConnect_Clicked(null, null);
}
private void CheckUpdates(object sender, RoutedEventArgs e)
{
UpdateHandler updater = (UpdateHandler)Application.Current.Properties["updater"];
updater.Start();
}
public void UpdateUpdateStatus(string version)
{
UpdateText.Visibility = Visibility.Visible;
UpdateText2.Text = unison.Resources.Resources.Update_String1 + " " + version + " " + unison.Resources.Resources.Update_String2;
UpdateButton.Content = unison.Resources.Resources.Update_ButtonStart;
}
private void Window_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
@ -373,12 +390,12 @@ namespace unison
InitializeShortcuts();
}
public uint GetMod(StackPanel stackPanel)
private uint GetMod(StackPanel stackPanel)
{
return (uint)(GetMOD(stackPanel.Children.OfType<ComboBox>().First().SelectedItem.ToString()) | GetMOD(stackPanel.Children.OfType<ComboBox>().Last().SelectedItem.ToString()));
}
public uint GetVk(StackPanel stackPanel)
private uint GetVk(StackPanel stackPanel)
{
Button button = stackPanel.Children.OfType<Button>().First();
TextBlock textBlock = (TextBlock)button.Content;

View File

@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.6" />
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="RadioBrowser" Version="0.6.1" />