From 3e91d891fa1e082cbf4eb82ee6a78601deae3c1c Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Fri, 9 Feb 2024 21:30:08 +0300 Subject: [PATCH] add - doc - Added sumtext --- We've added sumtext. This is going to be the last command that is going to be added to the final version of 0.1.0 for stability reasons. --- Type: add Breaking: False Doc Required: True Part: 1/1 --- .../Shell/Shells/UESH/Commands/SumFile.cs | 2 +- .../Shell/Shells/UESH/Commands/SumFiles.cs | 2 +- .../Shell/Shells/UESH/Commands/SumText.cs | 82 +++++++++++++++++++ .../Shell/Shells/UESH/UESHShellInfo.cs | 12 +++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 public/Nitrocid/Shell/Shells/UESH/Commands/SumText.cs diff --git a/public/Nitrocid/Shell/Shells/UESH/Commands/SumFile.cs b/public/Nitrocid/Shell/Shells/UESH/Commands/SumFile.cs index 70bc17f091..c7dbb5189e 100644 --- a/public/Nitrocid/Shell/Shells/UESH/Commands/SumFile.cs +++ b/public/Nitrocid/Shell/Shells/UESH/Commands/SumFile.cs @@ -39,7 +39,7 @@ namespace Nitrocid.Shell.Shells.UESH.Commands /// Calculates the sum of a file /// /// - /// Calculating the hash sum of files is important, because it lets users verify if the file is corrupt or not. It calculates the sum of a file using either the MD5, SHA1, SHA256, or SHA512 algorithms. + /// Calculating the hash sum of files is important, because it lets users verify if the file is corrupt or not. It calculates the sum of a file using the available algorithms. /// class SumFileCommand : BaseCommand, ICommand { diff --git a/public/Nitrocid/Shell/Shells/UESH/Commands/SumFiles.cs b/public/Nitrocid/Shell/Shells/UESH/Commands/SumFiles.cs index dbc28f00de..8e26bee1f5 100644 --- a/public/Nitrocid/Shell/Shells/UESH/Commands/SumFiles.cs +++ b/public/Nitrocid/Shell/Shells/UESH/Commands/SumFiles.cs @@ -40,7 +40,7 @@ namespace Nitrocid.Shell.Shells.UESH.Commands /// Calculates the sum of files /// /// - /// Calculating the hash sum of files is important, because it lets users verify if the file is corrupt or not. It calculates the sum of files using either the MD5, SHA1, SHA256, or SHA512 algorithms. + /// Calculating the hash sum of files is important, because it lets users verify if the file is corrupt or not. It calculates the sum of files using the available algorithms. /// class SumFilesCommand : BaseCommand, ICommand { diff --git a/public/Nitrocid/Shell/Shells/UESH/Commands/SumText.cs b/public/Nitrocid/Shell/Shells/UESH/Commands/SumText.cs new file mode 100644 index 0000000000..823f5a8ff9 --- /dev/null +++ b/public/Nitrocid/Shell/Shells/UESH/Commands/SumText.cs @@ -0,0 +1,82 @@ +// +// Nitrocid KS Copyright (C) 2018-2024 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using Nitrocid.ConsoleBase.Colors; +using Nitrocid.ConsoleBase.Writers; +using Terminaux.Writer.ConsoleWriters; +using Nitrocid.Drivers; +using Nitrocid.Drivers.Encryption; +using Nitrocid.Files; +using Nitrocid.Files.Operations.Querying; +using Nitrocid.Kernel.Exceptions; +using Nitrocid.Languages; +using Nitrocid.Shell.ShellBase.Commands; + +namespace Nitrocid.Shell.Shells.UESH.Commands +{ + /// + /// Calculates the sum of a text + /// + /// + /// It calculates the sum of a text using the available algorithms. + /// + class SumTextCommand : BaseCommand, ICommand + { + + public override int Execute(CommandParameters parameters, ref string variableValue) + { + string text = parameters.ArgumentsList[1]; + if (DriverHandler.IsRegistered(DriverTypes.Encryption, parameters.ArgumentsList[0])) + { + // Time when you're on a breakpoint is counted + var spent = new Stopwatch(); + spent.Start(); + string encrypted = Encryption.GetEncryptedString(text, parameters.ArgumentsList[0]); + TextWriterColor.Write(encrypted); + TextWriterColor.Write(Translate.DoTranslation("Time spent: {0} milliseconds"), spent.ElapsedMilliseconds); + spent.Stop(); + } + else if (parameters.ArgumentsList[0] == "all") + { + foreach (string driverName in DriverHandler.GetDriverNames()) + { + // Time when you're on a breakpoint is counted + var spent = new Stopwatch(); + spent.Start(); + string encrypted = Encryption.GetEncryptedString(text, driverName); + TextWriterColor.Write($"{driverName}: {encrypted}"); + TextWriterColor.Write(Translate.DoTranslation("Time spent: {0} milliseconds"), spent.ElapsedMilliseconds); + spent.Stop(); + } + } + else + { + TextWriters.Write(Translate.DoTranslation("Invalid encryption algorithm."), true, KernelColorType.Error); + return 10000 + (int)KernelExceptionType.Encryption; + } + return 0; + } + + } +} diff --git a/public/Nitrocid/Shell/Shells/UESH/UESHShellInfo.cs b/public/Nitrocid/Shell/Shells/UESH/UESHShellInfo.cs index 96ca1f25cf..c7329c3d0e 100644 --- a/public/Nitrocid/Shell/Shells/UESH/UESHShellInfo.cs +++ b/public/Nitrocid/Shell/Shells/UESH/UESHShellInfo.cs @@ -1388,6 +1388,18 @@ internal class UESHShellInfo : BaseShellInfo, IShellInfo ]) ], new SumFilesCommand()), + new CommandInfo("sumtext", /* Localizable */ "Calculates text sums.", + [ + new CommandArgumentInfo( + [ + new CommandArgumentPart(true, "algorithm/all", new CommandArgumentPartOptions() + { + AutoCompleter = (_) => EncryptionDriverTools.GetEncryptionDriverNames() + }), + new CommandArgumentPart(true, "text"), + ]) + ], new SumTextCommand()), + new CommandInfo("symlink", /* Localizable */ "Creates a symbolic link to a file or a folder", [ new CommandArgumentInfo(new[]