Code cleanup

This commit is contained in:
Stone_Red
2026-06-12 15:18:02 +02:00
parent 9f2aae3ba8
commit c70fd501bc
11 changed files with 735 additions and 707 deletions
+2 -3
View File
@@ -5,8 +5,8 @@ using Org.BouncyCastle.Crypto.Parameters;
using System.Security.Cryptography;
using System.Text;
namespace RemSox.Cryptography
{
namespace RemSox.Cryptography;
public static class AesGcmCrypto
{
private const int NonceSize = 12;
@@ -67,4 +67,3 @@ namespace RemSox.Cryptography
return Encoding.UTF8.GetString(plain);
}
}
}
+7 -7
View File
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Cosmos.Kernel.System.Keyboard;
using Cosmos.Kernel.System.Mouse;
using RemSox.Plugs;
using System.Drawing;
namespace RemSox.Cryptography;
public static class CryptoManager
@@ -26,7 +23,10 @@ public static class CryptoManager
RandomNumberGeneratorImplementationImpl.AddMouseEntropy(dx, dy, dz, x, y);
if (!KeyboardManager.KeyAvailable) return;
if (!KeyboardManager.KeyAvailable)
{
return;
}
KeyEvent keyEvent = KeyboardManager.Peek();
+2 -3
View File
@@ -3,8 +3,8 @@ using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
namespace RemSox.Cryptography
{
namespace RemSox.Cryptography;
public static class Pkcs5S2PasswordKeyDeriver
{
private const int KeySize = 32; // 256-bit key
@@ -24,4 +24,3 @@ namespace RemSox.Cryptography
.GetKey();
}
}
}
+3 -2
View File
@@ -1,9 +1,11 @@
global using Sys = Cosmos.Kernel.System;
using RemSox.Cryptography;
using RemSox.Processes;
using RemSox.Processing;
using RemSox.UI.CLI;
using RemSox.UI.CLI.Commands;
using System.Runtime;
namespace RemSox;
@@ -34,8 +36,7 @@ public class Kernel : Sys.Kernel
Sys.Mouse.MouseManager.Initialize();
Sys.Mouse.MouseManager.SetScreenSize((int)canvas.Mode.Width, (int)canvas.Mode.Height);
Sys.Keyboard.KeyboardManager.Initialize();
ProcessManager.SpawnProcess<CliProcess>();
_ = ProcessManager.SpawnProcess<CliProcess>();
}
protected override void Run()
+6 -8
View File
@@ -1,14 +1,13 @@
using System;
using RemSox.Processing;
using RemSox.Utils;
using YesNt.Interpreter.Runtime;
using YesNt.Interpreter.Utilities;
namespace RemSox.Processes
{
using YesNt.Interpreter.Runtime;
namespace RemSox.Processes;
public class YesNtInterpreterProcess() : Process("YesNtInterpreter")
{
YesNtInterpreter interpreter = null!;
private YesNtInterpreter interpreter = null!;
internal override void Start(string[] args)
{
@@ -32,7 +31,7 @@ namespace RemSox.Processes
{
if (interpreter.IsRunning)
{
interpreter.Step();
_ = interpreter.Step();
}
else
{
@@ -45,4 +44,3 @@ namespace RemSox.Processes
interpreter.Stop();
}
}
}
+2 -1
View File
@@ -1,8 +1,9 @@
using System.Drawing;
using RemSox.Logging;
using RemSox.Processing.IPC;
using RemSox.UI.GUI.Windows;
using System.Drawing;
namespace RemSox.Processing;
public abstract class Process(string name)
+1 -1
View File
@@ -216,7 +216,7 @@ public static class ProcessManager
{
process.Stop();
if (processes.TryRemove(process.Id, out var processEntry))
if (processes.TryRemove(process.Id, out (Process Process, ProcessMetrics Metrics, TaskCompletionSource ExitSource) processEntry))
{
_ = processEntry.ExitSource.TrySetResult();
}
+1 -1
View File
@@ -60,7 +60,7 @@ public static class CommandManager
arguments = trimmedInput[commandName.Length..].TrimStart();
}
cancellationToken.Register(async () => await entry.Value.StopAsync());
CancellationTokenRegistration unused = cancellationToken.Register(async () => await entry.Value.StopAsync());
await entry.Value.ExecuteAsync(arguments, printLine);
return true;
+2 -7
View File
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RemSox.Processing;
namespace RemSox.UI.CLI.Commands
{
namespace RemSox.UI.CLI.Commands;
public class YesNtCommand : ICommand
{
public string Name => "yesnt";
@@ -26,4 +22,3 @@ namespace RemSox.UI.CLI.Commands
return Task.CompletedTask;
}
}
}
+4 -1
View File
@@ -24,5 +24,8 @@ public interface ICommand
/// <summary>
/// Interrupts the command if it's currently running. This is called when the user presses Ctrl+C in the CLI.
/// </summary>
Task StopAsync() => Task.CompletedTask;
Task StopAsync()
{
return Task.CompletedTask;
}
}
+50 -18
View File
@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using RemSox.Processing;
using RemSox.UI.GUI.Windows;
using System.Drawing;
using YesNt.Interpreter.Runtime;
using YesNt.Interpreter.Utilities;
namespace RemSox.Utils
{
namespace RemSox.Utils;
/// <summary>
/// Registers all YesNt statements that expose the WindowManager / UI element API.
///
@@ -34,7 +34,7 @@ namespace RemSox.Utils
public static class YesNtWindowStatements
{
// Maps script-visible integer ids to actual Window objects.
private static readonly Dictionary<int, Window> s_windows = new();
private static readonly Dictionary<int, Window> s_windows = [];
private static int s_nextWindowId = 1;
private static int s_lastWindowId = 0;
@@ -114,7 +114,7 @@ namespace RemSox.Utils
if (int.TryParse(idStr, out int id) && s_windows.TryGetValue(id, out Window? win))
{
WindowManager.CloseWindow(win);
s_windows.Remove(id);
bool unused = s_windows.Remove(id);
}
});
@@ -232,7 +232,9 @@ namespace RemSox.Utils
b.Size = new Size(nums[2], nums[3]);
b.Text = label;
if (color != Color.Empty)
{
b.BackgroundColor = color;
}
});
});
}
@@ -488,14 +490,22 @@ namespace RemSox.Utils
if (input.StartsWith('"'))
{
int end = input.IndexOf('"', 1);
if (end < 0) return false;
if (end < 0)
{
return false;
}
title = input[1..end];
remaining = input[(end + 1)..].Trim();
}
else
{
int space = input.IndexOf(' ');
if (space < 0) return false;
if (space < 0)
{
return false;
}
title = input[..space];
remaining = input[(space + 1)..].Trim();
}
@@ -521,14 +531,23 @@ namespace RemSox.Utils
winId = 0; nums = Array.Empty<int>(); label = string.Empty; color = Color.Empty;
string[] parts = input.Split(' ', numCount + 2, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < numCount + 1) return false;
if (parts.Length < numCount + 1)
{
return false;
}
if (!int.TryParse(parts[0], out winId)) return false;
if (!int.TryParse(parts[0], out winId))
{
return false;
}
nums = new int[numCount];
for (int i = 0; i < numCount; i++)
{
if (!int.TryParse(parts[i + 1], out nums[i])) return false;
if (!int.TryParse(parts[i + 1], out nums[i]))
{
return false;
}
}
string rest = string.Join(" ", parts[(numCount + 1)..]).Trim();
@@ -536,7 +555,11 @@ namespace RemSox.Utils
if (rest.StartsWith('"'))
{
int end = rest.IndexOf('"', 1);
if (end < 0) return false;
if (end < 0)
{
return false;
}
label = rest[1..end];
rest = rest[(end + 1)..].Trim();
}
@@ -573,17 +596,27 @@ namespace RemSox.Utils
winId = 0; x = 0; y = 0; label = string.Empty; isChecked = false;
string[] parts = input.Split(' ', 4, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 4) return false;
if (parts.Length < 4)
{
return false;
}
if (!int.TryParse(parts[0], out winId)
|| !int.TryParse(parts[1], out x)
|| !int.TryParse(parts[2], out y)) return false;
|| !int.TryParse(parts[2], out y))
{
return false;
}
string rest = parts[3].Trim();
if (rest.StartsWith('"'))
{
int end = rest.IndexOf('"', 1);
if (end < 0) return false;
if (end < 0)
{
return false;
}
label = rest[1..end];
rest = rest[(end + 1)..].Trim();
}
@@ -594,8 +627,7 @@ namespace RemSox.Utils
else { label = rest[..sp]; rest = rest[(sp + 1)..].Trim(); }
}
bool.TryParse(rest, out isChecked);
_ = bool.TryParse(rest, out isChecked);
return true;
}
}
}