Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save ImageResizer settings in JSON format #1258

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9617c55
Combined settings files
arjunbalgovind Feb 6, 2020
da2caea
Added JSON settings functionality in PowerToys format with thread safety
arjunbalgovind Feb 7, 2020
9dd139b
Reverting changes to csproj file
arjunbalgovind Feb 7, 2020
bae33fa
Removed settings.settings and designer file and added target sdk tool…
arjunbalgovind Feb 7, 2020
6aafc98
Added NewtonSoft Json package
arjunbalgovind Feb 7, 2020
64d8b80
Added 3 tests
arjunbalgovind Feb 8, 2020
9e0a823
Added propertychanged test
arjunbalgovind Feb 8, 2020
46a0c96
Removed unused libraries
arjunbalgovind Feb 10, 2020
96ef3d9
Removed additional allocation statements in test
arjunbalgovind Feb 10, 2020
0556fd9
Added comments on test
arjunbalgovind Feb 10, 2020
8d1426a
Added one-time setup code
arjunbalgovind Feb 10, 2020
3a7dc47
Merge remote-tracking branch 'upstream/dev/imageResizer' into user/ar…
arjunbalgovind Feb 10, 2020
5254253
Added Newtonsoft.Json.dll to MSI and MSIX installer
arjunbalgovind Feb 10, 2020
9cfadd2
Fixed copyright header
arjunbalgovind Feb 10, 2020
46f70e7
Fixed folder location in MSIX
arjunbalgovind Feb 10, 2020
012e458
Merge remote-tracking branch 'upstream/dev/imageResizer' into user/ar…
arjunbalgovind Feb 11, 2020
151999b
Renamed jsonMutex to _jsonMutex
arjunbalgovind Feb 12, 2020
064e6fb
Fixed line endings
arjunbalgovind Feb 12, 2020
cc46bfc
Created private setup functions and added Arrange, Act, Assert comments
arjunbalgovind Feb 12, 2020
7acc0f2
Created private setup functions and added Arrange, Act, Assert comments
arjunbalgovind Feb 12, 2020
5f0c08b
Suppressed copyright warning on AppFixture and enabled treat warnings…
arjunbalgovind Feb 12, 2020
35ed946
Added comments on Reload/AppFixture and added constructor andispose
arjunbalgovind Feb 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions installer/MSIX/PackagingLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
<File DestinationPath="modules\PowerRenameExt.dll" SourcePath="..\..\x64\Release\modules\PowerRenameExt.dll"/>
<File DestinationPath="modules\shortcut_guide.dll" SourcePath="..\..\x64\Release\modules\shortcut_guide.dll"/>
<File DestinationPath="modules\PowerRenameUWPUI.exe" SourcePath="..\..\x64\Release\PowerRenameUWPUI.exe"/>
<File DestinationPath="modules\ImageResizer.exe" SourcePath="..\..\x64\Release\ImageResizer.exe"/>
<File DestinationPath="modules\ImageResizer.exe" SourcePath="..\..\x64\Release\modules\ImageResizer.exe"/>
<File DestinationPath="modules\ImageResizerExt.dll" SourcePath="..\..\x64\Release\modules\ImageResizerExt.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.dll" SourcePath="..\..\x64\Release\GalaSoft.MvvmLight.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.Platform.dll" SourcePath="..\..\x64\Release\GalaSoft.MvvmLight.Platform.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.Extras.dll" SourcePath="..\..\x64\Release\GalaSoft.MvvmLight.Extras.dll"/>
<File DestinationPath="modules\System.Windows.Interactivity.dll" SourcePath="..\..\x64\Release\System.Windows.Interactivity.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.dll" SourcePath="..\..\x64\Release\modules\GalaSoft.MvvmLight.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.Platform.dll" SourcePath="..\..\x64\Release\modules\GalaSoft.MvvmLight.Platform.dll"/>
<File DestinationPath="modules\GalaSoft.MvvmLight.Extras.dll" SourcePath="..\..\x64\Release\modules\GalaSoft.MvvmLight.Extras.dll"/>
<File DestinationPath="modules\System.Windows.Interactivity.dll" SourcePath="..\..\x64\Release\modules\System.Windows.Interactivity.dll"/>
<File DestinationPath="modules\Newtonsoft.Json.dll" SourcePath="..\..\x64\Release\modules\Newtonsoft.Json.dll"/>

