diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index eecada6..ee2a3b1 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -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 conversionJobs = new List(); - 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 filePaths = new List(); @@ -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 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); + } } } diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 3a6d136..027162a 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -46,6 +46,9 @@ + + ..\..\Middleware\Markdown.Xaml.dll + @@ -102,6 +105,8 @@ True + + @@ -128,6 +133,9 @@ SettingsWindow.xaml + + UpgradeWindow.xaml + Designer @@ -156,6 +164,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -199,6 +211,9 @@ + + + - + + + + diff --git a/Application/FileConverter/Windows/UpgradeWindow.xaml.cs b/Application/FileConverter/Windows/UpgradeWindow.xaml.cs new file mode 100644 index 0000000..abf7eec --- /dev/null +++ b/Application/FileConverter/Windows/UpgradeWindow.xaml.cs @@ -0,0 +1,80 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +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 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(); + } + } +} diff --git a/FileConverter.sln b/FileConverter.sln index af7cc2b..1eb9171 100644 --- a/FileConverter.sln +++ b/FileConverter.sln @@ -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 diff --git a/Middleware/Markdown.Xaml.dll b/Middleware/Markdown.Xaml.dll new file mode 100644 index 0000000..118156b Binary files /dev/null and b/Middleware/Markdown.Xaml.dll differ diff --git a/README.md b/README.md index 9993e2f..3851e1f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/version.xml b/version.xml new file mode 100644 index 0000000..5d12232 --- /dev/null +++ b/version.xml @@ -0,0 +1,4 @@ + + + http://github.com/Tichau/FileConverter/releases/download/v0.4/FileConverter-0.4-x64-setup.msi + \ No newline at end of file