Skip to content

Commit

Permalink
Updated to latest version with message that shows if fileoptimizer ca…
Browse files Browse the repository at this point in the history
…n't be found
  • Loading branch information
devedse committed Jan 23, 2022
1 parent 56b16a7 commit 09be928
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
Expand All @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
75 changes: 75 additions & 0 deletions DeveImageOptimizerWPF/Converters/SwitchBindingExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace DeveImageOptimizerWPF.Converters
{
public class SwitchBindingExtension : Binding
{
public SwitchBindingExtension()
{
Initialize();
}

public SwitchBindingExtension(string path)
: base(path)
{
Initialize();
}

public SwitchBindingExtension(string path, object valueIfTrue, object valueIfFalse)
: base(path)
{
Initialize();
this.ValueIfTrue = valueIfTrue;
this.ValueIfFalse = valueIfFalse;
}

private void Initialize()
{
this.ValueIfTrue = Binding.DoNothing;
this.ValueIfFalse = Binding.DoNothing;
this.Converter = new SwitchConverter(this);
}

[ConstructorArgument("valueIfTrue")]
public object ValueIfTrue { get; set; }

[ConstructorArgument("valueIfFalse")]
public object ValueIfFalse { get; set; }

private class SwitchConverter : IValueConverter
{
public SwitchConverter(SwitchBindingExtension switchExtension)
{
_switch = switchExtension;
}

private SwitchBindingExtension _switch;

#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
bool b = System.Convert.ToBoolean(value);
return b ? _switch.ValueIfTrue : _switch.ValueIfFalse;
}
catch
{
return DependencyProperty.UnsetValue;
}
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}

#endregion
}

}
}
2 changes: 1 addition & 1 deletion DeveImageOptimizerWPF/DeveImageOptimizerWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="DeveCoolLib" Version="1.0.509" />
<PackageReference Include="DeveImageOptimizer" Version="1.0.586" />
<PackageReference Include="DeveImageOptimizer" Version="1.0.589" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
Expand Down
2 changes: 1 addition & 1 deletion DeveImageOptimizerWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<TextBox Grid.Column="0" Text="{Binding WindowState.ProcessingDirectory, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<Button Grid.Column="1" Content="Browse" Command="{Binding BrowseCommand}"></Button>
</Grid>
<Button Grid.Row="2" Content="Go" Command="{Binding GoCommand}"/>
<Button Grid.Row="2" Content="{l:SwitchBinding IsOptimizing, In Progress..., Go}" Command="{Binding GoCommand}" IsEnabled="{Binding Path=IsOptimizing, Converter={StaticResource InverseBooleanConverter}}"/>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<StackPanel.Resources>
<Style TargetType="{x:Type RadioButton}">
Expand Down
34 changes: 30 additions & 4 deletions DeveImageOptimizerWPF/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DeveImageOptimizer.Exceptions;
using DeveImageOptimizer.FileProcessing;
using DeveImageOptimizer.State;
using DeveImageOptimizer.State.StoringProcessedDirectories;
Expand All @@ -8,7 +9,9 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using Ookii.Dialogs.Wpf;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;

Expand All @@ -32,6 +35,7 @@ public class MainViewModel : ObservableRecipient
public FileProgressState FilesProcessingState { get; set; }

public bool PreviewEnabled { get; set; }
public bool IsOptimizing { get; set; }

private readonly FileProcessedStateRememberer _fileRememberer;
private readonly DirProcessedStateRememberer _dirRememberer;
Expand Down Expand Up @@ -85,13 +89,35 @@ private void ProcessingStateData_PropertyChanged(object? sender, System.Componen
public ICommand GoCommand { get; private set; }
private async Task GoCommandImp()
{
var state = StaticState.UserSettingsManager.State;
IsOptimizing = true;
try
{
var state = StaticState.UserSettingsManager.State;

var config = state.ToDeveImageOptimizerConfiguration();

var config = state.ToDeveImageOptimizerConfiguration();
var fileProcessor = new DeveImageOptimizerProcessor(config, FilesProcessingState, _fileRememberer, _dirRememberer);

var fileProcessor = new DeveImageOptimizerProcessor(config, FilesProcessingState, _fileRememberer, _dirRememberer);
await fileProcessor.ProcessDirectory(WindowState.ProcessingDirectory);
}
catch (FileOptimizerNotFoundException ex)
{
ShowFileOptimizerNotFoundError(ex.Message);
}
catch (AggregateException ex) when (ex.InnerExceptions?.OfType<FileOptimizerNotFoundException>()?.Any() == true)
{
var message = ex.InnerExceptions?.OfType<FileOptimizerNotFoundException>().FirstOrDefault()?.Message;
ShowFileOptimizerNotFoundError(message);
}
finally
{
IsOptimizing = false;
}
}

await fileProcessor.ProcessDirectory(WindowState.ProcessingDirectory);
private static void ShowFileOptimizerNotFoundError(string? message)
{
System.Windows.MessageBox.Show(message, "Could not find FileOptimizer.exe", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}

public ICommand BrowseCommand { get; private set; }
Expand Down

0 comments on commit 09be928

Please sign in to comment.