<File DestinationPath="svgs\*" SourcePath="..\..\x64\Release\svgs\*"/>
<File DestinationPath="settings-html\**" SourcePath="..\..\x64\Release\settings-html\**"/>
Expand Down
1 change: 1 addition & 0 deletions installer/PowerToysSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<!-- NB: Needed since it's only referenced in XAML. -->
<netfx:NativeImage Id="Interactivity" Platform="all" Priority="0"/>
</File>
<File Source="$(var.BinX64Dir)\modules\Newtonsoft.Json.dll" />
<File Source="$(var.BinX64Dir)\modules\ImageResizerExt.dll" KeyPath="yes" />
<RegistryKey Root="HKCR" Key="CLSID\{51B4D7E5-7568-4234-B4BB-47FB3C016A69}\InprocServer32">
<RegistryValue Value="[ModulesInstallFolder]ImageResizerExt.dll" Type="string" />
Expand Down
1 change: 1 addition & 0 deletions src/modules/imageresizer/tests/ImageResizerUITest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Models\ResizeSizeTests.cs" />
<Compile Include="Models\ResizeBatchTests.cs" />
<Compile Include="Models\ResizeOperationTests.cs" />
<Compile Include="Properties\AppFixture.cs" />
<Compile Include="Properties\SettingsTests.cs" />
<Compile Include="Test\AssertEx.cs" />
<Compile Include="Test\BitmapSourceExtensions.cs" />
Expand Down
23 changes: 23 additions & 0 deletions src/modules/imageresizer/tests/Properties/AppFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace ImageResizer.Properties
{
public class AppFixture : IDisposable
{
public AppFixture()
{
imageResizerApp = new App();
}

public void Dispose()
{
imageResizerApp = null;
}

private App imageResizerApp;
}
}
94 changes: 91 additions & 3 deletions src/modules/imageresizer/tests/Properties/SettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// 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.Specialized;
using System.ComponentModel;
Expand All @@ -12,7 +12,7 @@

namespace ImageResizer.Properties
{
public class SettingsTests
public class SettingsTests : IClassFixture<AppFixture>
{
[Fact]
public void AllSizes_propagates_Sizes_collection_events()
Expand Down Expand Up @@ -186,5 +186,93 @@ public void IDataErrorInfo_Item_returns_empty_when_not_JpegQualityLevel()

Assert.Empty(result);
}
}

[Fact]
public void Reload_createsFile_when_FileNotFound()
{
var settings = new Settings();
Settings.SettingsPath = ".\\test_settings.json";
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}

Assert.False(System.IO.File.Exists(Settings.SettingsPath));
settings.Reload();
Assert.True(System.IO.File.Exists(Settings.SettingsPath));
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}
}

[Fact]
public void Save_creates_file()
{
var settings = new Settings();
Settings.SettingsPath = ".\\test_settings.json";
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}

Assert.False(System.IO.File.Exists(Settings.SettingsPath));
settings.Save();
Assert.True(System.IO.File.Exists(Settings.SettingsPath));
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}
}

[Fact]
public void Save_json_is_readable_by_Reload()
{
var settings = new Settings();
Settings.SettingsPath = ".\\test_settings.json";
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}

settings.Save();
settings.Reload();

if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}
}

[Fact]
public void Reload_raises_PropertyChanged_()
{
var settings = new Settings();
Settings.SettingsPath = ".\\test_settings.json";
if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}

