Permalink
Switch branches/tags
IDictionary-PubSub-Model AnyCPU-DX9-DX11 3.0.6761.40731 3.0.6758.40638 3.0.6441.35076 3.0.6427.17667 3.0.6409.35844 3.0.6402.24295 3.0.6400.32643 3.0.6395.32100 3.0.6392.18124 3.0.6391.35303 3.0.6391.18069 3.0.6383.18916 3.0.6383.223 3.0.6379.40728 3.0.6379.35597 3.0.6377.38482 3.0.6134.35573 3.0.5898.36428 3.0.5834.15042 3.0.5814.19716 3.0.5813.18369 3.0.5812.37251 3.0.5810.33872 3.0.5801.35974 3.0.5794.33436 3.0.5673.24391 3.0.5673.14425 3.0.5668.33057 3.0.5666.36582 3.0.5666.14749 3.0.5662.22794 3.0.5661.34112 3.0.5661.13091 3.0.5658.31200 3.0.5658.21972 3.0.5657.38413 3.0.5635.15843 3.0.5592.38336 3.0.5592.26103 3.0.5591.32096 3.0.5590.24659 3.0.5589.24942 3.0.5580.33145 3.0.5575.10294 3.0.5557.12288 3.0.5541.25524 3.0.5541.18798 3.0.5536.26837 3.0.5531.5431 3.0.5522.23271 3.0.5518.25820 3.0.5515.15265 3.0.5512.33349 3.0.5512.22932 3.0.5500.34975 3.0.5470.15461 3.0.5424.15207 3.0.5415.36653 3.0.5399.32231 3.0.5399.19376 3.0.5373.34340 3.0.5305.21874 3.0.5302.34037 3.0.5297.31340 3.0.5270.22631 3.0.5236.12525 3.0.5234.39295 3.0.5199.31150 3.0.5182.28512 3.0.5180.19752 3.0.5171.37963 3.0.5166.29044 3.0.5154.42899 3.0.5151.38425 3.0.5150.39125 3.0.5150.23737 3.0.5149.22159 3.0.5146.21931 3.0.5143.39535 3.0.5141.40333 3.0.5141.40022 3.0.5141.38511 3.0.5138.28759 3.0.5138.26815 3.0.5138.19782 3.0.5136.23315 3.0.5135.39305 3.0.5129.36799 3.0.5125.35655 3.0.5124.28712 3.0.5124.2415 3.0.5123.19492 3.0.5122.42910 3.0.5121.33063 3.0.5121.25183 3.0.5120.38788 3.0.5120.27848 3.0.5119.34450
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
180 lines (161 sloc) 7.17 KB
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MainWindow.xaml.cs" company="SyndicatedLife">
// Copyright(c) 2018 Ryan Wilson &amp;lt;syndicated.life@gmail.com&amp;gt; (http://syndicated.life/)
// Licensed under the MIT license. See LICENSE.md in the solution root for full license information.
// </copyright>
// <summary>
// MainWindow.xaml.cs Implementation
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace FFXIVAPP.Updater {
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Ionic.Zip;
using NLog;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : INotifyPropertyChanged {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly WebClient _webClient = new WebClient();
public MainWindow() {
this.InitializeComponent();
}
public event PropertyChangedEventHandler PropertyChanged = delegate { };
/// <summary>
/// </summary>
private void CleanupTemporary(string path) {
try {
FileInfo[] fileInfos = new DirectoryInfo(path).GetFiles();
foreach (FileInfo fileInfo in fileInfos.Where(t => t.Extension == ".tmp" || t.Extension == ".PendingOverwrite")) {
fileInfo.Delete();
}
}
catch (Exception) {
// IGNORED
}
}
private void CloseUpdater_OnClick(object sender, RoutedEventArgs e) {
Application.Current.Shutdown(0);
}
/// <summary>
/// </summary>
private void DownloadUpdate() {
this.GoogleAnalytics.Navigate("https://ffxiv-app.com/Analytics/Google/?eCategory=Application Update&eAction=Download&eLabel=FFXIVAPP");
this.GoogleAnalytics.LoadCompleted += delegate {
try {
this._webClient.DownloadFileCompleted += this.WebClientOnDownloadFileCompleted;
this._webClient.DownloadProgressChanged += this.WebClientOnDownloadProgressChanged;
this._webClient.DownloadFileAsync(new Uri(MainWindowViewModel.Instance.DownloadURI), MainWindowViewModel.Instance.ZipFileName);
}
catch (Exception) {
Environment.Exit(0);
}
};
}
private void ExtractAndClean() {
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
this.CleanupTemporary(path);
using (ZipFile zip = ZipFile.Read(MainWindowViewModel.Instance.ZipFileName)) {
foreach (ZipEntry zipEntry in zip) {
try {
if (File.Exists("FFXIVAPP.Client.exe.nlog") && zipEntry.FileName.Contains("FFXIVAPP.Client.exe.nlog")) {
continue;
}
zipEntry.Extract(path, ExtractExistingFileAction.OverwriteSilently);
}
catch (Exception ex) {
// IGNORED
}
}
}
this._webClient.Dispose();
try {
var m = new Process {
StartInfo = {
FileName = "FFXIVAPP.Client.exe"
}
};
m.Start();
}
catch (Exception) {
// IGNORED
}
finally {
this._webClient.DownloadFileCompleted -= this.WebClientOnDownloadFileCompleted;
this._webClient.DownloadProgressChanged -= this.WebClientOnDownloadProgressChanged;
this.CleanupTemporary(path);
Environment.Exit(0);
}
}
private void RaisePropertyChanged([CallerMemberName] string caller = "") {
this.PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
private void UIElement_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) {
if (Mouse.LeftButton == MouseButtonState.Pressed) {
this.DragMove();
}
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="asyncCompletedEventArgs"></param>
private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs) {
Func<bool> download = delegate {
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(this.ExtractAndClean));
return true;
};
download.BeginInvoke(delegate { }, download);
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="downloadProgressChangedEventArgs"></param>
private void WebClientOnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs downloadProgressChangedEventArgs) {
var bytesIn = double.Parse(downloadProgressChangedEventArgs.BytesReceived.ToString(CultureInfo.InvariantCulture));
var totalBytes = double.Parse(downloadProgressChangedEventArgs.TotalBytesToReceive.ToString(CultureInfo.InvariantCulture));
this.ProgressBarSingle.Value = bytesIn / totalBytes;
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void WindowLoaded(object sender, RoutedEventArgs e) {
IDictionary properties = Application.Current.Properties;
if (properties["DownloadUri"] == null || properties["Version"] == null) {
Application.Current.Shutdown();
}
else {
MainWindowViewModel.Instance.DownloadURI = properties["DownloadUri"] as string;
MainWindowViewModel.Instance.Version = properties["Version"] as string;
MainWindowViewModel.Instance.ZipFileName = $"FFXIVAPP_{MainWindowViewModel.Instance.Version}.zip";
Process[] app = Process.GetProcessesByName("FFXIVAPP.Client");
foreach (Process p in app) {
try {
p.Kill();
}
catch (Exception) {
// IGNORED
}
}
Func<bool> update = delegate {
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(this.DownloadUpdate));
return true;
};
update.BeginInvoke(delegate { }, update);
}
}
}
}