mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 01:08:18 +08:00
Standardize .NET JSON on System.Text.Json (#12805)
* Implement System.Text.Json for Community.PowerToys.Run.Plugin.VSCodeWorkspaces (#11697) * Implement System.Text.Json for Community.PowerToys.Run.Plugin.VSCodeWorkspaces * Cleanup property names * Implement System.Text.Json for Microsoft.PowerToys.Settings.UI (#11702) * Implement System.Text.Json for Powerlauncher (#11699) * Implement System.Text.Json for Wox.Infrastructure * Implement System.Text.Json for Powerlauncher * Implement System.Text.Json for Microsoft.Plugin.Folder * Implement System.Text.Json for Wox.Plugin * Remove Newtonsoft.Json from launcherInstallComponent * Update properties with private setter Format JSON output * Serialize Get with private set property * Implement System.Text.Json for ImageResizerUI (#11847) * Implement System.Text.Json for ImageRezierUI * Change Newtonsoft.Json.dll to System.Text.Json in ImageResizer * Add writefile to spelling whitelist * Fix installer * Fix bad merge Co-authored-by: mykhailopylyp <17161067+mykhailopylyp@users.noreply.github.com>
This commit is contained in:
parent
44ef29ca39
commit
ea25bd91b0
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@ -2380,6 +2380,7 @@ wprintf
|
|||||||
wprp
|
wprp
|
||||||
wregex
|
wregex
|
||||||
WResize
|
WResize
|
||||||
|
writefile
|
||||||
wsf
|
wsf
|
||||||
wsh
|
wsh
|
||||||
wsl
|
wsl
|
||||||
|
@ -539,7 +539,6 @@
|
|||||||
<Component Id="Module_ImageResizer" Guid="96E63289-759C-4A73-A56B-EE7429932F72" Win64="yes">
|
<Component Id="Module_ImageResizer" Guid="96E63289-759C-4A73-A56B-EE7429932F72" Win64="yes">
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.exe" />
|
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.exe" />
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizerExt.dll" KeyPath="yes" />
|
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizerExt.dll" KeyPath="yes" />
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\Newtonsoft.Json.dll" />
|
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.dll" />
|
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.dll" />
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.deps.json" />
|
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.deps.json" />
|
||||||
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.runtimeconfig.json" />
|
<File Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\ImageResizer.runtimeconfig.json" />
|
||||||
@ -553,7 +552,8 @@
|
|||||||
<File Id="Module_ImageResizer_Microsoft_Xaml_Behaviors" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\Microsoft.Xaml.Behaviors.dll" />
|
<File Id="Module_ImageResizer_Microsoft_Xaml_Behaviors" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\Microsoft.Xaml.Behaviors.dll" />
|
||||||
<File Id="ImageResizer_interop" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\PowerToysInterop.dll" />
|
<File Id="ImageResizer_interop" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\PowerToysInterop.dll" />
|
||||||
<File Id="ImageResizer_System.IO.Abstractions.dll" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\System.IO.Abstractions.dll" />
|
<File Id="ImageResizer_System.IO.Abstractions.dll" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\System.IO.Abstractions.dll" />
|
||||||
|
<File Id="ImageResizer_System.Runtime.CompilerServices.Unsafe.dll" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\System.Runtime.CompilerServices.Unsafe.dll" />
|
||||||
|
<File Id="ImageResizer_System.Text.Encodings.Web.dll" Source="$(var.BinX64Dir)modules\$(var.ImageResizerProjectName)\System.Text.Encodings.Web.dll" />
|
||||||
<!-- VCRuntime -->
|
<!-- VCRuntime -->
|
||||||
<?foreach File in vcruntime140.dll;vcruntime140_1.dll;concrt140.dll;msvcp140.dll;msvcp140_1.dll;msvcp140_2.dll;msvcp140_codecvt_ids.dll;vccorlib140.dll?>
|
<?foreach File in vcruntime140.dll;vcruntime140_1.dll;concrt140.dll;msvcp140.dll;msvcp140_1.dll;msvcp140_2.dll;msvcp140_codecvt_ids.dll;vccorlib140.dll?>
|
||||||
<File Id="ImageResizer_$(var.File)" Source="$(var.RepoDir)installer\VCRuntime\$(var.File)" />
|
<File Id="ImageResizer_$(var.File)" Source="$(var.RepoDir)installer\VCRuntime\$(var.File)" />
|
||||||
@ -1078,7 +1078,7 @@
|
|||||||
|
|
||||||
<Component Id="launcherInstallComponent" Directory="LauncherInstallFolder" Guid="5E688DB4-C522-4268-BA54-ED1CDFFE9DB6">
|
<Component Id="launcherInstallComponent" Directory="LauncherInstallFolder" Guid="5E688DB4-C522-4268-BA54-ED1CDFFE9DB6">
|
||||||
<File Source="$(var.BinX64Dir)modules\Launcher\Microsoft.Launcher.dll" />
|
<File Source="$(var.BinX64Dir)modules\Launcher\Microsoft.Launcher.dll" />
|
||||||
<?foreach File in concrt140_app.dll;ICSharpCode.SharpZipLib.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;Newtonsoft.Json.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerLauncher.deps.json;PowerLauncher.dll;PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToysInterop.dll;ManagedTelemetry.dll;PowerLauncher.Telemetry.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;ManagedCommon.dll;System.IO.Abstractions.dll;Microsoft.PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;System.Runtime.CompilerServices.Unsafe.dll;System.Text.Encodings.Web.dll?>
|
<?foreach File in concrt140_app.dll;ICSharpCode.SharpZipLib.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerLauncher.deps.json;PowerLauncher.dll;PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToysInterop.dll;ManagedTelemetry.dll;PowerLauncher.Telemetry.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;ManagedCommon.dll;System.IO.Abstractions.dll;Microsoft.PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;System.Runtime.CompilerServices.Unsafe.dll;System.Text.Encodings.Web.dll?>
|
||||||
<File Id="File_$(var.File)" Source="$(var.BinX64Dir)modules\launcher\$(var.File)" />
|
<File Id="File_$(var.File)" Source="$(var.BinX64Dir)modules\launcher\$(var.File)" />
|
||||||
<?endforeach?>
|
<?endforeach?>
|
||||||
<File Source="$(var.BinX64Dir)Settings\Microsoft.PowerToys.Settings.UI.Lib.dll" />
|
<File Source="$(var.BinX64Dir)Settings\Microsoft.PowerToys.Settings.UI.Lib.dll" />
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Specialized;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
using ImageResizer.Models;
|
using ImageResizer.Models;
|
||||||
using ImageResizer.Test;
|
using ImageResizer.Test;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
@ -347,6 +348,34 @@ namespace ImageResizer.Properties
|
|||||||
Assert.IsTrue(selectedSizeIndexChanged);
|
Assert.IsTrue(selectedSizeIndexChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SystemTextJsonDeserializesCorrectly()
|
||||||
|
{
|
||||||
|
// Generated Settings file in 0.72
|
||||||
|
var defaultInput =
|
||||||
|
"{\r\n \"properties\": {\r\n \"imageresizer_selectedSizeIndex\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_shrinkOnly\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_replace\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_ignoreOrientation\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_jpegQualityLevel\": {\r\n \"value\": 91\r\n },\r\n \"imageresizer_pngInterlaceOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_tiffCompressOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_fileName\": {\r\n \"value\": \"%1 %1 (%2)\"\r\n },\r\n \"imageresizer_sizes\": {\r\n \"value\": [\r\n {\r\n \"Id\": 0,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Small-NotDefault\",\r\n \"fit\": 1,\r\n \"width\": 854,\r\n \"height\": 480,\r\n \"unit\": 3\r\n },\r\n {\r\n \"Id\": 3,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Phone\",\r\n \"fit\": 1,\r\n \"width\": 320,\r\n \"height\": 568,\r\n \"unit\": 3\r\n }\r\n ]\r\n },\r\n \"imageresizer_keepDateModified\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_fallbackEncoder\": {\r\n \"value\": \"19e4a5aa-5662-4fc5-a0c0-1758028e1057\"\r\n },\r\n \"imageresizer_customSize\": {\r\n \"value\": {\r\n \"Id\": 4,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"custom\",\r\n \"fit\": 1,\r\n \"width\": 1024,\r\n \"height\": 640,\r\n \"unit\": 3\r\n }\r\n }\r\n },\r\n \"name\": \"ImageResizer\",\r\n \"version\": \"1\"\r\n}";
|
||||||
|
|
||||||
|
// Execute readFile/writefile twice and see if serialized string is still correct
|
||||||
|
var resultWrapper = JsonSerializer.Deserialize<SettingsWrapper>(defaultInput);
|
||||||
|
var serializedInput = JsonSerializer.Serialize(resultWrapper, new JsonSerializerOptions() { WriteIndented = true });
|
||||||
|
var resultWrapper2 = JsonSerializer.Deserialize<SettingsWrapper>(serializedInput);
|
||||||
|
var serializedInput2 = JsonSerializer.Serialize(resultWrapper2, new JsonSerializerOptions() { WriteIndented = true });
|
||||||
|
|
||||||
|
Assert.AreEqual(serializedInput, serializedInput2);
|
||||||
|
Assert.AreEqual("ImageResizer", resultWrapper2.Name);
|
||||||
|
Assert.AreEqual("1", resultWrapper2.Version);
|
||||||
|
Assert.IsNotNull(resultWrapper2.Properties);
|
||||||
|
Assert.IsTrue(resultWrapper2.Properties.ShrinkOnly);
|
||||||
|
Assert.IsTrue(resultWrapper2.Properties.Replace);
|
||||||
|
Assert.AreEqual(91, resultWrapper2.Properties.JpegQualityLevel);
|
||||||
|
Assert.AreEqual(1, (int)resultWrapper2.Properties.PngInterlaceOption);
|
||||||
|
Assert.AreEqual(1, (int)resultWrapper2.Properties.TiffCompressOption);
|
||||||
|
Assert.AreEqual("%1 %1 (%2)", resultWrapper2.Properties.FileName);
|
||||||
|
Assert.AreEqual(2, resultWrapper2.Properties.Sizes.Count);
|
||||||
|
Assert.IsFalse(resultWrapper2.Properties.KeepDateModified);
|
||||||
|
Assert.AreEqual("Small-NotDefault", resultWrapper2.Properties.Sizes[0].Name);
|
||||||
|
}
|
||||||
|
|
||||||
[ClassCleanup]
|
[ClassCleanup]
|
||||||
public static void ClassCleanup()
|
public static void ClassCleanup()
|
||||||
{
|
{
|
||||||
|
@ -66,13 +66,13 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||||
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.IO.Abstractions">
|
<PackageReference Include="System.IO.Abstractions">
|
||||||
<Version>12.2.5</Version>
|
<Version>12.2.5</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="System.Text.Json" Version="5.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\common\interop\PowerToysInterop.vcxproj" />
|
<ProjectReference Include="..\..\..\common\interop\PowerToysInterop.vcxproj" />
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// The Brice Lambson 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. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
||||||
|
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using ImageResizer.Properties;
|
using ImageResizer.Properties;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace ImageResizer.Models
|
namespace ImageResizer.Models
|
||||||
{
|
{
|
||||||
@ -16,6 +16,7 @@ namespace ImageResizer.Models
|
|||||||
set { /* no-op */ }
|
set { /* no-op */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
public CustomSize(ResizeFit fit, double width, double height, ResizeUnit unit)
|
public CustomSize(ResizeFit fit, double width, double height, ResizeUnit unit)
|
||||||
{
|
{
|
||||||
Fit = fit;
|
Fit = fit;
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
// Copyright (c) Brice Lambson
|
// Copyright (c) Brice Lambson
|
||||||
// The Brice Lambson 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. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
// 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.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using ImageResizer.Helpers;
|
using ImageResizer.Helpers;
|
||||||
using ImageResizer.Properties;
|
using ImageResizer.Properties;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace ImageResizer.Models
|
namespace ImageResizer.Models
|
||||||
{
|
{
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
|
||||||
public class ResizeSize : Observable
|
public class ResizeSize : Observable
|
||||||
{
|
{
|
||||||
private static readonly IDictionary<string, string> _tokens = new Dictionary<string, string>
|
private static readonly IDictionary<string, string> _tokens = new Dictionary<string, string>
|
||||||
@ -41,14 +40,14 @@ namespace ImageResizer.Models
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "name")]
|
[JsonPropertyName("name")]
|
||||||
public virtual string Name
|
public virtual string Name
|
||||||
{
|
{
|
||||||
get => _name;
|
get => _name;
|
||||||
set => Set(ref _name, ReplaceTokens(value));
|
set => Set(ref _name, ReplaceTokens(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "fit")]
|
[JsonPropertyName("fit")]
|
||||||
public ResizeFit Fit
|
public ResizeFit Fit
|
||||||
{
|
{
|
||||||
get => _fit;
|
get => _fit;
|
||||||
@ -63,14 +62,14 @@ namespace ImageResizer.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "width")]
|
[JsonPropertyName("width")]
|
||||||
public double Width
|
public double Width
|
||||||
{
|
{
|
||||||
get => _width;
|
get => _width;
|
||||||
set => Set(ref _width, value);
|
set => Set(ref _width, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "height")]
|
[JsonPropertyName("height")]
|
||||||
public double Height
|
public double Height
|
||||||
{
|
{
|
||||||
get => _height;
|
get => _height;
|
||||||
@ -86,7 +85,7 @@ namespace ImageResizer.Models
|
|||||||
public bool HasAuto
|
public bool HasAuto
|
||||||
=> Width == 0 || Height == 0 || double.IsNaN(Width) || double.IsNaN(Height);
|
=> Width == 0 || Height == 0 || double.IsNaN(Width) || double.IsNaN(Height);
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "unit")]
|
[JsonPropertyName("unit")]
|
||||||
public ResizeUnit Unit
|
public ResizeUnit Unit
|
||||||
{
|
{
|
||||||
get => _unit;
|
get => _unit;
|
||||||
|
@ -10,16 +10,14 @@ using System.Collections.Specialized;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using ImageResizer.Models;
|
using ImageResizer.Models;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace ImageResizer.Properties
|
namespace ImageResizer.Properties
|
||||||
{
|
{
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
|
||||||
public sealed partial class Settings : IDataErrorInfo, INotifyPropertyChanged
|
public sealed partial class Settings : IDataErrorInfo, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private static readonly IFileSystem _fileSystem = new FileSystem();
|
private static readonly IFileSystem _fileSystem = new FileSystem();
|
||||||
@ -63,6 +61,7 @@ namespace ImageResizer.Properties
|
|||||||
AllSizes = new AllSizesCollection(this);
|
AllSizes = new AllSizesCollection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public IEnumerable<ResizeSize> AllSizes { get; set; }
|
public IEnumerable<ResizeSize> AllSizes { get; set; }
|
||||||
|
|
||||||
// Using OrdinalIgnoreCase since this is internal and used for comparison with symbols
|
// Using OrdinalIgnoreCase since this is internal and used for comparison with symbols
|
||||||
@ -78,6 +77,7 @@ namespace ImageResizer.Properties
|
|||||||
.Replace("%5", "{4}", StringComparison.OrdinalIgnoreCase)
|
.Replace("%5", "{4}", StringComparison.OrdinalIgnoreCase)
|
||||||
.Replace("%6", "{5}", StringComparison.OrdinalIgnoreCase));
|
.Replace("%6", "{5}", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public ResizeSize SelectedSize
|
public ResizeSize SelectedSize
|
||||||
{
|
{
|
||||||
get => SelectedSizeIndex >= 0 && SelectedSizeIndex < Sizes.Count
|
get => SelectedSizeIndex >= 0 && SelectedSizeIndex < Sizes.Count
|
||||||
@ -222,6 +222,7 @@ namespace ImageResizer.Properties
|
|||||||
|
|
||||||
private static Settings defaultInstance = new Settings();
|
private static Settings defaultInstance = new Settings();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public static Settings Default
|
public static Settings Default
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -231,7 +232,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_selectedSizeIndex")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_selectedSizeIndex")]
|
||||||
public int SelectedSizeIndex
|
public int SelectedSizeIndex
|
||||||
{
|
{
|
||||||
get => _selectedSizeIndex;
|
get => _selectedSizeIndex;
|
||||||
@ -242,7 +244,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_shrinkOnly")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_shrinkOnly")]
|
||||||
public bool ShrinkOnly
|
public bool ShrinkOnly
|
||||||
{
|
{
|
||||||
get => _shrinkOnly;
|
get => _shrinkOnly;
|
||||||
@ -253,7 +256,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_replace")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_replace")]
|
||||||
public bool Replace
|
public bool Replace
|
||||||
{
|
{
|
||||||
get => _replace;
|
get => _replace;
|
||||||
@ -264,7 +268,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_ignoreOrientation")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_ignoreOrientation")]
|
||||||
public bool IgnoreOrientation
|
public bool IgnoreOrientation
|
||||||
{
|
{
|
||||||
get => _ignoreOrientation;
|
get => _ignoreOrientation;
|
||||||
@ -275,7 +280,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_jpegQualityLevel")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_jpegQualityLevel")]
|
||||||
public int JpegQualityLevel
|
public int JpegQualityLevel
|
||||||
{
|
{
|
||||||
get => _jpegQualityLevel;
|
get => _jpegQualityLevel;
|
||||||
@ -286,7 +292,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_pngInterlaceOption")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_pngInterlaceOption")]
|
||||||
public PngInterlaceOption PngInterlaceOption
|
public PngInterlaceOption PngInterlaceOption
|
||||||
{
|
{
|
||||||
get => _pngInterlaceOption;
|
get => _pngInterlaceOption;
|
||||||
@ -297,7 +304,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_tiffCompressOption")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_tiffCompressOption")]
|
||||||
public TiffCompressOption TiffCompressOption
|
public TiffCompressOption TiffCompressOption
|
||||||
{
|
{
|
||||||
get => _tiffCompressOption;
|
get => _tiffCompressOption;
|
||||||
@ -308,7 +316,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_fileName")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_fileName")]
|
||||||
public string FileName
|
public string FileName
|
||||||
{
|
{
|
||||||
get => _fileName;
|
get => _fileName;
|
||||||
@ -324,10 +333,13 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_sizes")]
|
[JsonInclude]
|
||||||
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_sizes")]
|
||||||
public ObservableCollection<ResizeSize> Sizes { get; private set; }
|
public ObservableCollection<ResizeSize> Sizes { get; private set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_keepDateModified")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_keepDateModified")]
|
||||||
public bool KeepDateModified
|
public bool KeepDateModified
|
||||||
{
|
{
|
||||||
get => _keepDateModified;
|
get => _keepDateModified;
|
||||||
@ -338,8 +350,9 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_fallbackEncoder")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
public System.Guid FallbackEncoder
|
[JsonPropertyName("imageresizer_fallbackEncoder")]
|
||||||
|
public Guid FallbackEncoder
|
||||||
{
|
{
|
||||||
get => _fallbackEncoder;
|
get => _fallbackEncoder;
|
||||||
set
|
set
|
||||||
@ -349,7 +362,8 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "imageresizer_customSize")]
|
[JsonConverter(typeof(WrappedJsonValueConverter))]
|
||||||
|
[JsonPropertyName("imageresizer_customSize")]
|
||||||
public CustomSize CustomSize
|
public CustomSize CustomSize
|
||||||
{
|
{
|
||||||
get => _customSize;
|
get => _customSize;
|
||||||
@ -372,18 +386,7 @@ namespace ImageResizer.Properties
|
|||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
_jsonMutex.WaitOne();
|
_jsonMutex.WaitOne();
|
||||||
string jsonData = "{\"version\":\"1.0\",\"name\":\"ImageResizer\",\"properties\":";
|
string jsonData = JsonSerializer.Serialize(new SettingsWrapper() { Properties = this });
|
||||||
string tempJsonData = JsonConvert.SerializeObject(this);
|
|
||||||
JObject tempSettings = JObject.Parse(tempJsonData);
|
|
||||||
|
|
||||||
// Replace the <Value> of the property with { "value": <Value> } to be consistent with PowerToys
|
|
||||||
foreach (var property in tempSettings)
|
|
||||||
{
|
|
||||||
tempSettings[property.Key] = new JObject { { "value", property.Value } };
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonData += tempSettings.ToString(Formatting.None);
|
|
||||||
jsonData += "}";
|
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
IFileInfo file = _fileSystem.FileInfo.FromFileName(SettingsPath);
|
IFileInfo file = _fileSystem.FileInfo.FromFileName(SettingsPath);
|
||||||
@ -405,15 +408,7 @@ namespace ImageResizer.Properties
|
|||||||
}
|
}
|
||||||
|
|
||||||
string jsonData = _fileSystem.File.ReadAllText(SettingsPath);
|
string jsonData = _fileSystem.File.ReadAllText(SettingsPath);
|
||||||
JObject imageResizerSettings = JObject.Parse(jsonData);
|
Settings jsonSettings = JsonSerializer.Deserialize<SettingsWrapper>(jsonData)?.Properties;
|
||||||
|
|
||||||
// Replace the { "value": <Value> } with <Value> to match the Settings object format
|
|
||||||
foreach (var property in (JObject)imageResizerSettings["properties"])
|
|
||||||
{
|
|
||||||
imageResizerSettings["properties"][property.Key] = property.Value["value"];
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings jsonSettings = JsonConvert.DeserializeObject<Settings>(imageResizerSettings["properties"].ToString(), new JsonSerializerSettings() { ObjectCreationHandling = ObjectCreationHandling.Replace });
|
|
||||||
|
|
||||||
// Needs to be called on the App UI thread as the properties are bound to the UI.
|
// Needs to be called on the App UI thread as the properties are bound to the UI.
|
||||||
App.Current.Dispatcher.Invoke(() =>
|
App.Current.Dispatcher.Invoke(() =>
|
||||||
|
20
src/modules/imageresizer/ui/Properties/SettingsWrapper.cs
Normal file
20
src/modules/imageresizer/ui/Properties/SettingsWrapper.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace ImageResizer.Properties
|
||||||
|
{
|
||||||
|
public class SettingsWrapper
|
||||||
|
{
|
||||||
|
[JsonPropertyName("name")]
|
||||||
|
public string Name { get; set; } = "ImageResizer";
|
||||||
|
|
||||||
|
[JsonPropertyName("version")]
|
||||||
|
public string Version { get; set; } = "1";
|
||||||
|
|
||||||
|
[JsonPropertyName("properties")]
|
||||||
|
public Settings Properties { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace ImageResizer.Properties
|
||||||
|
{
|
||||||
|
public class WrappedJsonConverter<T> : JsonConverter<T>
|
||||||
|
{
|
||||||
|
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if (reader.GetString() != "value")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = (T)JsonSerializer.Deserialize(ref reader, typeof(T), options);
|
||||||
|
reader.Read();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (writer == default)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.WriteStartObject();
|
||||||
|
writer.WritePropertyName("value");
|
||||||
|
|
||||||
|
JsonSerializer.Serialize(writer, value, typeof(T), options);
|
||||||
|
|
||||||
|
writer.WriteEndObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace ImageResizer.Properties
|
||||||
|
{
|
||||||
|
public class WrappedJsonValueConverter : JsonConverterFactory
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type typeToConvert)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override JsonConverter CreateConverter(
|
||||||
|
Type type,
|
||||||
|
JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type keyType = type.UnderlyingSystemType;
|
||||||
|
|
||||||
|
JsonConverter converter = (JsonConverter)Activator.CreateInstance(
|
||||||
|
typeof(WrappedJsonConverter<>).MakeGenericType(keyType));
|
||||||
|
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser;
|
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser;
|
||||||
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
|
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
|
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
|
||||||
@ -35,13 +35,14 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dynamic vscodeSettingsFile = JsonConvert.DeserializeObject<dynamic>(fileContent);
|
JsonElement vscodeSettingsFile = JsonSerializer.Deserialize<JsonElement>(fileContent);
|
||||||
if (vscodeSettingsFile.ContainsKey("remote.SSH.configFile"))
|
if (vscodeSettingsFile.TryGetProperty("remote.SSH.configFile", out var pathElement))
|
||||||
{
|
{
|
||||||
var path = vscodeSettingsFile["remote.SSH.configFile"];
|
var path = pathElement.GetString();
|
||||||
if (File.Exists(path.Value))
|
|
||||||
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
foreach (SshHost h in SshConfig.ParseFile(path.Value))
|
foreach (SshHost h in SshConfig.ParseFile(path))
|
||||||
{
|
{
|
||||||
var machine = new VSCodeRemoteMachine();
|
var machine = new VSCodeRemoteMachine();
|
||||||
machine.Host = h.Host;
|
machine.Host = h.Host;
|
||||||
|
@ -3,13 +3,16 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||||
{
|
{
|
||||||
public class OpenedPathsList
|
public class OpenedPathsList
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("workspaces3")]
|
||||||
public List<dynamic> Workspaces3 { get; set; }
|
public List<dynamic> Workspaces3 { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("entries")]
|
||||||
public List<VSCodeWorkspaceEntry> Entries { get; set; }
|
public List<VSCodeWorkspaceEntry> Entries { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation 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.
|
||||||
|
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||||
{
|
{
|
||||||
public class VSCodeStorageFile
|
public class VSCodeStorageFile
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("openedPathsList")]
|
||||||
public OpenedPathsList OpenedPathsList { get; set; }
|
public OpenedPathsList OpenedPathsList { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,16 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation 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.
|
||||||
|
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||||
{
|
{
|
||||||
public class VSCodeWorkspaceEntry
|
public class VSCodeWorkspaceEntry
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("folderUri")]
|
||||||
public string FolderUri { get; set; }
|
public string FolderUri { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("label")]
|
||||||
public string Label { get; set; }
|
public string Label { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,12 +67,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var options = new JsonSerializerOptions
|
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent);
|
||||||
{
|
|
||||||
PropertyNameCaseInsensitive = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent, options);
|
|
||||||
|
|
||||||
if (vscodeStorageFile != null)
|
if (vscodeStorageFile != null)
|
||||||
{
|
{
|
||||||
|
@ -4,16 +4,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Folder
|
namespace Microsoft.Plugin.Folder
|
||||||
{
|
{
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
|
||||||
public class FolderLink
|
public class FolderLink
|
||||||
{
|
{
|
||||||
[JsonProperty]
|
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public string Nickname =>
|
public string Nickname =>
|
||||||
Path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
|
Path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
|
||||||
.Last()
|
.Last()
|
||||||
|
@ -3,19 +3,15 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Folder
|
namespace Microsoft.Plugin.Folder
|
||||||
{
|
{
|
||||||
public class FolderSettings
|
public class FolderSettings
|
||||||
{
|
{
|
||||||
[JsonProperty]
|
|
||||||
public List<FolderLink> FolderLinks { get; } = new List<FolderLink>();
|
public List<FolderLink> FolderLinks { get; } = new List<FolderLink>();
|
||||||
|
|
||||||
[JsonProperty]
|
|
||||||
public int MaxFolderResults { get; set; } = 50;
|
public int MaxFolderResults { get; set; } = 50;
|
||||||
|
|
||||||
[JsonProperty]
|
|
||||||
public int MaxFileResults { get; set; } = 50;
|
public int MaxFileResults { get; set; } = 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
|
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
|
||||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -7,7 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ namespace PowerLauncher.Plugin
|
|||||||
PluginMetadata metadata;
|
PluginMetadata metadata;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
metadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(configPath));
|
||||||
metadata.PluginDirectory = pluginDirectory;
|
metadata.PluginDirectory = pluginDirectory;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -6,9 +6,9 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ namespace PowerLauncher.Plugin
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
metadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(configPath));
|
||||||
metadata.PluginDirectory = pluginDirectory;
|
metadata.PluginDirectory = pluginDirectory;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -100,7 +100,6 @@
|
|||||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="6.1.1" />
|
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="6.1.1" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||||
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
<PackageReference Include="NuGet.CommandLine" Version="5.7.0">
|
<PackageReference Include="NuGet.CommandLine" Version="5.7.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace PowerLauncher.Storage
|
namespace PowerLauncher.Storage
|
||||||
{
|
{
|
||||||
public class QueryHistory
|
public class QueryHistory
|
||||||
{
|
{
|
||||||
public List<HistoryItem> Items { get; } = new List<HistoryItem>();
|
[JsonInclude]
|
||||||
|
public List<HistoryItem> Items { get; private set; } = new List<HistoryItem>();
|
||||||
|
|
||||||
private readonly int _maxHistory = 300;
|
private readonly int _maxHistory = 300;
|
||||||
|
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace PowerLauncher.Storage
|
namespace PowerLauncher.Storage
|
||||||
{
|
{
|
||||||
public class UserSelectedRecord
|
public class UserSelectedRecord
|
||||||
{
|
{
|
||||||
[JsonProperty]
|
[JsonInclude]
|
||||||
private readonly Dictionary<string, int> records = new Dictionary<string, int>();
|
public Dictionary<string, int> Records { get; private set; } = new Dictionary<string, int>();
|
||||||
|
|
||||||
public void Add(Result result)
|
public void Add(Result result)
|
||||||
{
|
{
|
||||||
@ -22,13 +22,13 @@ namespace PowerLauncher.Storage
|
|||||||
}
|
}
|
||||||
|
|
||||||
var key = result.ToString();
|
var key = result.ToString();
|
||||||
if (records.TryGetValue(key, out int value))
|
if (Records.TryGetValue(key, out int value))
|
||||||
{
|
{
|
||||||
records[key] = value + 1;
|
Records[key] = value + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
records.Add(key, 1);
|
Records.Add(key, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace PowerLauncher.Storage
|
|||||||
throw new ArgumentNullException(nameof(result));
|
throw new ArgumentNullException(nameof(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != null && records.TryGetValue(result.ToString(), out int value))
|
if (result != null && Records.TryGetValue(result.ToString(), out int value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ using System.ComponentModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using System.Text.Json.Serialization;
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
namespace Wox.Infrastructure
|
namespace Wox.Infrastructure
|
||||||
@ -81,7 +81,14 @@ namespace Wox.Infrastructure
|
|||||||
|
|
||||||
public static string Formatted<T>(this T t)
|
public static string Formatted<T>(this T t)
|
||||||
{
|
{
|
||||||
var formatted = JsonConvert.SerializeObject(t, Formatting.Indented, new StringEnumConverter());
|
var formatted = JsonSerializer.Serialize(t, new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
WriteIndented = true,
|
||||||
|
Converters =
|
||||||
|
{
|
||||||
|
new JsonStringEnumConverter(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Storage
|
namespace Wox.Infrastructure.Storage
|
||||||
@ -20,7 +20,16 @@ namespace Wox.Infrastructure.Storage
|
|||||||
private static readonly IPath Path = FileSystem.Path;
|
private static readonly IPath Path = FileSystem.Path;
|
||||||
private static readonly IFile File = FileSystem.File;
|
private static readonly IFile File = FileSystem.File;
|
||||||
|
|
||||||
private readonly JsonSerializerSettings _serializerSettings;
|
// use property initialization instead of DefaultValueAttribute
|
||||||
|
// easier and flexible for default value of object
|
||||||
|
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
IgnoreNullValues = true,
|
||||||
|
IncludeFields = true,
|
||||||
|
PropertyNameCaseInsensitive = true,
|
||||||
|
WriteIndented = true,
|
||||||
|
};
|
||||||
|
|
||||||
private T _data;
|
private T _data;
|
||||||
|
|
||||||
// need a new directory name
|
// need a new directory name
|
||||||
@ -35,17 +44,6 @@ namespace Wox.Infrastructure.Storage
|
|||||||
private const int _jsonStorage = 1;
|
private const int _jsonStorage = 1;
|
||||||
private StoragePowerToysVersionInfo _storageHelper;
|
private StoragePowerToysVersionInfo _storageHelper;
|
||||||
|
|
||||||
internal JsonStorage()
|
|
||||||
{
|
|
||||||
// use property initialization instead of DefaultValueAttribute
|
|
||||||
// easier and flexible for default value of object
|
|
||||||
_serializerSettings = new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Load()
|
public T Load()
|
||||||
{
|
{
|
||||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, _jsonStorage);
|
_storageHelper = new StoragePowerToysVersionInfo(FilePath, _jsonStorage);
|
||||||
@ -84,7 +82,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_data = JsonConvert.DeserializeObject<T>(serialized, _serializerSettings);
|
_data = JsonSerializer.Deserialize<T>(serialized, _serializerOptions);
|
||||||
}
|
}
|
||||||
catch (JsonException e)
|
catch (JsonException e)
|
||||||
{
|
{
|
||||||
@ -105,7 +103,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
BackupOriginFile();
|
BackupOriginFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
_data = JsonConvert.DeserializeObject<T>("{}", _serializerSettings);
|
_data = JsonSerializer.Deserialize<T>("{}", _serializerOptions);
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
string serialized = JsonSerializer.Serialize(_data, _serializerOptions);
|
||||||
File.WriteAllText(FilePath, serialized);
|
File.WriteAllText(FilePath, serialized);
|
||||||
_storageHelper.Close();
|
_storageHelper.Close();
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation 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.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.UserSettings
|
namespace Wox.Infrastructure.UserSettings
|
||||||
@ -177,7 +176,7 @@ namespace Wox.Infrastructure.UserSettings
|
|||||||
|
|
||||||
public HttpProxy Proxy { get; set; } = new HttpProxy();
|
public HttpProxy Proxy { get; set; } = new HttpProxy();
|
||||||
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;
|
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Wox.Plugin
|
namespace Wox.Plugin
|
||||||
{
|
{
|
||||||
[JsonObject(MemberSerialization.OptOut)]
|
|
||||||
public class PluginMetadata : BaseModel
|
public class PluginMetadata : BaseModel
|
||||||
{
|
{
|
||||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||||
@ -36,6 +35,7 @@ namespace Wox.Plugin
|
|||||||
|
|
||||||
public bool Disabled { get; set; }
|
public bool Disabled { get; set; }
|
||||||
|
|
||||||
|
[JsonInclude]
|
||||||
public string ExecuteFilePath { get; private set; }
|
public string ExecuteFilePath { get; private set; }
|
||||||
|
|
||||||
public string ExecuteFileName { get; set; }
|
public string ExecuteFileName { get; set; }
|
||||||
|
@ -69,7 +69,6 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
|
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
|
||||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -284,9 +284,6 @@
|
|||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
|
||||||
<Version>2.0.1</Version>
|
<Version>2.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Newtonsoft.Json">
|
|
||||||
<Version>13.0.1</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="StyleCop.Analyzers">
|
<PackageReference Include="StyleCop.Analyzers">
|
||||||
<Version>1.1.118</Version>
|
<Version>1.1.118</Version>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
Loading…
Reference in New Issue
Block a user