Add software update system
This commit is contained in:
parent
801e1a415f
commit
b4061a7bdf
@ -19,15 +19,15 @@ namespace FileConverter
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.ConversionJobs;
|
||||
using FileConverter.Diagnostics;
|
||||
using FileConverter.Upgrade;
|
||||
|
||||
public partial class Application : System.Windows.Application
|
||||
{
|
||||
private int numberOfConversionThread = 1;
|
||||
|
||||
private static readonly Version Version = new Version()
|
||||
{
|
||||
Major = 0,
|
||||
@ -36,28 +36,17 @@ namespace FileConverter
|
||||
|
||||
private readonly List<ConversionJob> conversionJobs = new List<ConversionJob>();
|
||||
|
||||
private bool debugMode;
|
||||
private bool initialized;
|
||||
private int numberOfConversionThread = 1;
|
||||
|
||||
private bool needToRunConversionThread;
|
||||
private bool cancelAutoExit;
|
||||
private UpgradeVersionDescription upgradeVersionDescription = null;
|
||||
|
||||
public Application()
|
||||
{
|
||||
this.ConvertionJobs = this.conversionJobs.AsReadOnly();
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
this.Initialize();
|
||||
|
||||
if (this.initialized)
|
||||
{
|
||||
Thread fileConvertionThread = new Thread(this.ConvertFiles);
|
||||
fileConvertionThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public static Version ApplicationVersion
|
||||
{
|
||||
get
|
||||
@ -94,7 +83,68 @@ namespace FileConverter
|
||||
{
|
||||
this.cancelAutoExit = true;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
this.Initialize();
|
||||
|
||||
if (this.needToRunConversionThread)
|
||||
{
|
||||
Thread fileConvertionThread = new Thread(this.ConvertFiles);
|
||||
fileConvertionThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
Debug.Log("Exit application.");
|
||||
|
||||
if (this.upgradeVersionDescription != null && this.upgradeVersionDescription.NeedToUpgrade)
|
||||
{
|
||||
Debug.Log("A new version of file converter has been found: {0}.", this.upgradeVersionDescription.LatestVersion);
|
||||
|
||||
if (string.IsNullOrEmpty(this.upgradeVersionDescription.InstallerPath))
|
||||
{
|
||||
Debug.LogError("Invalid installer path.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Wait for the end of the installer download.");
|
||||
while (this.upgradeVersionDescription.InstallerDownloadInProgress)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
string installerPath = this.upgradeVersionDescription.InstallerPath;
|
||||
if (!System.IO.File.Exists(installerPath))
|
||||
{
|
||||
Debug.LogError("Can't find upgrade installer ({0}). Try to restart the application.", installerPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start process.
|
||||
Debug.Log("Start file converter upgrade from version {0} to {1}.", ApplicationVersion, this.upgradeVersionDescription.LatestVersion);
|
||||
|
||||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(installerPath);
|
||||
startInfo.UseShellExecute = true;
|
||||
|
||||
Debug.Log("Start upgrade process: {0}{1}.", System.IO.Path.GetFileName(startInfo.FileName), startInfo.Arguments);
|
||||
System.Diagnostics.Process process = new System.Diagnostics.Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
|
||||
process.Start();
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Release();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
Diagnostics.Debug.Log("The number of processors on this computer is {0}. Set the default number of conversion threads to {0}", Environment.ProcessorCount);
|
||||
@ -109,7 +159,7 @@ namespace FileConverter
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Retrieve arguments.
|
||||
Debug.Log("Retrieve arguments...");
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
@ -117,28 +167,27 @@ namespace FileConverter
|
||||
#if (DEBUG)
|
||||
if (args.Length <= 1)
|
||||
{
|
||||
this.debugMode = true;
|
||||
System.Array.Resize(ref args, 8);
|
||||
args[1] = "--conversion-preset";
|
||||
args[2] = "To Ogg";
|
||||
args[3] = "--verbose";
|
||||
|
||||
args[4] = @"D:\Test\TrailerV2 compressed.mkv";
|
||||
args[4] = @"D:\Test\image.png";
|
||||
args[4] = @"E:\Track01.cda";
|
||||
args[4] = @"D:\Test\Track01.mp3";
|
||||
args[5] = @"D:\Test\Track02.mp3";
|
||||
args[6] = @"D:\Test\Track03.mp3";
|
||||
args[7] = @"D:\Test\Track04.mp3";
|
||||
//args[1] = "--conversion-preset";
|
||||
//args[2] = "To Ogg";
|
||||
//args[3] = "--verbose";
|
||||
|
||||
//System.Array.Resize(ref args, 2);
|
||||
//args[1] = "--settings";
|
||||
//args[4] = @"D:\Test\TrailerV2 compressed.mkv";
|
||||
//args[4] = @"D:\Test\image.png";
|
||||
//args[4] = @"E:\Track01.cda";
|
||||
//args[4] = @"D:\Test\Track01.mp3";
|
||||
//args[5] = @"D:\Test\Track02.mp3";
|
||||
//args[6] = @"D:\Test\Track03.mp3";
|
||||
//args[7] = @"D:\Test\Track04.mp3";
|
||||
|
||||
System.Array.Resize(ref args, 5);
|
||||
args[1] = "--conversion-preset";
|
||||
args[2] = "To Aac";
|
||||
args[3] = "--verbose";
|
||||
args[4] = @"D:\Test\02 - Corn on the Cob.flac";
|
||||
System.Array.Resize(ref args, 2);
|
||||
args[1] = "--settings";
|
||||
|
||||
//System.Array.Resize(ref args, 5);
|
||||
//args[1] = "--conversion-preset";
|
||||
//args[2] = "To Wav";
|
||||
//args[3] = "--verbose";
|
||||
//args[4] = @"D:\Test\Track01.mp3";
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -150,6 +199,11 @@ namespace FileConverter
|
||||
|
||||
Debug.Log(string.Empty);
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
// TODO: Help windows to explain that this application is a context menu extension.
|
||||
}
|
||||
|
||||
ConversionPreset conversionPreset = null;
|
||||
List<string> filePaths = new List<string>();
|
||||
|
||||
@ -164,9 +218,14 @@ namespace FileConverter
|
||||
|
||||
switch (parameterTitle)
|
||||
{
|
||||
case "version":
|
||||
Console.Write(ApplicationVersion.ToString());
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
return;
|
||||
|
||||
case "settings":
|
||||
this.ShowSettings = true;
|
||||
return;
|
||||
break;
|
||||
|
||||
case "apply-settings":
|
||||
Settings.ApplyTemporarySettings();
|
||||
@ -191,7 +250,7 @@ namespace FileConverter
|
||||
|
||||
index++;
|
||||
continue;
|
||||
|
||||
|
||||
case "verbose":
|
||||
{
|
||||
this.Verbose = true;
|
||||
@ -200,7 +259,7 @@ namespace FileConverter
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogError("Unknown option {0}.", parameterTitle);
|
||||
Debug.LogError("Unknown application argument: '--{0}'.", parameterTitle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -210,41 +269,34 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
if (conversionPreset == null)
|
||||
if (this.Settings.CheckUpgradeAtStartup)
|
||||
{
|
||||
Debug.LogError("Can't retrieve the conversion preset from arguments.");
|
||||
return;
|
||||
Task<UpgradeVersionDescription> task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
|
||||
}
|
||||
|
||||
// Create convertion jobs.
|
||||
Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.Name);
|
||||
try
|
||||
if (conversionPreset != null)
|
||||
{
|
||||
for (int index = 0; index < filePaths.Count; index++)
|
||||
// Create convertion jobs.
|
||||
Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.Name);
|
||||
try
|
||||
{
|
||||
string inputFilePath = filePaths[index];
|
||||
ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath);
|
||||
conversionJob.PrepareConversion(inputFilePath);
|
||||
for (int index = 0; index < filePaths.Count; index++)
|
||||
{
|
||||
string inputFilePath = filePaths[index];
|
||||
ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath);
|
||||
conversionJob.PrepareConversion(inputFilePath);
|
||||
|
||||
this.conversionJobs.Add(conversionJob);
|
||||
this.conversionJobs.Add(conversionJob);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogError(exception.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
this.needToRunConversionThread = true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogError(exception.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
Debug.Log("Exit application.");
|
||||
|
||||
Debug.Release();
|
||||
}
|
||||
|
||||
private void ConvertFiles()
|
||||
@ -352,5 +404,21 @@ namespace FileConverter
|
||||
Debug.Log("The conversion job failed but there is an output file that does exists.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetLatestVersionDescription(UpgradeVersionDescription upgradeVersionDescription)
|
||||
{
|
||||
if (upgradeVersionDescription == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (upgradeVersionDescription.LatestVersion <= ApplicationVersion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.upgradeVersionDescription = upgradeVersionDescription;
|
||||
(this.MainWindow as MainWindow).OnNewVersionReleased(upgradeVersionDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,9 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Accessibility" />
|
||||
<Reference Include="Markdown.Xaml">
|
||||
<HintPath>..\..\Middleware\Markdown.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationUI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="ReachFramework" />
|
||||
<Reference Include="Ripper, Version=1.0.5806.33932, Culture=neutral, processorArchitecture=MSIL">
|
||||
@ -102,6 +105,8 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="Settings.Settings.cs" />
|
||||
<Compile Include="Upgrade\Helpers.cs" />
|
||||
<Compile Include="Upgrade\UpgradeVersionDescription.cs" />
|
||||
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionPreset.cs" />
|
||||
<Compile Include="ValueConverters\BitrateToString.cs" />
|
||||
@ -128,6 +133,9 @@
|
||||
<DependentUpon>SettingsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Version.cs" />
|
||||
<Compile Include="Windows\UpgradeWindow.xaml.cs">
|
||||
<DependentUpon>UpgradeWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="XmlHelpers.cs" />
|
||||
<Page Include="Controls\EncodingQualitySliderControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
@ -156,6 +164,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\UpgradeWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OutputType.cs" />
|
||||
@ -199,6 +211,9 @@
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\ApplicationIcon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\DownloadIcon.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
BIN
Application/FileConverter/Resources/DownloadIcon.png
Normal file
BIN
Application/FileConverter/Resources/DownloadIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
@ -2,19 +2,18 @@
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
public partial class Settings : IXmlSerializable
|
||||
{
|
||||
public const int Version = 1;
|
||||
|
||||
private double settingsWindowHeight = 640;
|
||||
private double settingsWindowWidth = 800;
|
||||
|
||||
private bool exitApplicationWhenConversionsFinished = true;
|
||||
private float durationBetweenEndOfConversionsAndApplicationExit = 3f;
|
||||
private ObservableCollection<ConversionPreset> conversionPresets = new ObservableCollection<ConversionPreset>();
|
||||
private bool checkUpgradeAtStartup = true;
|
||||
|
||||
[XmlAttribute]
|
||||
public int SerializationVersion
|
||||
@ -85,6 +84,21 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
[XmlElement]
|
||||
public bool CheckUpgradeAtStartup
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.checkUpgradeAtStartup;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.checkUpgradeAtStartup = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDeserializationComplete()
|
||||
{
|
||||
this.DurationBetweenEndOfConversionsAndApplicationExit = System.Math.Max(0, System.Math.Min(10, this.DurationBetweenEndOfConversionsAndApplicationExit));
|
||||
|
131
Application/FileConverter/Upgrade/Helpers.cs
Normal file
131
Application/FileConverter/Upgrade/Helpers.cs
Normal file
@ -0,0 +1,131 @@
|
||||
// <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.IO;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
public static class Helpers
|
||||
{
|
||||
#if DEBUG
|
||||
// https://github.com/Tichau/FileConverter/blob/development/version.xml
|
||||
private const string BaseURI = "file:///C:/Users/Adrien/Documents/GitHub/FileConverter/";
|
||||
#else
|
||||
private const string BaseURI = "https://github.com/Tichau/FileConverter/blob/master/";
|
||||
#endif
|
||||
|
||||
private static WebClient webClient = new WebClient();
|
||||
|
||||
public delegate void OnUpgradeOperationCompletedEventHandler(UpgradeVersionDescription upgradeVersionDescription);
|
||||
|
||||
public static async Task<UpgradeVersionDescription> GetLatestVersionDescriptionAsync(OnUpgradeOperationCompletedEventHandler onGetCompleteDelegate = null)
|
||||
{
|
||||
Uri uri = new Uri(Helpers.BaseURI + "version.xml");
|
||||
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("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 void DownloadInstallerAsync(UpgradeVersionDescription upgradeVersionDescription)
|
||||
{
|
||||
Thread thread = new Thread(Helpers.DownloadInstallerAsync);
|
||||
thread.Start(upgradeVersionDescription);
|
||||
}
|
||||
|
||||
private static void DownloadInstallerAsync(object parameter)
|
||||
{
|
||||
UpgradeVersionDescription upgradeVersionDescription = parameter as UpgradeVersionDescription;
|
||||
|
||||
if (upgradeVersionDescription == null)
|
||||
{
|
||||
throw new ArgumentNullException("upgradeVersionDescription");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Helpers.webClient.DownloadFile(uri, installerPath);
|
||||
|
||||
upgradeVersionDescription.InstallerDownloadInProgress = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
// <copyright file="UpgradeVersionDescription.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System.Xml.Serialization;
|
||||
|
||||
public class UpgradeVersionDescription
|
||||
{
|
||||
[XmlElement("Latest")]
|
||||
public Version LatestVersion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlElement("URL")]
|
||||
public string InstallerURL
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string ChangeLog
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string InstallerPath
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public bool InstallerDownloadInProgress
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public bool NeedToUpgrade
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,91 @@
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public struct Version
|
||||
using System.Xml.Serialization;
|
||||
|
||||
public struct Version : System.IComparable<Version>
|
||||
{
|
||||
[XmlAttribute]
|
||||
public int Major;
|
||||
|
||||
[XmlAttribute]
|
||||
public int Minor;
|
||||
|
||||
[XmlAttribute]
|
||||
public int Patch;
|
||||
|
||||
public static bool operator !=(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) != 0;
|
||||
}
|
||||
|
||||
public static bool operator ==(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) == 0;
|
||||
}
|
||||
|
||||
public static bool operator <=(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) <= 0;
|
||||
}
|
||||
|
||||
public static bool operator >=(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) >= 0;
|
||||
}
|
||||
|
||||
public static bool operator <(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) < 0;
|
||||
}
|
||||
|
||||
public static bool operator >(Version a, Version b)
|
||||
{
|
||||
return a.CompareTo(b) > 0;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}.{1}", this.Major, this.Minor);
|
||||
if (this.Patch == 0)
|
||||
{
|
||||
return string.Format("{0}.{1}", this.Major, this.Minor);
|
||||
}
|
||||
|
||||
return string.Format("{0}.{1}.{2}", this.Major, this.Minor, this.Patch);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Version))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Version other = (Version)obj;
|
||||
|
||||
return this.Major == other.Major && this.Minor == other.Minor && this.Patch == other.Patch;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public int CompareTo(Version other)
|
||||
{
|
||||
if (this.Major == other.Major && this.Minor == other.Minor && this.Patch == other.Patch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this.Major > other.Major ||
|
||||
(this.Major == other.Major && this.Minor > other.Minor) ||
|
||||
(this.Major == other.Major && this.Minor == other.Minor && this.Patch > other.Patch))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace FileConverter
|
||||
{
|
||||
private DiagnosticsWindow diagnosticsWindow;
|
||||
private SettingsWindow settingsWindow;
|
||||
private UpgradeWindow upgradeWindow;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@ -36,7 +37,13 @@ namespace FileConverter
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
public void OnNewVersionReleased(UpgradeVersionDescription upgradeVersionDescription)
|
||||
{
|
||||
this.ShowUpgradeWindow();
|
||||
this.upgradeWindow.VersionDescription = upgradeVersionDescription;
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
@ -94,5 +101,21 @@ namespace FileConverter
|
||||
application?.CancelAutoExit();
|
||||
this.settingsWindow.Show();
|
||||
}
|
||||
|
||||
private void ShowUpgradeWindow()
|
||||
{
|
||||
if (this.upgradeWindow != null && this.upgradeWindow.IsVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.upgradeWindow = new UpgradeWindow();
|
||||
}
|
||||
|
||||
Application application = Application.Current as Application;
|
||||
application?.CancelAutoExit();
|
||||
this.upgradeWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -343,12 +343,13 @@
|
||||
|
||||
<!-- Application settings -->
|
||||
<StackPanel x:Name="ApplicationSettingsPanel" Grid.Row="2" Margin="5,10,5,5">
|
||||
<CheckBox x:Name="QuitAtEndCheckBox" Content="Automaticaly exit when all conversions finished" IsChecked="{Binding ApplicationSettings.ExitApplicationWhenConversionsFinished, ElementName=window, Mode=TwoWay}" />
|
||||
<CheckBox x:Name="QuitAtEndCheckBox" Content="Automatically exit when all conversions finished" IsChecked="{Binding ApplicationSettings.ExitApplicationWhenConversionsFinished, ElementName=window, Mode=TwoWay}" />
|
||||
<DockPanel Margin="40,0,0,5" Visibility="{Binding IsChecked, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed, ElementName=QuitAtEndCheckBox}">
|
||||
<Label Content="Waiting duration :"/>
|
||||
<Slider x:Name="DurationBeforeQuitSlider" Value="{Binding ApplicationSettings.DurationBetweenEndOfConversionsAndApplicationExit, ElementName=window, Mode=TwoWay}" Minimum="0" Maximum="10" SmallChange="0.1" IsSnapToTickEnabled="True" Width="250" TickFrequency="0.1"/>
|
||||
<Label Content="{Binding Value, Converter={StaticResource DoubleToTimeString}, ElementName=DurationBeforeQuitSlider}"/>
|
||||
</DockPanel>
|
||||
<CheckBox Content="Automatically check for updates when File Converter starts" IsChecked="{Binding ApplicationSettings.CheckUpgradeAtStartup, ElementName=window, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
|
||||
<Button x:Name="CloseButton" Grid.Row="3" Content="Close" HorizontalAlignment="Right" Width="100" Margin="0,4,105,0" Click="CloseButton_Click" />
|
||||
|
95
Application/FileConverter/Windows/UpgradeWindow.xaml
Normal file
95
Application/FileConverter/Windows/UpgradeWindow.xaml
Normal file
@ -0,0 +1,95 @@
|
||||
<Window x:Name="window" x:Class="FileConverter.Windows.UpgradeWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FileConverter.Windows"
|
||||
xmlns:fileConverter="clr-namespace:FileConverter"
|
||||
xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters"
|
||||
xmlns:xaml="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml"
|
||||
mc:Ignorable="d"
|
||||
Title="File Converter Updates"
|
||||
WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
MinHeight="300" MinWidth="450"
|
||||
Height="450" Width="450" WindowStyle="ToolWindow">
|
||||
<Window.Resources>
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
|
||||
<Style TargetType="FlowDocument" x:Key="DocumentStyle">
|
||||
<Setter Property="FontFamily" Value="Segoe UI" />
|
||||
<Setter Property="TextAlignment" Value="Left" />
|
||||
<Setter Property="Foreground" Value="#786C71" />
|
||||
<Setter Property="Background" Value="White" />
|
||||
<Setter Property="LineHeight" Value="9"/>
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="PageHeader" TargetType="Paragraph">
|
||||
<Setter Property="FontSize" Value="24" />
|
||||
<Setter Property="Foreground" Value="#1E6BB8" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SubHeader"
|
||||
TargetType="Paragraph">
|
||||
<Setter Property="FontSize"
|
||||
Value="20" />
|
||||
<Setter Property="Foreground"
|
||||
Value="#DF3900" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SubHeaderSecondary"
|
||||
TargetType="Paragraph">
|
||||
<Setter Property="FontSize"
|
||||
Value="20" />
|
||||
<Setter Property="Foreground"
|
||||
Value="#DF3900" />
|
||||
</Style>
|
||||
|
||||
<xaml:Markdown x:Key="Markdown"
|
||||
DocumentStyle="{StaticResource DocumentStyle}"
|
||||
Heading1Style="{StaticResource PageHeader}"
|
||||
Heading2Style="{StaticResource SubHeader}"
|
||||
Heading3Style="{StaticResource SubHeaderSecondary}"/>
|
||||
|
||||
<xaml:TextToFlowDocumentConverter x:Key="TextToFlowDocumentConverter" Markdown="{StaticResource Markdown}"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<!--<RowDefinition Height="{Binding Height, ElementName=ApplicationSettingsPanel, Mode=OneWay}"/>-->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Margin="5"
|
||||
Text="An update for File Converter is available. It is strongly recommended that you install it as soon as possible!" TextWrapping="Wrap"/>
|
||||
|
||||
<!--<Label Grid.Row="1" Margin="5"
|
||||
Content="{Binding VersionDescription.LatestVersion, Converter={StaticResource ApplicationVersionToApplicationName}, ElementName=window}" FontWeight="Bold" FontSize="14.667"/>-->
|
||||
|
||||
<FlowDocumentScrollViewer Grid.Row="2" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Document="{Binding ReleaseNote, Converter={StaticResource TextToFlowDocumentConverter}, ElementName=window}"/>
|
||||
|
||||
<Button Background="WhiteSmoke" Grid.Row="3" Padding="10,5,10,5" Margin="5" HorizontalContentAlignment="Left" Click="OnInstallButtonClick" >
|
||||
<Button.Content>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="64"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="/FileConverter;component/Resources/DownloadIcon.png" Stretch="Fill"/>
|
||||
<Grid Grid.Column="1" Margin="10,0,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Content="Install when I exit File Converter" FontSize="14.667"/>
|
||||
<TextBlock Grid.Row="1" Text="The update will be downloaded in background, and installed once you exit File Converter." TextWrapping="Wrap" FontSize="10.667"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
80
Application/FileConverter/Windows/UpgradeWindow.xaml.cs
Normal file
80
Application/FileConverter/Windows/UpgradeWindow.xaml.cs
Normal file
@ -0,0 +1,80 @@
|
||||
// <copyright file="UpgradeWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.Windows
|
||||
{
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.Upgrade;
|
||||
|
||||
public partial class UpgradeWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
private UpgradeVersionDescription upgradeVersionDescription;
|
||||
private string releaseNoteContent;
|
||||
|
||||
public UpgradeWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public UpgradeVersionDescription VersionDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.upgradeVersionDescription;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.upgradeVersionDescription = value;
|
||||
|
||||
Task<string> task = Helpers.GetChangeLogAsync(this.upgradeVersionDescription, this.OnChangeLogRetrieved);
|
||||
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string ReleaseNote
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.releaseNoteContent))
|
||||
{
|
||||
return "###Downloading change log ...";
|
||||
}
|
||||
|
||||
return this.releaseNoteContent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.releaseNoteContent = value;
|
||||
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void OnChangeLogRetrieved(UpgradeVersionDescription versionDescription)
|
||||
{
|
||||
this.ReleaseNote = versionDescription.ChangeLog;
|
||||
}
|
||||
|
||||
private void OnInstallButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.upgradeVersionDescription.NeedToUpgrade = true;
|
||||
Helpers.DownloadInstallerAsync(this.upgradeVersionDescription);
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileConverter", "Application\FileConverter\FileConverter.csproj", "{D27A76D2-43E4-43CC-9DA3-334B0B46F4E5}"
|
||||
EndProject
|
||||
|
BIN
Middleware/Markdown.Xaml.dll
Normal file
BIN
Middleware/Markdown.Xaml.dll
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
# File Converter
|
||||
|
||||
## Description
|
||||
**File Converter** is a very simple tool which allows you to convert one or several file(s) from one format to another using the context menu in windows explorer.
|
||||
**File Converter** is a very simple tool which allows you to convert and compress one or several file(s) from one format to another using the context menu in windows explorer.
|
||||
|
||||
You can download it here: [www.file-converter.org](http://file-converter.org).
|
||||
|
||||
@ -30,6 +30,9 @@ Thanks to Dave Kerr for his work on SharpShell. [CodePlex link](https://sharpshe
|
||||
**Ripper** and **yeti.mmedia** for CD Audio extraction.
|
||||
Thanks to Idael Cardoso for his work on CD Audio ripper. [Code project link](http://www.codeproject.com/Articles/5458/C-Sharp-Ripper)
|
||||
|
||||
**Markdown.XAML** for markdown rendering in the wpf application.
|
||||
Thanks to Bevan Arps for his work on Markdown.XAML. [GitHub link](https://github.com/theunrepentantgeek/Markdown.XAML)
|
||||
|
||||
## License
|
||||
|
||||
File Converter is licensed under the GPL version 3 License.
|
||||
|
4
version.xml
Normal file
4
version.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<Version>
|
||||
<Latest Major="0" Minor="4" Patch="1"/>
|
||||
<URL>http://github.com/Tichau/FileConverter/releases/download/v0.4/FileConverter-0.4-x64-setup.msi</URL>
|
||||
</Version>
|
Loading…
x
Reference in New Issue
Block a user