mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-19 17:12:22 +01:00
Put upgrade helpers in upgrade service. Unify changelog display.
This commit is contained in:
1 parent
c913c601de
commit
db280c8ebe
11 files changed
+299
-324
No files matched your search
@@ -16,24 +16,6 @@
|
||||
<services:SettingsService x:Key="Settings" />
|
||||
<services:UpgradeService x:Key="Upgrade" />
|
||||
|
||||
<!-- Converters -->
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<generic:BoolToVisibility x:Key="BoolToVisibility"/>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="InvBoolToVisibility">
|
||||
<generic:BoolInverterConverter/>
|
||||
<generic:BoolToVisibility/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="EnumEqualsToVisibility">
|
||||
<generic:ValueToString/>
|
||||
<generic:EqualsConverter/>
|
||||
<generic:BoolToVisibility/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToBrush" />
|
||||
<valueConverters:ConversionJobToEstimatedRemainingDuration x:Key="ConversionJobToEstimatedRemainingDuration" />
|
||||
|
||||
<!-- Markdown style -->
|
||||
<Style TargetType="FlowDocument" x:Key="DocumentStyle">
|
||||
<Setter Property="FontFamily" Value="Segoe UI" />
|
||||
@@ -66,11 +48,33 @@
|
||||
</Style>
|
||||
|
||||
<xaml:Markdown x:Key="Markdown"
|
||||
DocumentStyle="{StaticResource DocumentStyle}"
|
||||
Heading1Style="{StaticResource PageHeader}"
|
||||
Heading2Style="{StaticResource SubHeader}"
|
||||
Heading3Style="{StaticResource SubHeaderSecondary}"/>
|
||||
DocumentStyle="{StaticResource DocumentStyle}"
|
||||
Heading1Style="{StaticResource PageHeader}"
|
||||
Heading2Style="{StaticResource SubHeader}"
|
||||
Heading3Style="{StaticResource SubHeaderSecondary}"/>
|
||||
|
||||
<xaml:TextToFlowDocumentConverter x:Key="TextToFlowDocumentConverter" Markdown="{StaticResource Markdown}"/>
|
||||
<!-- Converters -->
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<generic:BoolToVisibility x:Key="BoolToVisibility"/>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="InvBoolToVisibility">
|
||||
<generic:BoolInverterConverter/>
|
||||
<generic:BoolToVisibility/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="EnumEqualsToVisibility">
|
||||
<generic:ValueToString/>
|
||||
<generic:EqualsConverter/>
|
||||
<generic:BoolToVisibility/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToBrush" />
|
||||
<valueConverters:ConversionJobToEstimatedRemainingDuration x:Key="ConversionJobToEstimatedRemainingDuration" />
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ChangelogToMarkdown">
|
||||
<valueConverters:ChangelogConverter/>
|
||||
<xaml:TextToFlowDocumentConverter Markdown="{StaticResource Markdown}"/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -190,11 +190,11 @@
|
||||
<Compile Include="Services\UpgradeService.cs" />
|
||||
<Compile Include="Settings.Migration.cs" />
|
||||
<Compile Include="Settings.Settings.cs" />
|
||||
<Compile Include="Upgrade\Helpers.cs" />
|
||||
<Compile Include="Upgrade\UpgradeVersionDescription.cs" />
|
||||
<Compile Include="Services\UpgradeVersionDescription.cs" />
|
||||
<Compile Include="ValueConverters\ConversionJobsToProgressState.cs" />
|
||||
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionPreset.cs" />
|
||||
<Compile Include="ValueConverters\ChangelogConverter.cs" />
|
||||
<Compile Include="ValueConverters\ConversionJobToEstimatedRemainingDuration.cs" />
|
||||
<Compile Include="ValueConverters\ConversionJobsToProgressValue.cs" />
|
||||
<Compile Include="ValueConverters\OutputTypeEnumToViewModel.cs" />
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace FileConverter.Services
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface IUpgradeService
|
||||
{
|
||||
event System.EventHandler<UpgradeVersionDescription> NewVersionAvailable;
|
||||
@@ -16,5 +18,7 @@ namespace FileConverter.Services
|
||||
void StartUpgrade();
|
||||
|
||||
void CancelUpgrade();
|
||||
|
||||
Task<string> GetChangeLogAsync(UpgradeService.OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,41 @@
|
||||
namespace FileConverter.Services
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
|
||||
public class UpgradeService : ObservableObject, IUpgradeService
|
||||
{
|
||||
#if DEBUG
|
||||
private const string BaseURI = "https://raw.githubusercontent.com/Tichau/FileConverter/integration/";
|
||||
#else
|
||||
private const string BaseURI = "https://raw.githubusercontent.com/Tichau/FileConverter/master/";
|
||||
#endif
|
||||
|
||||
[NotNull]
|
||||
private readonly WebClient webClient = new WebClient();
|
||||
|
||||
private UpgradeVersionDescription upgradeVersionDescription;
|
||||
|
||||
public UpgradeService()
|
||||
{
|
||||
this.UpgradeVersionDescription = new UpgradeVersionDescription();
|
||||
SimpleIoc.Default.Register<IUpgradeService>(() => this);
|
||||
}
|
||||
|
||||
public delegate void OnUpgradeOperationCompletedEventHandler(UpgradeVersionDescription upgradeVersionDescription);
|
||||
|
||||
public event System.EventHandler<UpgradeVersionDescription> NewVersionAvailable;
|
||||
|
||||
public UpgradeVersionDescription UpgradeVersionDescription
|
||||
@@ -28,13 +49,13 @@ namespace FileConverter.Services
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CheckForUpgrade()
|
||||
{
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
Task<UpgradeVersionDescription> task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
|
||||
Task<UpgradeVersionDescription> task = this.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
|
||||
#else
|
||||
long fileTime = Registry.GetValue<long>(Registry.Keys.LastUpdateCheckDate);
|
||||
DateTime lastUpdateDateTime = DateTime.FromFileTime(fileTime);
|
||||
@@ -42,7 +63,7 @@ namespace FileConverter.Services
|
||||
TimeSpan durationSinceLastUpdate = DateTime.Now.Subtract(lastUpdateDateTime);
|
||||
if (durationSinceLastUpdate > new TimeSpan(1, 0, 0, 0))
|
||||
{
|
||||
Task<UpgradeVersionDescription> task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
|
||||
Task<UpgradeVersionDescription> task = this.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -63,7 +84,7 @@ namespace FileConverter.Services
|
||||
try
|
||||
{
|
||||
this.UpgradeVersionDescription.NeedToUpgrade = true;
|
||||
Task task = Upgrade.Helpers.DownloadInstallerAsync(this.upgradeVersionDescription);
|
||||
Task task = this.DownloadInstallerAsync();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -75,14 +96,43 @@ namespace FileConverter.Services
|
||||
{
|
||||
if (this.UpgradeVersionDescription == null)
|
||||
{
|
||||
Diagnostics.Debug.Log("Can't cancel upgrade because there is no upgrade in progress.");
|
||||
Debug.Log("Can't cancel upgrade because there is no upgrade in progress.");
|
||||
return;
|
||||
}
|
||||
|
||||
Diagnostics.Debug.Log("Cancel application upgrade.");
|
||||
Debug.Log("Cancel application upgrade.");
|
||||
this.UpgradeVersionDescription.NeedToUpgrade = false;
|
||||
}
|
||||
|
||||
public async Task<string> GetChangeLogAsync(OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null)
|
||||
{
|
||||
if (this.UpgradeVersionDescription == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(this.UpgradeVersionDescription));
|
||||
}
|
||||
|
||||
this.UpgradeVersionDescription.ChangeLog = Properties.Resources.DownloadingChangeLog;
|
||||
|
||||
Uri uri = new Uri(UpgradeService.BaseURI + "CHANGELOG.md");
|
||||
try
|
||||
{
|
||||
Stream stream = await this.webClient.OpenReadTaskAsync(uri);
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
this.UpgradeVersionDescription.ChangeLog = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Debug.LogError("Error while retrieving change log.");
|
||||
return null;
|
||||
}
|
||||
|
||||
onGetCompleteDelegate?.Invoke(this.UpgradeVersionDescription);
|
||||
|
||||
return this.UpgradeVersionDescription.ChangeLog;
|
||||
}
|
||||
|
||||
private void OnGetLatestVersionDescription(UpgradeVersionDescription description)
|
||||
{
|
||||
if (description == null)
|
||||
@@ -101,5 +151,123 @@ namespace FileConverter.Services
|
||||
|
||||
this.NewVersionAvailable?.Invoke(this, description);
|
||||
}
|
||||
|
||||
private async Task<UpgradeVersionDescription> GetLatestVersionDescriptionAsync(OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null)
|
||||
{
|
||||
#if BUILD32
|
||||
Uri uri = new Uri(Helpers.BaseURI + "version (x86).xml");
|
||||
#else
|
||||
Uri uri = new Uri(UpgradeService.BaseURI + "version.xml");
|
||||
#endif
|
||||
|
||||
UpgradeVersionDescription description = null;
|
||||
try
|
||||
{
|
||||
Stream stream = await this.webClient.OpenReadTaskAsync(uri);
|
||||
|
||||
XmlRootAttribute xmlRoot = new XmlRootAttribute
|
||||
{
|
||||
ElementName = "Version"
|
||||
};
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(UpgradeVersionDescription), xmlRoot);
|
||||
|
||||
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
|
||||
{
|
||||
IgnoreWhitespace = true,
|
||||
IgnoreComments = true
|
||||
};
|
||||
|
||||
using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
|
||||
{
|
||||
description = (UpgradeVersionDescription)serializer.Deserialize(xmlReader);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Debug.Log("Error while retrieving change log.");
|
||||
return null;
|
||||
}
|
||||
|
||||
onGetCompleteDelegate?.Invoke(description);
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
private async Task DownloadInstallerAsync()
|
||||
{
|
||||
if (this.UpgradeVersionDescription == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(this.UpgradeVersionDescription));
|
||||
}
|
||||
|
||||
if (this.UpgradeVersionDescription.InstallerDownloadInProgress)
|
||||
{
|
||||
throw new Exception("The installer download is currently in progress.");
|
||||
}
|
||||
|
||||
Uri uri = new Uri(this.UpgradeVersionDescription.InstallerURL);
|
||||
|
||||
string fileName = "FileConverter-setup.msi";
|
||||
Regex retrieveFileNameRegex = new Regex("/([^/]*)");
|
||||
MatchCollection matchCollection = retrieveFileNameRegex.Matches(this.UpgradeVersionDescription.InstallerURL);
|
||||
if (matchCollection.Count > 0)
|
||||
{
|
||||
Match match = matchCollection[matchCollection.Count - 1];
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
fileName = match.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
|
||||
string tempPath = System.IO.Path.GetTempPath();
|
||||
string installerPath = System.IO.Path.Combine(tempPath, fileName);
|
||||
|
||||
this.UpgradeVersionDescription.InstallerPath = installerPath;
|
||||
this.UpgradeVersionDescription.InstallerDownloadInProgress = true;
|
||||
this.UpgradeVersionDescription.InstallerDownloadProgress = 0;
|
||||
|
||||
// Source: https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel#2904963
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
this.webClient.DownloadProgressChanged += this.WebClient_DownloadProgressChanged;
|
||||
this.webClient.DownloadFileCompleted += this.WebClient_DownloadFileCompleted;
|
||||
Task downloadTask = this.webClient.DownloadFileTaskAsync(uri, installerPath);
|
||||
if (downloadTask != null)
|
||||
{
|
||||
await downloadTask;
|
||||
}
|
||||
}
|
||||
|
||||
private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
this.webClient.DownloadProgressChanged -= this.WebClient_DownloadProgressChanged;
|
||||
this.webClient.DownloadFileCompleted -= this.WebClient_DownloadFileCompleted;
|
||||
|
||||
if (e.Error != null)
|
||||
{
|
||||
Debug.LogError("Failed to download the new File Converter upgrade. You should try again or download it manually.");
|
||||
Debug.Log(e.Error.ToString());
|
||||
if (this.UpgradeVersionDescription != null)
|
||||
{
|
||||
this.UpgradeVersionDescription.NeedToUpgrade = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.UpgradeVersionDescription != null)
|
||||
{
|
||||
this.UpgradeVersionDescription.InstallerDownloadProgress = 100;
|
||||
this.UpgradeVersionDescription.InstallerDownloadInProgress = false;
|
||||
this.UpgradeVersionDescription = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs eventArgs)
|
||||
{
|
||||
if (this.UpgradeVersionDescription != null)
|
||||
{
|
||||
this.UpgradeVersionDescription.InstallerDownloadProgress = eventArgs.ProgressPercentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -1,6 +1,6 @@
|
||||
// <copyright file="UpgradeVersionDescription.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
namespace FileConverter.Services
|
||||
{
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -8,12 +8,14 @@ namespace FileConverter
|
||||
|
||||
using FileConverter.Annotations;
|
||||
|
||||
public class UpgradeVersionDescription : INotifyPropertyChanged
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
public class UpgradeVersionDescription : ObservableObject
|
||||
{
|
||||
private int installerDownloadProgress;
|
||||
private bool installerDownloadInProgress;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private string changeLog;
|
||||
|
||||
[XmlElement("Latest")]
|
||||
public Version LatestVersion
|
||||
@@ -28,12 +30,16 @@ namespace FileConverter
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
[XmlIgnore]
|
||||
public string ChangeLog
|
||||
{
|
||||
get;
|
||||
set;
|
||||
get => this.changeLog;
|
||||
set
|
||||
{
|
||||
this.changeLog = value;
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
@@ -54,9 +60,9 @@ namespace FileConverter
|
||||
set
|
||||
{
|
||||
this.installerDownloadInProgress = value;
|
||||
this.OnPropertyChanged();
|
||||
this.OnPropertyChanged(nameof(this.InstallerDownloadDone));
|
||||
this.OnPropertyChanged(nameof(this.InstallerDownloadNotStarted));
|
||||
this.RaisePropertyChanged();
|
||||
this.RaisePropertyChanged(nameof(this.InstallerDownloadDone));
|
||||
this.RaisePropertyChanged(nameof(this.InstallerDownloadNotStarted));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +77,9 @@ namespace FileConverter
|
||||
set
|
||||
{
|
||||
this.installerDownloadProgress = value;
|
||||
this.OnPropertyChanged();
|
||||
this.OnPropertyChanged(nameof(this.InstallerDownloadDone));
|
||||
this.OnPropertyChanged(nameof(this.InstallerDownloadNotStarted));
|
||||
this.RaisePropertyChanged();
|
||||
this.RaisePropertyChanged(nameof(this.InstallerDownloadDone));
|
||||
this.RaisePropertyChanged(nameof(this.InstallerDownloadNotStarted));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,11 +107,5 @@ namespace FileConverter
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
// <copyright file="Helpers.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.Upgrade
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public static class Helpers
|
||||
{
|
||||
#if DEBUG
|
||||
private const string BaseURI = "https://raw.githubusercontent.com/Tichau/FileConverter/integration/";
|
||||
#else
|
||||
private const string BaseURI = "https://raw.githubusercontent.com/Tichau/FileConverter/master/";
|
||||
#endif
|
||||
|
||||
private static WebClient webClient = new WebClient();
|
||||
private static UpgradeVersionDescription currentlyDownloadedVersionDescription;
|
||||
|
||||
public delegate void OnUpgradeOperationCompletedEventHandler(UpgradeVersionDescription upgradeVersionDescription);
|
||||
|
||||
public static async Task<UpgradeVersionDescription> GetLatestVersionDescriptionAsync(OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null)
|
||||
{
|
||||
#if BUILD32
|
||||
Uri uri = new Uri(Helpers.BaseURI + "version (x86).xml");
|
||||
#else
|
||||
Uri uri = new Uri(Helpers.BaseURI + "version.xml");
|
||||
#endif
|
||||
|
||||
Stream stream = await Helpers.webClient.OpenReadTaskAsync(uri);
|
||||
|
||||
UpgradeVersionDescription upgradeVersionDescription = null;
|
||||
try
|
||||
{
|
||||
XmlRootAttribute xmlRoot = new XmlRootAttribute
|
||||
{
|
||||
ElementName = "Version"
|
||||
};
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(UpgradeVersionDescription), xmlRoot);
|
||||
|
||||
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
|
||||
{
|
||||
IgnoreWhitespace = true,
|
||||
IgnoreComments = true
|
||||
};
|
||||
|
||||
using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
|
||||
{
|
||||
upgradeVersionDescription = (UpgradeVersionDescription)serializer.Deserialize(xmlReader);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Diagnostics.Debug.LogError("Error while retrieving change log.");
|
||||
return null;
|
||||
}
|
||||
|
||||
onGetCompleteDelegate?.Invoke(upgradeVersionDescription);
|
||||
|
||||
return upgradeVersionDescription;
|
||||
}
|
||||
|
||||
public static async Task<string> GetChangeLogAsync(UpgradeVersionDescription upgradeVersionDescription, OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null)
|
||||
{
|
||||
if (upgradeVersionDescription == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(upgradeVersionDescription));
|
||||
}
|
||||
|
||||
Uri uri = new Uri(Helpers.BaseURI + "CHANGELOG.md");
|
||||
Stream stream = await Helpers.webClient.OpenReadTaskAsync(uri);
|
||||
try
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
upgradeVersionDescription.ChangeLog = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Diagnostics.Debug.LogError("Error while retrieving change log.");
|
||||
return null;
|
||||
}
|
||||
|
||||
onGetCompleteDelegate?.Invoke(upgradeVersionDescription);
|
||||
|
||||
return upgradeVersionDescription.ChangeLog;
|
||||
}
|
||||
|
||||
public static async Task DownloadInstallerAsync(UpgradeVersionDescription upgradeVersionDescription)
|
||||
{
|
||||
if (upgradeVersionDescription == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(upgradeVersionDescription));
|
||||
}
|
||||
|
||||
if (Helpers.currentlyDownloadedVersionDescription != null)
|
||||
{
|
||||
throw new Exception("The installer download is currently in progress.");
|
||||
}
|
||||
|
||||
Uri uri = new Uri(upgradeVersionDescription.InstallerURL);
|
||||
|
||||
string fileName = "FileConverter-setup.msi";
|
||||
Regex retrieveFileNameRegex = new Regex("/([^/]*)");
|
||||
MatchCollection matchCollection = retrieveFileNameRegex.Matches(upgradeVersionDescription.InstallerURL);
|
||||
if (matchCollection.Count > 0)
|
||||
{
|
||||
Match match = matchCollection[matchCollection.Count - 1];
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
fileName = match.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
|
||||
string tempPath = System.IO.Path.GetTempPath();
|
||||
string installerPath = System.IO.Path.Combine(tempPath, fileName);
|
||||
|
||||
upgradeVersionDescription.InstallerPath = installerPath;
|
||||
upgradeVersionDescription.InstallerDownloadInProgress = true;
|
||||
upgradeVersionDescription.InstallerDownloadProgress = 0;
|
||||
|
||||
Helpers.currentlyDownloadedVersionDescription = upgradeVersionDescription;
|
||||
|
||||
// Source: https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel#2904963
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
Helpers.webClient.DownloadProgressChanged += Helpers.WebClient_DownloadProgressChanged;
|
||||
Helpers.webClient.DownloadFileCompleted += Helpers.WebClient_DownloadFileCompleted;
|
||||
Task downloadTask = Helpers.webClient.DownloadFileTaskAsync(uri, installerPath);
|
||||
if (downloadTask != null)
|
||||
{
|
||||
await downloadTask;
|
||||
}
|
||||
}
|
||||
|
||||
private static void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
Helpers.webClient.DownloadProgressChanged -= WebClient_DownloadProgressChanged;
|
||||
Helpers.webClient.DownloadFileCompleted -= WebClient_DownloadFileCompleted;
|
||||
|
||||
if (e.Error != null)
|
||||
{
|
||||
Debug.LogError("Failed to download the new File Converter upgrade. You should try again or download it manually.");
|
||||
Debug.Log(e.Error.ToString());
|
||||
if (Helpers.currentlyDownloadedVersionDescription != null)
|
||||
{
|
||||
Helpers.currentlyDownloadedVersionDescription.NeedToUpgrade = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Helpers.currentlyDownloadedVersionDescription != null)
|
||||
{
|
||||
Helpers.currentlyDownloadedVersionDescription.InstallerDownloadProgress = 100;
|
||||
Helpers.currentlyDownloadedVersionDescription.InstallerDownloadInProgress = false;
|
||||
Helpers.currentlyDownloadedVersionDescription = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs eventArgs)
|
||||
{
|
||||
if (Helpers.currentlyDownloadedVersionDescription != null)
|
||||
{
|
||||
Helpers.currentlyDownloadedVersionDescription.InstallerDownloadProgress = eventArgs.ProgressPercentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// <copyright file="ChangelogConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public class ChangelogConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
bool header = false;
|
||||
if (parameter != null)
|
||||
{
|
||||
switch (parameter)
|
||||
{
|
||||
case string s:
|
||||
{
|
||||
if (!bool.TryParse(s, out header))
|
||||
{
|
||||
Debug.LogError($"Invalid parameter {s}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case bool b:
|
||||
header = b;
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogError($"Invalid parameter {parameter}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string content = string.Empty;
|
||||
if (header)
|
||||
{
|
||||
content += Properties.Resources.LicenceHeader1 + "\n";
|
||||
content += Properties.Resources.LicenceHeader2 + "\n\n";
|
||||
content += Properties.Resources.LicenceHeader3 + "\n\n";
|
||||
}
|
||||
|
||||
string changelog = (string)value;
|
||||
content += changelog;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,15 @@
|
||||
|
||||
namespace FileConverter.ViewModels
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
using FileConverter.ConversionJobs;
|
||||
using FileConverter.Services;
|
||||
|
||||
using GalaSoft.MvvmLight;
|
||||
@@ -56,7 +52,6 @@ namespace FileConverter.ViewModels
|
||||
private ListCollectionView outputTypes;
|
||||
private CultureInfo[] supportedCultures;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SettingsViewModel class.
|
||||
/// </summary>
|
||||
@@ -183,25 +178,6 @@ namespace FileConverter.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public string AboutSectionContent
|
||||
{
|
||||
get
|
||||
{
|
||||
string content = Properties.Resources.LicenceHeader1 + "\n";
|
||||
content += Properties.Resources.LicenceHeader2 + "\n\n";
|
||||
content += Properties.Resources.LicenceHeader3 + "\n\n";
|
||||
content += this.releaseNoteContent;
|
||||
return content;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.releaseNoteContent = value;
|
||||
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisplaySeeChangeLogLink
|
||||
{
|
||||
get
|
||||
@@ -333,10 +309,8 @@ namespace FileConverter.ViewModels
|
||||
|
||||
private void DownloadChangeLogAction()
|
||||
{
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
Upgrade.Helpers.GetChangeLogAsync(new UpgradeVersionDescription(), description => this.AboutSectionContent = description.ChangeLog);
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
this.AboutSectionContent = Properties.Resources.DownloadingChangeLog;
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
upgradeService.GetChangeLogAsync();
|
||||
this.DisplaySeeChangeLogLink = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace FileConverter.ViewModels
|
||||
/// </summary>
|
||||
public class UpgradeViewModel : ViewModelBase
|
||||
{
|
||||
private UpgradeVersionDescription upgradeVersionDescription;
|
||||
private string releaseNoteContent;
|
||||
private readonly IUpgradeService upgradeService;
|
||||
|
||||
private RelayCommand downloadInstallerCommand;
|
||||
private RelayCommand launchInstallerCommand;
|
||||
@@ -38,19 +37,8 @@ namespace FileConverter.ViewModels
|
||||
/// </summary>
|
||||
public UpgradeViewModel()
|
||||
{
|
||||
if (this.IsInDesignMode)
|
||||
{
|
||||
// Code runs in Blend --> create design time data.
|
||||
UpgradeVersionDescription versionDescription = new UpgradeVersionDescription();
|
||||
versionDescription.LatestVersion = new Version() { Major = 0, Minor = 1, Patch = 0, };
|
||||
this.VersionDescription = versionDescription;
|
||||
}
|
||||
else
|
||||
{
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
this.VersionDescription = upgradeService.UpgradeVersionDescription;
|
||||
upgradeService.NewVersionAvailable += this.UpgradeService_NewVersionAvailable;
|
||||
}
|
||||
this.upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
this.upgradeService.GetChangeLogAsync();
|
||||
}
|
||||
|
||||
public ICommand DownloadInstallerCommand
|
||||
@@ -92,55 +80,9 @@ namespace FileConverter.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public UpgradeVersionDescription VersionDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.upgradeVersionDescription;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.upgradeVersionDescription = value;
|
||||
|
||||
Task<string> task = Upgrade.Helpers.GetChangeLogAsync(this.upgradeVersionDescription, this.OnChangeLogRetrieved);
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string ReleaseNote
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.releaseNoteContent))
|
||||
{
|
||||
return Properties.Resources.DownloadingChangeLog;
|
||||
}
|
||||
|
||||
return this.releaseNoteContent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.releaseNoteContent = value;
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpgradeService_NewVersionAvailable(object sender, UpgradeVersionDescription newVersion)
|
||||
{
|
||||
this.VersionDescription = newVersion;
|
||||
}
|
||||
|
||||
private void OnChangeLogRetrieved(UpgradeVersionDescription versionDescription)
|
||||
{
|
||||
this.ReleaseNote = versionDescription.ChangeLog;
|
||||
}
|
||||
|
||||
private void ExecuteDownloadInstallerCommand()
|
||||
{
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
upgradeService.StartUpgrade();
|
||||
this.upgradeService.StartUpgrade();
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Close(Pages.Upgrade, false);
|
||||
|
||||
@@ -308,8 +308,8 @@
|
||||
</DockPanel>
|
||||
|
||||
<DockPanel Grid.Row="1" Grid.Column="0" Margin="0,0,5,0">
|
||||
<FlowDocumentScrollViewer Grid.Row="0" Grid.Column="0" Margin="5,10,5,10" HorizontalAlignment="Stretch" VerticalAlignment="Top" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
|
||||
Document="{Binding AboutSectionContent, Converter={StaticResource TextToFlowDocumentConverter}}" DockPanel.Dock="Top"/>
|
||||
<FlowDocumentScrollViewer Grid.Row="0" Grid.Column="0" Margin="5,10,5,10" HorizontalAlignment="Stretch" VerticalAlignment="Top" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Top"
|
||||
Document="{Binding UpgradeVersionDescription.ChangeLog, Source={StaticResource Upgrade}, Converter={StaticResource ChangelogToMarkdown}, ConverterParameter=True|}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Margin="5" DockPanel.Dock="Top" FontSize="14" HorizontalAlignment="Center"
|
||||
Visibility="{Binding DisplaySeeChangeLogLink, Mode=OneWay, Converter={StaticResource BoolToVisibility}}">
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
<TextBlock Margin="5"
|
||||
Text="{x:Static project:Resources.UpgradeAvailable}" TextWrapping="Wrap"/>
|
||||
|
||||
<FlowDocumentScrollViewer Grid.Row="2" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Document="{Binding ReleaseNote, Converter={StaticResource TextToFlowDocumentConverter}}"/>
|
||||
<FlowDocumentScrollViewer Grid.Row="2" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Document="{Binding UpgradeVersionDescription.ChangeLog, Source={StaticResource Upgrade}, Converter={StaticResource ChangelogToMarkdown}}"/>
|
||||
|
||||
<!-- Download button -->
|
||||
<Button Background="WhiteSmoke" Grid.Row="3" Padding="10,5,10,5" Margin="5" HorizontalContentAlignment="Left" Command="{Binding DownloadInstallerCommand}"
|
||||
Visibility="{Binding VersionDescription.InstallerDownloadNotStarted, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
Visibility="{Binding UpgradeVersionDescription.InstallerDownloadNotStarted, Source={StaticResource Upgrade}, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
<Button.Content>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
<!-- Download in progress -->
|
||||
<Grid Grid.Row="3" Margin="5"
|
||||
Visibility="{Binding VersionDescription.InstallerDownloadInProgress, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
Visibility="{Binding UpgradeVersionDescription.InstallerDownloadInProgress, Source={StaticResource Upgrade}, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="64"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@@ -71,13 +71,13 @@
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Content="{x:Static project:Resources.UpgradeDownloadInProgress}" FontSize="14.667"/>
|
||||
<ProgressBar Grid.Row="1" Margin="5" Height="30" Foreground="#004B82" Minimum="0" Maximum="100"
|
||||
Value="{Binding VersionDescription.InstallerDownloadProgress}"/>
|
||||
Value="{Binding UpgradeVersionDescription.InstallerDownloadProgress, Source={StaticResource Upgrade}}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<!-- Install button -->
|
||||
<Button Background="WhiteSmoke" Grid.Row="3" Padding="10,5,10,5" Margin="5" HorizontalContentAlignment="Left" Command="{Binding LaunchInstallerCommand}"
|
||||
Visibility="{Binding VersionDescription.InstallerDownloadDone, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
Visibility="{Binding UpgradeVersionDescription.InstallerDownloadDone, Source={StaticResource Upgrade}, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed}">
|
||||
<Button.Content>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
Reference in new issue
Block a user