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

Functionality to GZip compress/decompress strings #214

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
15 changes: 15 additions & 0 deletions src/dev/impl/DevToys/Assets/Icons/Gzip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolProvider.cs" />
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolViewModel.cs" />
<Compile Include="ViewModels\Tools\Converters\ConvertersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolProvider.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolViewModel.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\EncodersDecodersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\Generators\GeneratorsGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\Generators\LoremIpsumGenerator\LoremIpsumGeneratorToolProvider.cs" />
Expand All @@ -67,6 +69,9 @@
<Compile Include="Views\Tools\AllTools\AllToolsToolPage.xaml.cs">
<DependentUpon>AllToolsToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolPage.xaml.cs">
<DependentUpon>GZipEncoderDecoderToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\Graphic\ColorBlindnessSimulator\ColorBlindnessSimulatorToolPage.xaml.cs">
<DependentUpon>ColorBlindnessSimulatorToolPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -461,6 +466,7 @@
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<PRIResource Include="Strings\en-US\GZipEncoderDecoder.resw" />
jedjohan marked this conversation as resolved.
Show resolved Hide resolved
<PRIResource Include="Strings\*\*.resw" />
<Page Include="Themes\Custom.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -502,6 +508,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Tools\EncodersDecoders\Base64EncoderDecoder\Base64EncoderDecoderToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
86 changes: 86 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class LanguageManager : ObservableObject
private readonly ColorBlindnessSimulatorStrings _colorblindnesssimulator = new ColorBlindnessSimulatorStrings();
private readonly CommonStrings _common = new CommonStrings();
private readonly GuidGeneratorStrings _guidgenerator = new GuidGeneratorStrings();
private readonly GZipEncoderDecoderStrings _gzipencoderdecoder = new GZipEncoderDecoderStrings();
private readonly HashGeneratorStrings _hashgenerator = new HashGeneratorStrings();
private readonly HtmlEncoderDecoderStrings _htmlencoderdecoder = new HtmlEncoderDecoderStrings();
private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();
Expand Down Expand Up @@ -82,6 +83,11 @@ public partial class LanguageManager : ObservableObject
/// </summary>
public GuidGeneratorStrings GuidGenerator => _guidgenerator;

/// <summary>
/// Gets the <see cref="GZipEncoderDecoderStrings"/>.
/// </summary>
public GZipEncoderDecoderStrings GZipEncoderDecoder => _gzipencoderdecoder;

/// <summary>
/// Gets the <see cref="HashGeneratorStrings"/>.
/// </summary>
Expand Down Expand Up @@ -582,6 +588,86 @@ public class GuidGeneratorStrings : ObservableObject
public string SearchDisplayName => _resources.GetString("SearchDisplayName");
}

public class GZipEncoderDecoderStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("GZipEncoderDecoder");

/// <summary>
/// Gets the resource AccessibleName.
/// </summary>
public string AccessibleName => _resources.GetString("AccessibleName");

/// <summary>
/// Gets the resource Ascii.
/// </summary>
public string Ascii => _resources.GetString("Ascii");

/// <summary>
/// Gets the resource ConfigurationTitle.
/// </summary>
public string ConfigurationTitle => _resources.GetString("ConfigurationTitle");

/// <summary>
/// Gets the resource ConversionDecompress.
/// </summary>
public string ConversionDecompress => _resources.GetString("ConversionDecompress");

/// <summary>
/// Gets the resource ConversionDescription.
/// </summary>
public string ConversionDescription => _resources.GetString("ConversionDescription");

/// <summary>
/// Gets the resource ConversionCompress.
/// </summary>
public string ConversionCompress => _resources.GetString("ConversionCompress");

/// <summary>
/// Gets the resource ConversionTitle.
/// </summary>
public string ConversionTitle => _resources.GetString("ConversionTitle");

/// <summary>
/// Gets the resource MenuDisplayName.
/// </summary>
public string MenuDisplayName => _resources.GetString("MenuDisplayName");

/// <summary>
/// Gets the resource EncodingDescription.
/// </summary>
public string EncodingDescription => _resources.GetString("EncodingDescription");

/// <summary>
/// Gets the resource EncodingTitle.
/// </summary>
public string EncodingTitle => _resources.GetString("EncodingTitle");

