getting stuff to work

headers and trailing commas

adding braces

updated encoder
This commit is contained in:
Clint Rutkas
2020-01-02 16:58:06 -08:00
parent 3d204e7da9
commit 5310866120
39 changed files with 206 additions and 132 deletions

View File

@@ -1,6 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Copyright (c) Brice Lambson
// The .NET Foundation licenses this file to you under the MIT license. // The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
// This file is used by Code Analysis to maintain SuppressMessage // This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project. // attributes that are applied to this project.

View File

@@ -4,13 +4,13 @@
namespace System.Windows.Media.Imaging namespace System.Windows.Media.Imaging
{ {
static class BitmapEncoderExtensions internal static class BitmapEncoderExtensions
{ {
public static bool CanEncode(this BitmapEncoder encoder) public static bool CanEncode(this BitmapEncoder encoder)
{ {
try try
{ {
var = encoder.CodecInfo; var test = encoder.CodecInfo;
} }
catch (NotSupportedException) catch (NotSupportedException)
{ {

View File

@@ -4,12 +4,14 @@
namespace System.Collections.Generic namespace System.Collections.Generic
{ {
static class ICollectionExtensions internal static class ICollectionExtensions
{ {
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items) public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items)
{ {
foreach (var item in items) foreach (var item in items)
{
collection.Add(item); collection.Add(item);
}
} }
} }
} }

View File

@@ -4,7 +4,7 @@
namespace System namespace System
{ {
static class TimeSpanExtensions internal static class TimeSpanExtensions
{ {
public static TimeSpan Multiply(this TimeSpan timeSpan, double scalar) public static TimeSpan Multiply(this TimeSpan timeSpan, double scalar)
=> new TimeSpan((long)(timeSpan.Ticks * scalar)); => new TimeSpan((long)(timeSpan.Ticks * scalar));

View File

@@ -169,6 +169,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" /> <AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" />
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
@@ -181,7 +184,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MvvmLightLibs"> <PackageReference Include="MvvmLightLibs">
<Version>5.4.1</Version> <Version>5.4.1.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="StyleCop.Analyzers"> <PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version> <Version>1.1.118</Version>

View File

@@ -15,6 +15,7 @@ namespace ImageResizer.Models
public class ResizeBatch public class ResizeBatch
{ {
public string DestinationDirectory { get; set; } public string DestinationDirectory { get; set; }
public ICollection<string> Files { get; } = new List<string>(); public ICollection<string> Files { get; } = new List<string>();
public static ResizeBatch FromCommandLine(TextReader standardInput, string[] args) public static ResizeBatch FromCommandLine(TextReader standardInput, string[] args)
@@ -24,7 +25,9 @@ namespace ImageResizer.Models
// NB: We read these from stdin since there are limits on the number of args you can have // NB: We read these from stdin since there are limits on the number of args you can have
string file; string file;
while ((file = standardInput.ReadLine()) != null) while ((file = standardInput.ReadLine()) != null)
{
batch.Files.Add(file); batch.Files.Add(file);
}
for (var i = 0; i < args.Length; i++) for (var i = 0; i < args.Length; i++)
{ {
@@ -55,7 +58,7 @@ namespace ImageResizer.Models
new ParallelOptions new ParallelOptions
{ {
CancellationToken = cancellationToken, CancellationToken = cancellationToken,
MaxDegreeOfParallelism = Environment.ProcessorCount MaxDegreeOfParallelism = Environment.ProcessorCount,
}, },
(file, state, i) => (file, state, i) =>
{ {

View File

@@ -7,6 +7,7 @@ namespace ImageResizer.Models
public class ResizeError public class ResizeError
{ {
public string File { get; set; } public string File { get; set; }
public string Error { get; set; } public string Error { get; set; }
} }
} }

View File

@@ -8,6 +8,6 @@ namespace ImageResizer.Models
{ {
Fill, Fill,
Fit, Fit,
Stretch Stretch,
} }
} }

View File

@@ -14,11 +14,11 @@ using Microsoft.VisualBasic.FileIO;
namespace ImageResizer.Models namespace ImageResizer.Models
{ {
class ResizeOperation internal class ResizeOperation
{ {
readonly string _file; private readonly string _file;
readonly string _destinationDirectory; private readonly string _destinationDirectory;
readonly Settings _settings; private readonly Settings _settings;
public ResizeOperation(string file, string destinationDirectory, Settings settings) public ResizeOperation(string file, string destinationDirectory, Settings settings)
{ {
@@ -39,7 +39,9 @@ namespace ImageResizer.Models
var encoder = BitmapEncoder.Create(decoder.CodecInfo.ContainerFormat); var encoder = BitmapEncoder.Create(decoder.CodecInfo.ContainerFormat);
if (!encoder.CanEncode()) if (!encoder.CanEncode())
{
encoder = BitmapEncoder.Create(_settings.FallbackEncoder); encoder = BitmapEncoder.Create(_settings.FallbackEncoder);
}
ConfigureEncoder(encoder); ConfigureEncoder(encoder);
@@ -55,7 +57,9 @@ namespace ImageResizer.Models
} }
if (decoder.Palette != null) if (decoder.Palette != null)
{
encoder.Palette = decoder.Palette; encoder.Palette = decoder.Palette;
}
foreach (var originalFrame in decoder.Frames) foreach (var originalFrame in decoder.Frames)
{ {
@@ -71,11 +75,15 @@ namespace ImageResizer.Models
path = GetDestinationPath(encoder); path = GetDestinationPath(encoder);
Directory.CreateDirectory(Path.GetDirectoryName(path)); Directory.CreateDirectory(Path.GetDirectoryName(path));
using (var outputStream = File.Open(path, FileMode.CreateNew, FileAccess.Write)) using (var outputStream = File.Open(path, FileMode.CreateNew, FileAccess.Write))
{
encoder.Save(outputStream); encoder.Save(outputStream);
}
} }
if (_settings.KeepDateModified) if (_settings.KeepDateModified)
{
File.SetLastWriteTimeUtc(path, File.GetLastWriteTimeUtc(_file)); File.SetLastWriteTimeUtc(path, File.GetLastWriteTimeUtc(_file));
}
if (_settings.Replace) if (_settings.Replace)
{ {
@@ -85,7 +93,7 @@ namespace ImageResizer.Models
} }
} }
void ConfigureEncoder(BitmapEncoder encoder) private void ConfigureEncoder(BitmapEncoder encoder)
{ {
switch (encoder) switch (encoder)
{ {
@@ -103,7 +111,7 @@ namespace ImageResizer.Models
} }
} }
BitmapSource Transform(BitmapSource source) private BitmapSource Transform(BitmapSource source)
{ {
var originalWidth = source.PixelWidth; var originalWidth = source.PixelWidth;
var originalHeight = source.PixelHeight; var originalHeight = source.PixelHeight;
@@ -137,7 +145,9 @@ namespace ImageResizer.Models
if (_settings.ShrinkOnly if (_settings.ShrinkOnly
&& _settings.SelectedSize.Unit != ResizeUnit.Percent && _settings.SelectedSize.Unit != ResizeUnit.Percent
&& (scaleX >= 1 || scaleY >= 1)) && (scaleX >= 1 || scaleY >= 1))
{
return source; return source;
}
var scaledBitmap = new TransformedBitmap(source, new ScaleTransform(scaleX, scaleY)); var scaledBitmap = new TransformedBitmap(source, new ScaleTransform(scaleX, scaleY));
if (_settings.SelectedSize.Fit == ResizeFit.Fill if (_settings.SelectedSize.Fit == ResizeFit.Fill
@@ -153,7 +163,7 @@ namespace ImageResizer.Models
return scaledBitmap; return scaledBitmap;
} }
string GetDestinationPath(BitmapEncoder encoder) private string GetDestinationPath(BitmapEncoder encoder)
{ {
var directory = _destinationDirectory ?? Path.GetDirectoryName(_file); var directory = _destinationDirectory ?? Path.GetDirectoryName(_file);
var originalFileName = Path.GetFileNameWithoutExtension(_file); var originalFileName = Path.GetFileNameWithoutExtension(_file);
@@ -176,12 +186,14 @@ namespace ImageResizer.Models
var path = Path.Combine(directory, fileName + extension); var path = Path.Combine(directory, fileName + extension);
var uniquifier = 1; var uniquifier = 1;
while (File.Exists(path)) while (File.Exists(path))
{
path = Path.Combine(directory, fileName + " (" + uniquifier++ + ")" + extension); path = Path.Combine(directory, fileName + " (" + uniquifier++ + ")" + extension);
}
return path; return path;
} }
string GetBackupPath() private string GetBackupPath()
{ {
var directory = Path.GetDirectoryName(_file); var directory = Path.GetDirectoryName(_file);
var fileName = Path.GetFileNameWithoutExtension(_file); var fileName = Path.GetFileNameWithoutExtension(_file);
@@ -190,7 +202,9 @@ namespace ImageResizer.Models
var path = Path.Combine(directory, fileName + ".bak" + extension); var path = Path.Combine(directory, fileName + ".bak" + extension);
var uniquifier = 1; var uniquifier = 1;
while (File.Exists(path)) while (File.Exists(path))
{
path = Path.Combine(directory, fileName + " (" + uniquifier++ + ")" + ".bak" + extension); path = Path.Combine(directory, fileName + " (" + uniquifier++ + ")" + ".bak" + extension);
}
return path; return path;
} }

View File

@@ -11,14 +11,14 @@ namespace ImageResizer.Models
{ {
public class ResizeSize : ObservableObject public class ResizeSize : ObservableObject
{ {
static readonly IDictionary<string, string> _tokens; private static readonly IDictionary<string, string> _tokens;
string _name; private string _name;
ResizeFit _fit = ResizeFit.Fit; private ResizeFit _fit = ResizeFit.Fit;
double _width; private double _width;
double _height; private double _height;
bool _showHeight = true; private bool _showHeight = true;
ResizeUnit _unit = ResizeUnit.Pixel; private ResizeUnit _unit = ResizeUnit.Pixel;
static ResizeSize() static ResizeSize()
=> _tokens = new Dictionary<string, string> => _tokens = new Dictionary<string, string>
@@ -26,7 +26,7 @@ namespace ImageResizer.Models
["$small$"] = Resources.Small, ["$small$"] = Resources.Small,
["$medium$"] = Resources.Medium, ["$medium$"] = Resources.Medium,
["$large$"] = Resources.Large, ["$large$"] = Resources.Large,
["$phone$"] = Resources.Phone ["$phone$"] = Resources.Phone,
}; };
public virtual string Name public virtual string Name
@@ -41,7 +41,9 @@ namespace ImageResizer.Models
set set
{ {
if (Set(nameof(Fit), ref _fit, value)) if (Set(nameof(Fit), ref _fit, value))
{
UpdateShowHeight(); UpdateShowHeight();
}
} }
} }
@@ -69,7 +71,9 @@ namespace ImageResizer.Models
set set
{ {
if (Set(nameof(Unit), ref _unit, value)) if (Set(nameof(Unit), ref _unit, value))
{
UpdateShowHeight(); UpdateShowHeight();
}
} }
} }
@@ -85,23 +89,25 @@ namespace ImageResizer.Models
originalHeight, originalHeight,
dpi); dpi);
static string ReplaceTokens(string text) private static string ReplaceTokens(string text)
=> (text != null && _tokens.TryGetValue(text, out var result)) => (text != null && _tokens.TryGetValue(text, out var result))
? result ? result
: text; : text;
void UpdateShowHeight() private void UpdateShowHeight()
=> Set( => Set(
nameof(ShowHeight), nameof(ShowHeight),
ref _showHeight, ref _showHeight,
Fit == ResizeFit.Stretch || Unit != ResizeUnit.Percent); Fit == ResizeFit.Stretch || Unit != ResizeUnit.Percent);
double ConvertToPixels(double value, ResizeUnit unit, int originalValue, double dpi) private double ConvertToPixels(double value, ResizeUnit unit, int originalValue, double dpi)
{ {
if (value == 0) if (value == 0)
{ {
if (Fit == ResizeFit.Fit) if (Fit == ResizeFit.Fit)
{
return double.PositiveInfinity; return double.PositiveInfinity;
}
Debug.Assert(Fit == ResizeFit.Fill || Fit == ResizeFit.Stretch, "Unexpected ResizeFit value: " + Fit); Debug.Assert(Fit == ResizeFit.Fill || Fit == ResizeFit.Stretch, "Unexpected ResizeFit value: " + Fit);

View File

@@ -9,6 +9,6 @@ namespace ImageResizer.Models
Centimeter, Centimeter,
Inch, Inch,
Percent, Percent,
Pixel Pixel,
} }
} }

View File

@@ -13,7 +13,7 @@ namespace ImageResizer.Properties
{ {
partial class Settings : IDataErrorInfo partial class Settings : IDataErrorInfo
{ {
string _fileNameFormat; private string _fileNameFormat;
public Settings() public Settings()
=> AllSizes = new AllSizesCollection(this); => AllSizes = new AllSizesCollection(this);
@@ -41,7 +41,9 @@ namespace ImageResizer.Properties
{ {
var index = Sizes.IndexOf(value); var index = Sizes.IndexOf(value);
if (index == -1) if (index == -1)
{
index = Sizes.Count; index = Sizes.Count;
}
SelectedSizeIndex = index; SelectedSizeIndex = index;
} }
@@ -53,12 +55,15 @@ namespace ImageResizer.Properties
public override object this[string propertyName] public override object this[string propertyName]
{ {
get { return base[propertyName]; } get { return base[propertyName]; }
set set
{ {
base[propertyName] = value; base[propertyName] = value;
if (propertyName == nameof(FileName)) if (propertyName == nameof(FileName))
{
_fileNameFormat = null; _fileNameFormat = null;
}
} }
} }
@@ -67,19 +72,23 @@ namespace ImageResizer.Properties
get get
{ {
if (columnName != nameof(JpegQualityLevel)) if (columnName != nameof(JpegQualityLevel))
{
return string.Empty; return string.Empty;
}
if (JpegQualityLevel < 1 || JpegQualityLevel > 100) if (JpegQualityLevel < 1 || JpegQualityLevel > 100)
{
return string.Format(Resources.ValueMustBeBetween, 1, 100); return string.Format(Resources.ValueMustBeBetween, 1, 100);
}
return string.Empty; return string.Empty;
} }
} }
class AllSizesCollection : IEnumerable<ResizeSize>, INotifyCollectionChanged, INotifyPropertyChanged private class AllSizesCollection : IEnumerable<ResizeSize>, INotifyCollectionChanged, INotifyPropertyChanged
{ {
ObservableCollection<ResizeSize> _sizes; private ObservableCollection<ResizeSize> _sizes;
CustomSize _customSize; private CustomSize _customSize;
public AllSizesCollection(Settings settings) public AllSizesCollection(Settings settings)
{ {
@@ -121,6 +130,7 @@ namespace ImageResizer.Properties
} }
public event NotifyCollectionChangedEventHandler CollectionChanged; public event NotifyCollectionChangedEventHandler CollectionChanged;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public int Count public int Count
@@ -134,23 +144,23 @@ namespace ImageResizer.Properties
public IEnumerator<ResizeSize> GetEnumerator() public IEnumerator<ResizeSize> GetEnumerator()
=> new AllSizesEnumerator(this); => new AllSizesEnumerator(this);
void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
=> OnCollectionChanged(e); => OnCollectionChanged(e);
void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
=> PropertyChanged?.Invoke(this, e); => PropertyChanged?.Invoke(this, e);
void OnCollectionChanged(NotifyCollectionChangedEventArgs e) private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
=> CollectionChanged?.Invoke(this, e); => CollectionChanged?.Invoke(this, e);
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator(); => GetEnumerator();
class AllSizesEnumerator : IEnumerator<ResizeSize> private class AllSizesEnumerator : IEnumerator<ResizeSize>
{ {
readonly AllSizesCollection _list; private readonly AllSizesCollection _list;
int _index = -1; private int _index = -1;
public AllSizesEnumerator(AllSizesCollection list) public AllSizesEnumerator(AllSizesCollection list)
=> _list = list; => _list = list;

View File

@@ -6,7 +6,7 @@ using System;
namespace ImageResizer.Utilities namespace ImageResizer.Utilities
{ {
static class MathHelpers internal static class MathHelpers
{ {
public static int Clamp(int value, int min, int max) public static int Clamp(int value, int min, int max)
=> Math.Min(Math.Max(value, min), max); => Math.Min(Math.Max(value, min), max);

View File

@@ -16,7 +16,7 @@ namespace ImageResizer.ViewModels
{ {
public class AdvancedViewModel : ViewModelBase public class AdvancedViewModel : ViewModelBase
{ {
static readonly IDictionary<Guid, string> _encoderMap; private static readonly IDictionary<Guid, string> _encoderMap;
static AdvancedViewModel() static AdvancedViewModel()
{ {
@@ -58,6 +58,7 @@ namespace ImageResizer.ViewModels
=> _encoderMap.Keys; => _encoderMap.Keys;
public ICommand RemoveSizeCommand { get; } public ICommand RemoveSizeCommand { get; }
public ICommand AddSizeCommand { get; } public ICommand AddSizeCommand { get; }
public void RemoveSize(ResizeSize size) public void RemoveSize(ResizeSize size)

View File

@@ -13,9 +13,9 @@ namespace ImageResizer.ViewModels
{ {
public class InputViewModel : ViewModelBase public class InputViewModel : ViewModelBase
{ {
readonly ResizeBatch _batch; private readonly ResizeBatch _batch;
readonly MainViewModel _mainViewModel; private readonly MainViewModel _mainViewModel;
readonly IMainView _mainView; private readonly IMainView _mainView;
public InputViewModel( public InputViewModel(
Settings settings, Settings settings,
@@ -38,7 +38,9 @@ namespace ImageResizer.ViewModels
public Settings Settings { get; } public Settings Settings { get; }
public ICommand ResizeCommand { get; } public ICommand ResizeCommand { get; }
public ICommand CancelCommand { get; } public ICommand CancelCommand { get; }
public ICommand ShowAdvancedCommand { get; } public ICommand ShowAdvancedCommand { get; }
public void Resize() public void Resize()

View File

@@ -14,11 +14,11 @@ namespace ImageResizer.ViewModels
{ {
public class MainViewModel : ViewModelBase public class MainViewModel : ViewModelBase
{ {
readonly Settings _settings; private readonly Settings _settings;
readonly ResizeBatch _batch; private readonly ResizeBatch _batch;
object _currentPage; private object _currentPage;
double _progress; private double _progress;
public MainViewModel(ResizeBatch batch, Settings settings) public MainViewModel(ResizeBatch batch, Settings settings)
{ {
@@ -44,7 +44,9 @@ namespace ImageResizer.ViewModels
public void Load(IMainView view) public void Load(IMainView view)
{ {
if (_batch.Files.Count == 0) if (_batch.Files.Count == 0)
{
_batch.Files.AddRange(view.OpenPictureFiles()); _batch.Files.AddRange(view.OpenPictureFiles());
}
if (_settings.UpgradeRequired) if (_settings.UpgradeRequired)
{ {

View File

@@ -17,14 +17,14 @@ namespace ImageResizer.ViewModels
{ {
public class ProgressViewModel : ViewModelBase public class ProgressViewModel : ViewModelBase
{ {
readonly MainViewModel _mainViewModel; private readonly MainViewModel _mainViewModel;
readonly ResizeBatch _batch; private readonly ResizeBatch _batch;
readonly IMainView _mainView; private readonly IMainView _mainView;
readonly Stopwatch _stopwatch = new Stopwatch(); private readonly Stopwatch _stopwatch = new Stopwatch();
readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
double _progress; private double _progress;
TimeSpan _timeRemaining; private TimeSpan _timeRemaining;
public ProgressViewModel( public ProgressViewModel(
ResizeBatch batch, ResizeBatch batch,
@@ -52,6 +52,7 @@ namespace ImageResizer.ViewModels
} }
public ICommand StartCommand { get; } public ICommand StartCommand { get; }
public ICommand StopCommand { get; } public ICommand StopCommand { get; }
public void Start() public void Start()

View File

@@ -13,7 +13,7 @@ namespace ImageResizer.ViewModels
{ {
public class ResultsViewModel : ViewModelBase public class ResultsViewModel : ViewModelBase
{ {
readonly IMainView _mainView; private readonly IMainView _mainView;
public ResultsViewModel(IMainView mainView, IEnumerable<ResizeError> errors) public ResultsViewModel(IMainView mainView, IEnumerable<ResizeError> errors)
{ {
@@ -23,6 +23,7 @@ namespace ImageResizer.ViewModels
} }
public IEnumerable<ResizeError> Errors { get; } public IEnumerable<ResizeError> Errors { get; }
public ICommand CloseCommand { get; } public ICommand CloseCommand { get; }
public void Close() => _mainView.Close(); public void Close() => _mainView.Close();

View File

@@ -17,10 +17,10 @@ namespace ImageResizer.Views
InitializeComponent(); InitializeComponent();
} }
void HandleAcceptClick(object sender, RoutedEventArgs e) private void HandleAcceptClick(object sender, RoutedEventArgs e)
=> DialogResult = true; => DialogResult = true;
void HandleRequestNavigate(object sender, RequestNavigateEventArgs e) private void HandleRequestNavigate(object sender, RequestNavigateEventArgs e)
{ {
Process.Start(e.Uri.ToString()); Process.Start(e.Uri.ToString());
e.Handled = true; e.Handled = true;

View File

@@ -10,7 +10,7 @@ using ImageResizer.Properties;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
[ValueConversion(typeof(double), typeof(string))] [ValueConversion(typeof(double), typeof(string))]
class AutoDoubleConverter : IValueConverter internal class AutoDoubleConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {

View File

@@ -7,7 +7,7 @@ using System.Windows.Controls;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
class AutoDoubleValidationRule : ValidationRule internal class AutoDoubleValidationRule : ValidationRule
{ {
public override ValidationResult Validate(object value, CultureInfo cultureInfo) public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{ {

View File

@@ -10,7 +10,7 @@ using System.Windows.Data;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
[ValueConversion(typeof(Enum), typeof(string))] [ValueConversion(typeof(Enum), typeof(string))]
class BoolValueConverter : IValueConverter internal class BoolValueConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> (bool)value ? Visibility.Visible : Visibility.Collapsed; => (bool)value ? Visibility.Visible : Visibility.Collapsed;

View File

@@ -38,7 +38,9 @@ namespace ImageResizer.Views
var targetValue = Resources.ResourceManager.GetString(builder.ToString()); var targetValue = Resources.ResourceManager.GetString(builder.ToString());
if (toLower) if (toLower)
{
targetValue = targetValue.ToLower(); targetValue = targetValue.ToLower();
}
return targetValue; return targetValue;
} }

View File

@@ -10,7 +10,9 @@ namespace ImageResizer.Views
public interface IMainView public interface IMainView
{ {
void Close(); void Close();
void ShowAdvanced(AdvancedViewModel viewModel); void ShowAdvanced(AdvancedViewModel viewModel);
IEnumerable<string> OpenPictureFiles(); IEnumerable<string> OpenPictureFiles();
} }
} }

View File

@@ -28,11 +28,13 @@ namespace ImageResizer.Views
"|*.bmp;*.dib;*.exif;*.gif;*.jfif;*.jpe;*.jpeg;*.jpg;*.jxr;*.png;*.rle;*.tif;*.tiff;*.wdp|" + "|*.bmp;*.dib;*.exif;*.gif;*.jfif;*.jpe;*.jpeg;*.jpg;*.jxr;*.png;*.rle;*.tif;*.tiff;*.wdp|" +
AppResources.AllFilesFilter + "|*.*", AppResources.AllFilesFilter + "|*.*",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
Multiselect = true Multiselect = true,
}; };
if (openFileDialog.ShowDialog() != true) if (openFileDialog.ShowDialog() != true)
{
return Enumerable.Empty<string>(); return Enumerable.Empty<string>();
}
return openFileDialog.FileNames; return openFileDialog.FileNames;
} }

View File

@@ -11,7 +11,7 @@ using ImageResizer.Properties;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
[ValueConversion(typeof(ResizeUnit), typeof(string))] [ValueConversion(typeof(ResizeUnit), typeof(string))]
class ResizeUnitConverter : IValueConverter internal class ResizeUnitConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {

View File

@@ -11,7 +11,7 @@ using ImageResizer.Properties;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
[ValueConversion(typeof(TiffCompressOption), typeof(string))] [ValueConversion(typeof(TiffCompressOption), typeof(string))]
class TiffCompressOptionConverter : IValueConverter internal class TiffCompressOptionConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> Resources.ResourceManager.GetString( => Resources.ResourceManager.GetString(

View File

@@ -11,7 +11,7 @@ using ImageResizer.Properties;
namespace ImageResizer.Views namespace ImageResizer.Views
{ {
[ValueConversion(typeof(TimeSpan), typeof(string))] [ValueConversion(typeof(TimeSpan), typeof(string))]
class TimeRemainingConverter : IValueConverter internal class TimeRemainingConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
@@ -23,10 +23,12 @@ namespace ImageResizer.Views
{ {
builder.Append(timeRemaining.Hours == 1 ? "Hour" : "Hours"); builder.Append(timeRemaining.Hours == 1 ? "Hour" : "Hours");
} }
if (timeRemaining.Hours != 0 || timeRemaining.Minutes > 0) if (timeRemaining.Hours != 0 || timeRemaining.Minutes > 0)
{ {
builder.Append(timeRemaining.Minutes == 1 ? "Minute" : "Minutes"); builder.Append(timeRemaining.Minutes == 1 ? "Minute" : "Minutes");
} }
if (timeRemaining.Hours == 0) if (timeRemaining.Hours == 0)
{ {
builder.Append(timeRemaining.Seconds == 1 ? "Second" : "Seconds"); builder.Append(timeRemaining.Seconds == 1 ? "Second" : "Seconds");

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup> </startup>
</configuration> </configuration>

View File

@@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ImageResizer</RootNamespace> <RootNamespace>ImageResizer</RootNamespace>
<AssemblyName>ImageResizer.Test</AssemblyName> <AssemblyName>ImageResizer.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>..\..\codeAnalysis\Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@@ -29,6 +32,8 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>..\..\codeAnalysis\Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
@@ -75,8 +80,22 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" />
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>2.9.8</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq"> <PackageReference Include="Moq">
<Version>4.2.1510.2205</Version> <Version>4.13.1</Version>
</PackageReference>
<PackageReference Include="MvvmLightLibs">
<Version>5.4.1.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="StyleCop.Analyzers"> <PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version> <Version>1.1.118</Version>
@@ -84,10 +103,10 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="System.ValueTuple"> <PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version> <Version>4.5.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="xunit.extensions"> <PackageReference Include="xunit">
<Version>1.9.2</Version> <Version>2.4.1</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,6 +1,6 @@
// <copyright file="CustomSizeTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using ImageResizer.Properties; using ImageResizer.Properties;
using Xunit; using Xunit;

View File

@@ -1,6 +1,6 @@
// <copyright file="ResizeBatchTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
@@ -17,7 +17,7 @@ namespace ImageResizer.Models
{ {
public class ResizeBatchTests public class ResizeBatchTests
{ {
static readonly string EOL = Environment.NewLine; private static readonly string EOL = Environment.NewLine;
[Fact] [Fact]
public void FromCommandLine_works() public void FromCommandLine_works()
@@ -28,7 +28,7 @@ namespace ImageResizer.Models
var args = new[] var args = new[]
{ {
"/d", "OutputDir", "/d", "OutputDir",
"Image3.jpg" "Image3.jpg",
}; };
var result = ResizeBatch.FromCommandLine( var result = ResizeBatch.FromCommandLine(
@@ -97,7 +97,7 @@ namespace ImageResizer.Models
Assert.True(calls.Any(c => c.i == 2 && c.count == 2)); Assert.True(calls.Any(c => c.i == 2 && c.count == 2));
} }
static ResizeBatch CreateBatch(Action<string> executeAction) private static ResizeBatch CreateBatch(Action<string> executeAction)
{ {
var mock = new Mock<ResizeBatch> { CallBase = true }; var mock = new Mock<ResizeBatch> { CallBase = true };
mock.Protected().Setup("Execute", ItExpr.IsAny<string>()).Callback(executeAction); mock.Protected().Setup("Execute", ItExpr.IsAny<string>()).Callback(executeAction);

View File

@@ -1,6 +1,6 @@
// <copyright file="ResizeOperationTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -15,7 +15,7 @@ namespace ImageResizer.Models
{ {
public class ResizeOperationTests : IDisposable public class ResizeOperationTests : IDisposable
{ {
readonly TestDirectory _directory = new TestDirectory(); private readonly TestDirectory _directory = new TestDirectory();
[Fact] [Fact]
public void Execute_copies_frame_metadata() public void Execute_copies_frame_metadata()
@@ -430,7 +430,7 @@ namespace ImageResizer.Models
public void Dispose() public void Dispose()
=> _directory.Dispose(); => _directory.Dispose();
Settings Settings(Action<Settings> action = null) private Settings Settings(Action<Settings> action = null)
{ {
var settings = new Settings var settings = new Settings
{ {
@@ -440,10 +440,10 @@ namespace ImageResizer.Models
{ {
Name = "Test", Name = "Test",
Width = 96, Width = 96,
Height = 96 Height = 96,
} },
}, },
SelectedSizeIndex = 0 SelectedSizeIndex = 0,
}; };
action?.Invoke(settings); action?.Invoke(settings);

View File

@@ -1,6 +1,6 @@
// <copyright file="ResizeSizeTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@@ -35,7 +35,7 @@ namespace ImageResizer.Models
("$small$", Resources.Small), ("$small$", Resources.Small),
("$medium$", Resources.Medium), ("$medium$", Resources.Medium),
("$large$", Resources.Large), ("$large$", Resources.Large),
("$phone$", Resources.Phone) ("$phone$", Resources.Phone),
}; };
foreach (var (name, expected) in args) foreach (var (name, expected) in args)
{ {
@@ -95,7 +95,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 0, Width = 0,
Height = 42 Height = 42,
}; };
Assert.True(size.HasAuto); Assert.True(size.HasAuto);
@@ -107,7 +107,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 42, Width = 42,
Height = 0 Height = 0,
}; };
Assert.True(size.HasAuto); Assert.True(size.HasAuto);
@@ -119,7 +119,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 42, Width = 42,
Height = 42 Height = 42,
}; };
Assert.False(size.HasAuto); Assert.False(size.HasAuto);
@@ -145,7 +145,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 1, Width = 1,
Unit = ResizeUnit.Inch Unit = ResizeUnit.Inch,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);
@@ -159,7 +159,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Height = 1, Height = 1,
Unit = ResizeUnit.Inch Unit = ResizeUnit.Inch,
}; };
var result = size.GetPixelHeight(100, 96); var result = size.GetPixelHeight(100, 96);
@@ -191,7 +191,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 0, Width = 0,
Fit = ResizeFit.Fit Fit = ResizeFit.Fit,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);
@@ -205,7 +205,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 0, Width = 0,
Fit = ResizeFit.Fill Fit = ResizeFit.Fill,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);
@@ -219,7 +219,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 0.5, Width = 0.5,
Unit = ResizeUnit.Inch Unit = ResizeUnit.Inch,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);
@@ -233,7 +233,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 1, Width = 1,
Unit = ResizeUnit.Centimeter Unit = ResizeUnit.Centimeter,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);
@@ -247,7 +247,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 50, Width = 50,
Unit = ResizeUnit.Percent Unit = ResizeUnit.Percent,
}; };
var result = size.GetPixelWidth(200, 96); var result = size.GetPixelWidth(200, 96);
@@ -261,7 +261,7 @@ namespace ImageResizer.Models
var size = new ResizeSize var size = new ResizeSize
{ {
Width = 50, Width = 50,
Unit = ResizeUnit.Pixel Unit = ResizeUnit.Pixel,
}; };
var result = size.GetPixelWidth(100, 96); var result = size.GetPixelWidth(100, 96);

View File

@@ -1,6 +1,6 @@
// <copyright file="SettingsTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
@@ -20,7 +20,7 @@ namespace ImageResizer.Properties
var settings = new Settings var settings = new Settings
{ {
Sizes = new ObservableCollection<ResizeSize>(), Sizes = new ObservableCollection<ResizeSize>(),
CustomSize = new CustomSize() CustomSize = new CustomSize(),
}; };
var ncc = (INotifyCollectionChanged)settings.AllSizes; var ncc = (INotifyCollectionChanged)settings.AllSizes;
@@ -38,7 +38,7 @@ namespace ImageResizer.Properties
var settings = new Settings var settings = new Settings
{ {
Sizes = new ObservableCollection<ResizeSize>(), Sizes = new ObservableCollection<ResizeSize>(),
CustomSize = new CustomSize() CustomSize = new CustomSize(),
}; };
Assert.PropertyChanged( Assert.PropertyChanged(
@@ -53,7 +53,7 @@ namespace ImageResizer.Properties
var settings = new Settings var settings = new Settings
{ {
Sizes = new ObservableCollection<ResizeSize> { new ResizeSize() }, Sizes = new ObservableCollection<ResizeSize> { new ResizeSize() },
CustomSize = new CustomSize() CustomSize = new CustomSize(),
}; };
Assert.Contains(settings.Sizes[0], settings.AllSizes); Assert.Contains(settings.Sizes[0], settings.AllSizes);
@@ -65,7 +65,7 @@ namespace ImageResizer.Properties
var settings = new Settings var settings = new Settings
{ {
Sizes = new ObservableCollection<ResizeSize>(), Sizes = new ObservableCollection<ResizeSize>(),
CustomSize = new CustomSize() CustomSize = new CustomSize(),
}; };
Assert.Contains(settings.CustomSize, settings.AllSizes); Assert.Contains(settings.CustomSize, settings.AllSizes);
@@ -78,7 +78,7 @@ namespace ImageResizer.Properties
var settings = new Settings var settings = new Settings
{ {
Sizes = new ObservableCollection<ResizeSize>(), Sizes = new ObservableCollection<ResizeSize>(),
CustomSize = originalCustomSize CustomSize = originalCustomSize,
}; };
var ncc = (INotifyCollectionChanged)settings.AllSizes; var ncc = (INotifyCollectionChanged)settings.AllSizes;
@@ -116,7 +116,7 @@ namespace ImageResizer.Properties
{ {
SelectedSizeIndex = index, SelectedSizeIndex = index,
Sizes = new ObservableCollection<ResizeSize>(), Sizes = new ObservableCollection<ResizeSize>(),
CustomSize = new CustomSize() CustomSize = new CustomSize(),
}; };
var result = settings.SelectedSize; var result = settings.SelectedSize;
@@ -132,8 +132,8 @@ namespace ImageResizer.Properties
SelectedSizeIndex = 0, SelectedSizeIndex = 0,
Sizes = new ObservableCollection<ResizeSize> Sizes = new ObservableCollection<ResizeSize>
{ {
new ResizeSize() new ResizeSize(),
} },
}; };
var result = settings.SelectedSize; var result = settings.SelectedSize;

View File

@@ -1,6 +1,6 @@
// <copyright file="AssertEx.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -12,7 +12,7 @@ using Xunit;
namespace ImageResizer.Test namespace ImageResizer.Test
{ {
static class AssertEx internal static class AssertEx
{ {
public static void All<T>(IEnumerable<T> collection, Action<T> action) public static void All<T>(IEnumerable<T> collection, Action<T> action)
{ {
@@ -80,6 +80,7 @@ namespace ImageResizer.Test
} }
public object Sender { get; } public object Sender { get; }
public TArgs Arguments { get; } public TArgs Arguments { get; }
} }
} }

View File

@@ -1,6 +1,6 @@
// <copyright file="BitmapSourceExtensions.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
@@ -8,7 +8,7 @@ using System.Windows.Media.Imaging;
namespace ImageResizer.Test namespace ImageResizer.Test
{ {
static class BitmapSourceExtensions internal static class BitmapSourceExtensions
{ {
public static Color GetFirstPixel(this BitmapSource source) public static Color GetFirstPixel(this BitmapSource source)
{ {

View File

@@ -1,6 +1,6 @@
// <copyright file="TestDirectory.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,7 +15,7 @@ namespace ImageResizer
{ {
public class TestDirectory : IDisposable public class TestDirectory : IDisposable
{ {
readonly string _path; private readonly string _path;
public TestDirectory() public TestDirectory()
{ {
@@ -25,7 +25,7 @@ namespace ImageResizer
Directory.CreateDirectory(_path); Directory.CreateDirectory(_path);
} }
IEnumerable<string> Files private IEnumerable<string> Files
=> Directory.EnumerateFiles(_path); => Directory.EnumerateFiles(_path);
public IEnumerable<string> FileNames public IEnumerable<string> FileNames

View File

@@ -1,6 +1,6 @@
// <copyright file="TimeRemainingConverterTests.cs" company="PlaceholderCompany"> // Copyright (c) Brice Lambson
// Copyright (c) PlaceholderCompany. All rights reserved. // The Brice Lambson licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System; using System;
using System.Globalization; using System.Globalization;