Skip to content

Commit

Permalink
Merge pull request #52 from 0x78654C/1.8.5-newFeature
Browse files Browse the repository at this point in the history
1.8.5 new feature
  • Loading branch information
0x78654C authored Jun 25, 2024
2 parents cc4d811 + d113701 commit 7aef420
Show file tree
Hide file tree
Showing 32 changed files with 229 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Commands/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.7.0")]
[assembly: AssemblyFileVersion("1.7.7.0")]
[assembly: AssemblyVersion("1.7.8.0")]
[assembly: AssemblyFileVersion("1.7.8.0")]
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/Alias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Execute(string args)
{
try
{
if (args.Length == 5)
if (args == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/FileShred.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Execute(string args)
{
try
{
if (args.Length == 5 && !GlobalVariables.isPipeCommand)
if (args == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/FileSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Execute(string args)
{
var currentDirectory = File.ReadAllText(GlobalVariables.currentDirectory);

if (args.Length == 4 && !GlobalVariables.isPipeCommand)
if (args == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
1 change: 1 addition & 0 deletions Commands/TerminalCommands/ConsoleSystem/Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ xTerminal Copyright @ 2020-2024 0x078654c
echo -- Write/append data to a file. Use -h for additional help.
diff -- Outputs the difference between two files. Use -h for additional help.
exif -- Extracts image metadata. Use -h for additional help.
pjson -- Prettify the JSON data. Use -h for additional help.
---------------------- Networking ----------------------
ifconfig -- Display onboard Network Interface Cards configuration (Ethernet and Wireless)
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/HexViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Execute(string args)
s_currentDirectory = File.ReadAllText(GlobalVariables.currentDirectory);
var arg = args.Split(' ');

if (args.Length == 3 && !GlobalVariables.isPipeCommand)
if (args == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NewTWindow : ITerminalCommand
public void Execute(string args)
{

if (args.Length > 2 && !args.Contains("-u"))
if (args ==Name && !args.Contains("-u"))
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/ProcessKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Execute(string arg)
{
try
{
if (arg.Length == 3)
if (arg == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/ConsoleSystem/StartProccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Execute(string args)
// Set directory, to be used in other functions
s_currentDirectory =
File.ReadAllText(GlobalVariables.currentDirectory);
if (args.Length == 2)
if (args == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
32 changes: 18 additions & 14 deletions Commands/TerminalCommands/DirFiles/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Delete : ITerminalCommand
public void Execute(string args)
{
_currentLocation = File.ReadAllText(GlobalVariables.currentDirectory);
if (args.Length == 3 && !GlobalVariables.isPipeCommand)
if (args == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down Expand Up @@ -50,7 +50,11 @@ public void Execute(string args)
else
{
args = args.Replace("del ", "");
DeleteFile(args, _currentLocation);
if (GlobalVariables.isPipeCommand && GlobalVariables.pipeCmdCount == 0 || GlobalVariables.pipeCmdCount < GlobalVariables.pipeCmdCountTemp)
args = FileSystem.SanitizePath(GlobalVariables.pipeCmdOutput.Trim(), _currentLocation);
else
args = FileSystem.SanitizePath(args, _currentLocation);
DeleteFile(args);
}
}

Expand Down Expand Up @@ -79,29 +83,29 @@ private void DeleteAllFilesDris(string currentLocation, bool fileDelete, bool di
}
}
}
private void DeleteFile(string arg, string currentLocation)

/// <summary>
/// Delete File/Directory method.
/// </summary>
/// <param name="arg"></param>
private void DeleteFile(string arg)
{
string input = string.Empty;
if (GlobalVariables.isPipeCommand && GlobalVariables.pipeCmdCount >0)
input = FileSystem.SanitizePath(GlobalVariables.pipeCmdOutput.Trim(), currentLocation);
else
input = FileSystem.SanitizePath(arg, currentLocation);
try
{
// Get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(input);
FileAttributes attr = File.GetAttributes(arg);

if (attr.HasFlag(FileAttributes.Directory))
{
var dir = new DirectoryInfo(input);
var dir = new DirectoryInfo(arg);
RecursiveDeleteDir(dir);
FileSystem.SuccessWriteLine($"Directory {input} deleted!");
FileSystem.SuccessWriteLine($"Directory {arg} deleted!");
}
else
{
File.SetAttributes(input, FileAttributes.Normal);
File.Delete(input);
FileSystem.SuccessWriteLine($"File {input} deleted!");
File.SetAttributes(arg, FileAttributes.Normal);
File.Delete(arg);
FileSystem.SuccessWriteLine($"File {arg} deleted!");
}
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/Difference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Execute(string args)
{
_currentLocation = File.ReadAllText(GlobalVariables.currentDirectory);

if (args.Length == 4)
if (args == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/Echo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Execute(string arg)
try
{
_currentLocation = File.ReadAllText(GlobalVariables.currentDirectory);
if (arg.Length == 4)
if (arg == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
5 changes: 5 additions & 0 deletions Commands/TerminalCommands/DirFiles/Exif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public void Execute(string args)
Console.WriteLine(s_helpMessage);
return;
}
if (args == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
}
var currentDirectory = File.ReadAllText(GlobalVariables.currentDirectory);
var pathFile = string.Empty;
var param = FileSystem.SanitizePath(args.Replace($"{Name}", "").Trim(), currentDirectory);
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/FCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void FCopyRun(string param)
return;
}

if (param.Length == 5)
if (param == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/FMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void FMoveRun(string param)
return;
}

if (param.Length == 5)
if (param == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
106 changes: 106 additions & 0 deletions Commands/TerminalCommands/DirFiles/JsonPrettifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Core;
using System;
using System.IO;
using System.Runtime.Versioning;
using Core.SystemTools;

namespace Commands.TerminalCommands.DirFiles
{
[SupportedOSPlatform("Windows")]
public class JsonPrettifier : ITerminalCommand
{
public string Name => "pjson";
private static string s_helpMessage = @"Usage of pjson command:
pjson -h : Display this message.
pjson <file_path> : Will prettify the JSON data and stores back in file.
pjson <file_path> -o <new_file_path> : Stores the prettified JSON in new file.
";
public void Execute(string arg)
{
if (arg == $"{Name} -h" && !GlobalVariables.isPipeCommand)
{
Console.WriteLine(s_helpMessage);
return;
}

if (arg == Name && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
}

arg = arg.Replace($"{Name}", "").Trim();
var currentDirectory = File.ReadAllText(GlobalVariables.currentDirectory);
var param = arg.Split(' ');
// Store to file param
if (param.ContainsParameter("-o"))
{
var jFile = arg.SplitByText("-o")[0].Trim();
jFile = FileSystem.SanitizePath(jFile, currentDirectory);
if (GlobalVariables.isPipeCommand && GlobalVariables.pipeCmdCount == 0 || GlobalVariables.pipeCmdCount < GlobalVariables.pipeCmdCountTemp)
jFile = FileSystem.SanitizePath(GlobalVariables.pipeCmdOutput.Trim(), currentDirectory);
var newFile = arg.SplitByText("-o")[1].Trim();
newFile = FileSystem.SanitizePath(newFile, currentDirectory);

if (!File.Exists(jFile))
{
FileSystem.ErrorWriteLine($"Original file not found: {jFile}");
return;
}

if (File.Exists(newFile))
{
Console.WriteLine($"File already exist: {newFile}.");
Console.Write($"Do you want to overwrite it? YES (Y), NO (N): ");
var userImputKey = Console.ReadKey();

switch (userImputKey.KeyChar.ToString().ToLower())
{
case "y":
var readJsonFileOriginal = File.ReadAllText(jFile);
var jsonPrettyOriginal = JsonManage.JsonPrettifier(readJsonFileOriginal);
Console.Write("\n");
File.WriteAllText(newFile, jsonPrettyOriginal);
if (newFile != jFile)
FileSystem.SuccessWriteLine($"Current JSON file prettified: {newFile}");
else
FileSystem.SuccessWriteLine($"Original JSON file prettified: {newFile}");
break;
default:
Console.Write("\n");
break;

}
}
else
{
var readJsonFileOriginal = File.ReadAllText(jFile);
var jsonPrettyOriginal = JsonManage.JsonPrettifier(readJsonFileOriginal);
File.WriteAllText(newFile, jsonPrettyOriginal);
FileSystem.SuccessWriteLine($"Saved new JSON file prettified: {newFile}");
}
return;
}

var jsonFile = FileSystem.SanitizePath(arg, currentDirectory).Trim();
if (GlobalVariables.isPipeCommand && GlobalVariables.pipeCmdCount == 0 || GlobalVariables.pipeCmdCount < GlobalVariables.pipeCmdCountTemp)
jsonFile = FileSystem.SanitizePath(GlobalVariables.pipeCmdOutput.Trim(), currentDirectory);

if (!File.Exists(jsonFile))
{
FileSystem.ErrorWriteLine($"File not found: {jsonFile}");
return;
}

var readJsonFile = File.ReadAllText(jsonFile);
var jsonPretty = JsonManage.JsonPrettifier(readJsonFile);


if (File.Exists(jsonFile))
{
File.WriteAllText(jsonFile, jsonPretty);
FileSystem.SuccessWriteLine($"Original JSON file prettified: {jsonFile}");
}
}
}
}
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/MD5Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Execute(string arg)
}

// Empty command info display.
if (arg.Length == 3)
if (arg == Name)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
2 changes: 1 addition & 1 deletion Commands/TerminalCommands/DirFiles/StringView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Execute(string arg)
string fileSearchIn = string.Empty;
string saveToFile;

if (arg.Length == 3 && !arg.Contains("-lc") && !GlobalVariables.isPipeCommand)
if (arg == Name && !arg.Contains("-lc") && !GlobalVariables.isPipeCommand)
{
FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!");
return;
Expand Down
3 changes: 2 additions & 1 deletion Commands/TerminalCommands/Network/ExternalIp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Core;
using System;
using System.Net;
using System.Net.Http;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;

Expand All @@ -25,7 +26,7 @@ public void Execute(string arg)
}

string externalIP;
externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org");
externalIP = (new HttpClient()).GetStringAsync("http://checkip.dyndns.org").Result;
externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
.Matches(externalIP)[0].ToString();
if (GlobalVariables.isPipeCommand && GlobalVariables.pipeCmdCount > 0)
Expand Down
Loading

0 comments on commit 7aef420

Please sign in to comment.