/// <summary>
/// Gets the resource InputTitle.
/// </summary>
public string InputTitle => _resources.GetString("InputTitle");

/// <summary>
/// Gets the resource OutputTitle.
/// </summary>
public string OutputTitle => _resources.GetString("OutputTitle");

/// <summary>
/// Gets the resource Utf8.
/// </summary>
public string Utf8 => _resources.GetString("Utf8");

/// <summary>
/// Gets the resource Description.
/// </summary>
public string Description => _resources.GetString("Description");

/// <summary>
/// Gets the resource SearchDisplayName.
/// </summary>
public string SearchDisplayName => _resources.GetString("SearchDisplayName");
}

public class HashGeneratorStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("HashGenerator");
Expand Down
165 changes: 165 additions & 0 deletions src/dev/impl/DevToys/Strings/en-US/GZipEncoderDecoder.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AccessibleName" xml:space="preserve">
<value>GZip Encoder and Decoder tool</value>
</data>
<data name="Ascii" xml:space="preserve">
<value>ASCII</value>
</data>
<data name="ConfigurationTitle" xml:space="preserve">
<value>Configuration</value>
</data>
<data name="ConversionDecompress" xml:space="preserve">
<value>Decompress</value>
</data>
<data name="ConversionDescription" xml:space="preserve">
<value>Select compress or decompress</value>
</data>
<data name="ConversionCompress" xml:space="preserve">
<value>Compress</value>
</data>
<data name="ConversionTitle" xml:space="preserve">
<value>Compress/Decompress</value>
jedjohan marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="MenuDisplayName" xml:space="preserve">
<value>GZip</value>
</data>
<data name="EncodingDescription" xml:space="preserve">
<value>Compress or decompress strings with GZip</value>
</data>
<data name="EncodingTitle" xml:space="preserve">
<value>Encoding</value>
</data>
<data name="InputTitle" xml:space="preserve">
<value>Input</value>
</data>
<data name="OutputTitle" xml:space="preserve">
<value>Output</value>
</data>
<data name="Utf8" xml:space="preserve">
<value>UTF-8</value>
</data>
<data name="Description" xml:space="preserve">
<value>Compress or decompress strings</value>
</data>
<data name="SearchDisplayName" xml:space="preserve">
<value>GZip Compress/Decompress</value>
jedjohan marked this conversation as resolved.
Show resolved Hide resolved
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#nullable enable

using System.Composition;
using DevToys.Shared.Api.Core;
using DevToys.Api.Tools;
using DevToys.Core.Threading;
using Windows.UI.Xaml.Controls;

namespace DevToys.ViewModels.Tools.GZipEncoderDecoder
{
[Export(typeof(IToolProvider))]
[Name("GZip Compress/Decompress")]
[Parent(EncodersDecodersGroupToolProvider.InternalName)]
[ProtocolName("gzip")]
[Order(1)]
internal sealed class GZipEncoderDecoderToolProvider : ToolProviderBase, IToolProvider
{
public string MenuDisplayName => LanguageManager.Instance.GZipEncoderDecoder.MenuDisplayName;

public string? SearchDisplayName => LanguageManager.Instance.GZipEncoderDecoder.SearchDisplayName;

public string? Description => LanguageManager.Instance.GZipEncoderDecoder.Description;

public string AccessibleName => LanguageManager.Instance.GZipEncoderDecoder.AccessibleName;

public TaskCompletionNotifier<IconElement> IconSource => CreateSvgIcon("Gzip.svg"); // TODO: icon. Dont know how to create svg stuff
veler marked this conversation as resolved.
Show resolved Hide resolved

private readonly IMefProvider _mefProvider;

[ImportingConstructor]
public GZipEncoderDecoderToolProvider(IMefProvider mefProvider)
{
_mefProvider = mefProvider;
}

public bool CanBeTreatedByTool(string data)
{
if (string.IsNullOrWhiteSpace(data))
{
return false;
}

string? trimmedData = data.Trim();
return trimmedData.StartsWith("H4sI");
veler marked this conversation as resolved.
Show resolved Hide resolved
}

public IToolViewModel CreateTool()
{
return _mefProvider.Import<GZipEncoderDecoderToolViewModel>();
}
}
}
Loading