mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-21 01:52:54 +01:00
Add cancel conversion button (for ffmpeg conversion only)
This commit is contained in:
1 parent
c0d7c404b2
commit
e447410a1e
7 files changed
+140
-6
No files matched your search
@@ -214,6 +214,11 @@ namespace FileConverter
|
||||
for (int index = 1; index < args.Length; index++)
|
||||
{
|
||||
string argument = args[index];
|
||||
if (string.IsNullOrEmpty(argument))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.StartsWith("--"))
|
||||
{
|
||||
// This is an optional parameter.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// <copyright file="CancelConversionJobCommand.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ConversionJobs
|
||||
{
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
public class CancelConversionJobCommand : ICommand
|
||||
{
|
||||
private readonly ConversionJob conversionJob;
|
||||
|
||||
public CancelConversionJobCommand(ConversionJob conversionJob)
|
||||
{
|
||||
this.conversionJob = conversionJob;
|
||||
this.conversionJob.PropertyChanged += this.ConversionJob_PropertyChanged;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (this.conversionJob == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.conversionJob.IsCancelable && this.conversionJob.State == ConversionJob.ConversionState.InProgress;
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
this.conversionJob?.Cancel();
|
||||
}
|
||||
|
||||
private void ConversionJob_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName != "State")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ namespace FileConverter.ConversionJobs
|
||||
private string errorMessage = string.Empty;
|
||||
private string initialInputPath = string.Empty;
|
||||
private string userState = string.Empty;
|
||||
private CancelConversionJobCommand cancelCommand;
|
||||
|
||||
public ConversionJob()
|
||||
{
|
||||
@@ -126,6 +127,31 @@ namespace FileConverter.ConversionJobs
|
||||
protected set;
|
||||
}
|
||||
|
||||
public CancelConversionJobCommand CancelCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.cancelCommand == null)
|
||||
{
|
||||
this.cancelCommand = new CancelConversionJobCommand(this);
|
||||
}
|
||||
|
||||
return this.cancelCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCancelable
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
protected bool CancelIsRequested
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected virtual InputPostConversionAction InputPostConversionAction
|
||||
{
|
||||
get
|
||||
@@ -280,6 +306,17 @@ namespace FileConverter.ConversionJobs
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Cancel()
|
||||
{
|
||||
if (!this.IsCancelable || this.State != ConversionState.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.CancelIsRequested = true;
|
||||
this.ConversionFailed("Canceled.");
|
||||
}
|
||||
|
||||
protected virtual void Convert()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,12 +25,14 @@ namespace FileConverter.ConversionJobs
|
||||
|
||||
public ConversionJob_FFMPEG() : base()
|
||||
{
|
||||
this.IsCancelable = true;
|
||||
}
|
||||
|
||||
public ConversionJob_FFMPEG(ConversionPreset conversionPreset) : base(conversionPreset)
|
||||
{
|
||||
this.IsCancelable = true;
|
||||
}
|
||||
|
||||
|
||||
protected virtual string FfmpegPath
|
||||
{
|
||||
get
|
||||
@@ -363,6 +365,11 @@ namespace FileConverter.ConversionJobs
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
if (this.CancelIsRequested && !exeProcess.HasExited)
|
||||
{
|
||||
exeProcess.Kill();
|
||||
}
|
||||
|
||||
string result = reader.ReadLine();
|
||||
|
||||
this.ParseFFMPEGOutput(result);
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
<Compile Include="Controls\EncodingQualitySliderControl.xaml.cs">
|
||||
<DependentUpon>EncodingQualitySliderControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ConversionJobs\CancelConversionJobCommand.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionFlags.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_ExtractCDA.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJobFactory.cs" />
|
||||
@@ -104,6 +105,7 @@
|
||||
<Compile Include="Diagnostics\DiagnosticsData.cs" />
|
||||
<Compile Include="Controls\EncodingMode.cs" />
|
||||
<Compile Include="ConversionPreset\IConversionSettings.cs" />
|
||||
<Compile Include="IfoFile.cs" />
|
||||
<Compile Include="InputPostConversionAction.cs" />
|
||||
<Compile Include="IXmlSerializable.cs" />
|
||||
<Compile Include="PathHelpers.cs" />
|
||||
@@ -127,6 +129,7 @@
|
||||
<Compile Include="ValueConverters\Generic\EqualsConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\CollectionContainsElementToBool.cs" />
|
||||
<Compile Include="ValueConverters\Generic\FormatStringConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\ValueToString.cs" />
|
||||
<Compile Include="ValueConverters\Generic\StringToValueType.cs" />
|
||||
<Compile Include="ValueConverters\InputTypesToBool.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// <copyright file="StringToEnum.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class ValueToString : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value?.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,20 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FileConverter"
|
||||
xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters"
|
||||
xmlns:conversionJobs="clr-namespace:FileConverter.ConversionJobs" mc:Ignorable="d" x:Class="FileConverter.MainWindow"
|
||||
x:Name="FileConverterMainWindow" Height="500" Width="950" MinHeight="250" MinWidth="450" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
|
||||
xmlns:conversionJobs="clr-namespace:FileConverter.ConversionJobs"
|
||||
xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic"
|
||||
mc:Ignorable="d" x:Class="FileConverter.MainWindow"
|
||||
x:Name="FileConverterMainWindow" Height="500" Width="950" MinHeight="250" MinWidth="500" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
|
||||
<Window.Resources>
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToColor" />
|
||||
|
||||
<generic:ValueConverterGroup x:Key="EnumEqualsToVisibility">
|
||||
<generic:ValueToString/>
|
||||
<generic:EqualsConverter/>
|
||||
<!--<generic:BoolInverterConverter/>-->
|
||||
<generic:BoolToVisibility/>
|
||||
</generic:ValueConverterGroup>
|
||||
</Window.Resources>
|
||||
<Window.Title>
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
@@ -39,8 +48,13 @@
|
||||
<ItemsControl x:Name="ConverterJobsList">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DockPanel Background="{Binding State, ConverterParameter=Background, Converter={StaticResource ConversionStateToColor}}" Margin="0,4">
|
||||
<Grid Margin="10">
|
||||
<Grid Background="{Binding State, ConverterParameter=Background, Converter={StaticResource ConversionStateToColor}}" Margin="0,4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Margin="10" Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -64,7 +78,9 @@
|
||||
|
||||
<ProgressBar Grid.Row="1" Grid.Column="1" Height="18" Width="Auto" Minimum="0" Maximum="1" SmallChange="0.001" Value="{Binding Progress, Mode=OneWay}" Foreground="{Binding State, ConverterParameter=Foreground, Converter={StaticResource ConversionStateToColor}}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" MinWidth="100" LargeChange="0.1" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
<Button Content="Cancel" Margin="5" Grid.Column="1" Width="80" Background="WhiteSmoke" Foreground="#FF3E3E3E" Visibility="{Binding State, Converter={StaticResource EnumEqualsToVisibility}, ConverterParameter=|InProgress|Collapsed}" Command="{Binding CancelCommand}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.DataContext>
|
||||
|
||||
Reference in new issue
Block a user