settings.Save();
var action = new System.Action(settings.Reload);
Assert.PropertyChanged(settings, "ShrinkOnly", action);
Assert.PropertyChanged(settings, "Replace", action);
Assert.PropertyChanged(settings, "IgnoreOrientation", action);
Assert.PropertyChanged(settings, "JpegQualityLevel", action);
Assert.PropertyChanged(settings, "PngInterlaceOption", action);
Assert.PropertyChanged(settings, "TiffCompressOption", action);
Assert.PropertyChanged(settings, "FileName", action);
Assert.PropertyChanged(settings, "Sizes", action);
Assert.PropertyChanged(settings, "KeepDateModified", action);
Assert.PropertyChanged(settings, "FallbackEncoder", action);
Assert.PropertyChanged(settings, "CustomSize", action);
Assert.PropertyChanged(settings, "SelectedSizeIndex", action);

if (System.IO.File.Exists(Settings.SettingsPath))
{
System.IO.File.Delete(Settings.SettingsPath);
}
}
}
}
16 changes: 6 additions & 10 deletions src/modules/imageresizer/ui/ImageResizerUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@
<Compile Include="Models\ResizeOperation.cs" />
<Compile Include="Models\ResizeSize.cs" />
<Compile Include="Models\ResizeUnit.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Utilities\MathHelpers.cs" />
<Compile Include="ViewModels\AdvancedViewModel.cs" />
<Compile Include="ViewModels\InputViewModel.cs" />
Expand Down Expand Up @@ -164,11 +159,6 @@
<EmbeddedResource Include="Properties\Resources.sk.resx" />
<EmbeddedResource Include="Properties\Resources.tr.resx" />
<EmbeddedResource Include="Properties\Resources.zh-Hans.resx" />
<None Include="Properties\Settings.settings">
<Generator>PublicSettingsSingleFileGenerator</Generator>
<SubType>Designer</SubType>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\codeAnalysis\StyleCop.json" />
Expand All @@ -186,11 +176,17 @@
<PackageReference Include="MvvmLightLibs">
<Version>5.4.1.1</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<TargetFrameworkSDKToolsDirectory Condition=" '$(Platform)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(Platform)\</TargetFrameworkSDKToolsDirectory>
</PropertyGroup>
</Project>
16 changes: 15 additions & 1 deletion src/modules/imageresizer/ui/Models/CustomSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
// 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 Newtonsoft.Json;

namespace ImageResizer.Models
{
public class CustomSize : ResizeSize
{
[JsonIgnore]
public override string Name
{
get => Resources.Input_Custom;
set { /* no-op */ }
}

public CustomSize(ResizeFit fit, double width, double height, ResizeUnit unit)
{
Fit = fit;
Width = width;
Height = height;
Unit = unit;
}

public CustomSize()
{
}
}
}
22 changes: 21 additions & 1 deletion src/modules/imageresizer/ui/Models/ResizeSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using System.Diagnostics;
using GalaSoft.MvvmLight;
using ImageResizer.Properties;

using Newtonsoft.Json;

namespace ImageResizer.Models
{
[JsonObject(MemberSerialization.OptIn)]
public class ResizeSize : ObservableObject
{
private static readonly IDictionary<string, string> _tokens;
Expand All @@ -29,12 +31,27 @@ static ResizeSize()
["$phone$"] = Resources.Phone,
};

public ResizeSize(string name, ResizeFit fit, double width, double height, ResizeUnit unit)
{
Name = name;
Fit = fit;
Width = width;
Height = height;
Unit = unit;
}

public ResizeSize()
{
}

[JsonProperty(PropertyName = "name")]
public virtual string Name
{
get => _name;
set => Set(nameof(Name), ref _name, ReplaceTokens(value));
}

[JsonProperty(PropertyName = "fit")]
public ResizeFit Fit
{
get => _fit;
Expand All @@ -47,12 +64,14 @@ public ResizeFit Fit
}
}

[JsonProperty(PropertyName = "width")]
public double Width
{
get => _width;
set => Set(nameof(Width), ref _width, value);
}

[JsonProperty(PropertyName = "height")]
public double Height
{
get => _height;
Expand All @@ -65,6 +84,7 @@ public bool ShowHeight
public bool HasAuto
=> Width == 0 || Height == 0;

[JsonProperty(PropertyName = "unit")]
public ResizeUnit Unit
{
get => _unit;
Expand Down
Loading