From 07edf94bbdd81dead0d645e348f87d61d0b39165 Mon Sep 17 00:00:00 2001 From: frederik-hoeft <43813142+frederik-hoeft@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:20:18 +0100 Subject: [PATCH] simplify Guid description switch + update devdocs --- .../plugins/community.valuegenerator.md | 7 +++- .../Generators/GUID/GUIDGenerator.cs | 1 - .../Generators/GUID/GUIDRequest.cs | 38 ++++--------------- .../Helper/QueryHelper.cs | 1 - 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/doc/devdocs/modules/launcher/plugins/community.valuegenerator.md b/doc/devdocs/modules/launcher/plugins/community.valuegenerator.md index 4a580f090d..9b94ae78f2 100644 --- a/doc/devdocs/modules/launcher/plugins/community.valuegenerator.md +++ b/doc/devdocs/modules/launcher/plugins/community.valuegenerator.md @@ -1,6 +1,6 @@ # Value Generator Plugin -The Value Generator plugin is used to generate hashes for strings, to calculate base64 encodings, escape and encode URLs/URIs and to generate GUIDs versions 1, 3, 4 and 5. +The Value Generator plugin is used to generate hashes for strings, to calculate base64 encodings, escape and encode URLs/URIs and to generate GUIDs of version 1, 3, 4, 5, and 7. ![Image of Value Generator plugin](/doc/images/launcher/plugin/community.valuegenerator.png) @@ -34,7 +34,10 @@ The Value Generator plugin is used to generate hashes for strings, to calculate ### [`GUIDGenerator`](/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDGenerator.cs) - Utility class for generating or calculating GUIDs -- Generating GUID versions 1 and 4 is done using builtin APIs. [`UuidCreateSequential`](https://learn.microsoft.com/en-us/windows/win32/api/rpcdce/nf-rpcdce-uuidcreatesequential) for version 1 and `System.Guid.NewGuid()` for version 4 +- Generating GUID versions 1, 4, and 7 is done using builtin APIs: + - [`UuidCreateSequential`](https://learn.microsoft.com/en-us/windows/win32/api/rpcdce/nf-rpcdce-uuidcreatesequential) for version 1 + - `System.Guid.NewGuid()` for version 4 + - `System.Guid.CreateVersion7()` for version 7 - Versions 3 and 5 take two parameters, a namespace and a name - The namespace must be a valid GUID or one of the [predefined ones](https://datatracker.ietf.org/doc/html/rfc4122#appendix-C) - The `PredefinedNamespaces` dictionary contains aliases for the predefined namespaces diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDGenerator.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDGenerator.cs index eaba59ce81..8039877665 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDGenerator.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDGenerator.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Buffers.Binary; using System.Collections.Generic; using System.Net; using System.Security.Cryptography; diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDRequest.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDRequest.cs index c05b0d66a7..718b4b709a 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDRequest.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Generators/GUID/GUIDRequest.cs @@ -4,7 +4,6 @@ using System; using System.Security.Cryptography; -using WinRT; using Wox.Plugin.Logger; namespace Community.PowerToys.Run.Plugin.ValueGenerator.GUID @@ -19,36 +18,15 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator.GUID private int Version { get; set; } - public string Description + public string Description => Version switch { - get - { - switch (Version) - { - case 1: - return "Version 1: Time base GUID"; - case 3: - case 5: - string hashAlgorithm; - if (Version == 3) - { - hashAlgorithm = HashAlgorithmName.MD5.ToString(); - } - else - { - hashAlgorithm = HashAlgorithmName.SHA1.ToString(); - } - - return $"Version {Version} ({hashAlgorithm}): Namespace and name based GUID."; - case 4: - return "Version 4: Randomly generated GUID"; - case 7: - return "Version 7: Time-ordered randomly generated GUID"; - default: - return string.Empty; - } - } - } + 1 => "Version 1: Time base GUID", + 3 => $"Version 3 ({HashAlgorithmName.MD5}): Namespace and name based GUID.", + 4 => "Version 4: Randomly generated GUID", + 5 => $"Version 5 ({HashAlgorithmName.SHA1}): Namespace and name based GUID.", + 7 => "Version 7: Time-ordered randomly generated GUID", + _ => string.Empty, + }; private Guid? GuidNamespace { get; set; } diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Helper/QueryHelper.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Helper/QueryHelper.cs index d97b6b471c..6fb73f5268 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Helper/QueryHelper.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Helper/QueryHelper.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Globalization; -using System.Text; using Community.PowerToys.Run.Plugin.ValueGenerator.Properties;