2021-02-07 17:08:40 +00:00
using System.ComponentModel ;
using System.Net.Http ;
2021-02-07 06:28:26 +00:00
using System.Threading.Tasks ;
using System.Windows ;
using AutoUpdaterDotNET ;
namespace XIVChat_Desktop {
2021-02-07 17:08:40 +00:00
public partial class UpdateWindow : INotifyPropertyChanged {
public event PropertyChangedEventHandler ? PropertyChanged ;
2021-02-07 06:28:26 +00:00
private App App = > ( App ) Application . Current ;
2021-02-07 17:08:40 +00:00
public bool Downloading { get ; set ; }
2021-02-07 06:28:26 +00:00
private UpdateInfoEventArgs Info { get ; }
public UpdateWindow ( Window owner , UpdateInfoEventArgs info ) {
this . Owner = owner ;
this . Info = info ;
this . InitializeComponent ( ) ;
this . DataContext = this ;
if ( info . ChangelogURL ! = null ) {
Task . Run ( async ( ) = > {
using var client = new HttpClient ( ) ;
try {
var changelog = await client . GetStringAsync ( info . ChangelogURL ) ;
this . Dispatch ( ( ) = > this . Changelog . Text = changelog ) ;
} catch ( HttpRequestException ex ) {
this . Dispatch ( ( ) = > this . Changelog . Text = $"Error fetching changelog:\n{ex.Message}\n\n{info.ChangelogURL}" ) ;
}
} ) ;
}
var currentVersion = typeof ( App ) . Assembly . GetName ( ) . Version ? . ToString ( 3 ) ? ? "<UNKNOWN>" ;
this . UpdateInfo . Text = $"A new update is available. You are currently running version {currentVersion}. Version {info.CurrentVersion} is available. Would you like to update?" ;
}
private void Close_Click ( object sender , RoutedEventArgs e ) {
this . Close ( ) ;
}
private void Update_Click ( object sender , RoutedEventArgs e ) {
2021-02-07 17:08:40 +00:00
this . Downloading = true ;
2021-02-07 06:28:26 +00:00
if ( ! AutoUpdater . DownloadUpdate ( this . Info ) ) {
2021-02-07 17:08:40 +00:00
this . Downloading = false ;
2021-02-07 06:28:26 +00:00
return ;
}
this . App . Shutdown ( ) ;
}
}
}