Skip to content

Commit

Permalink
add - doc - Added sumtext
Browse files Browse the repository at this point in the history
---

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
  • Loading branch information
AptiviCEO committed Feb 9, 2024
1 parent 926f642 commit 3e91d89
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/Nitrocid/Shell/Shells/UESH/Commands/SumFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Nitrocid.Shell.Shells.UESH.Commands
/// Calculates the sum of a file
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
class SumFileCommand : BaseCommand, ICommand
{
Expand Down
2 changes: 1 addition & 1 deletion public/Nitrocid/Shell/Shells/UESH/Commands/SumFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Nitrocid.Shell.Shells.UESH.Commands
/// Calculates the sum of files
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
class SumFilesCommand : BaseCommand, ICommand
{
Expand Down
82 changes: 82 additions & 0 deletions public/Nitrocid/Shell/Shells/UESH/Commands/SumText.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

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
{
/// <summary>
/// Calculates the sum of a text
/// </summary>
/// <remarks>
/// It calculates the sum of a text using the available algorithms.
/// </remarks>
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<IEncryptionDriver>())
{
// 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;
}

}
}
12 changes: 12 additions & 0 deletions public/Nitrocid/Shell/Shells/UESH/UESHShellInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit 3e91d89

Please sign in to comment.