mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Code cleanup
This commit is contained in:
@@ -5,10 +5,10 @@ using Org.BouncyCastle.Crypto.Parameters;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace RemSox.Cryptography
|
||||
namespace RemSox.Cryptography;
|
||||
|
||||
public static class AesGcmCrypto
|
||||
{
|
||||
public static class AesGcmCrypto
|
||||
{
|
||||
private const int NonceSize = 12;
|
||||
private const int TagSize = 128;
|
||||
|
||||
@@ -66,5 +66,4 @@ namespace RemSox.Cryptography
|
||||
byte[] plain = Decrypt(data, key);
|
||||
return Encoding.UTF8.GetString(plain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ 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
|
||||
{
|
||||
public static class Pkcs5S2PasswordKeyDeriver
|
||||
{
|
||||
private const int KeySize = 32; // 256-bit key
|
||||
private const int Iterations = 150_000; // PBKDF2 cost factor
|
||||
|
||||
@@ -23,5 +23,4 @@ namespace RemSox.Cryptography
|
||||
return ((KeyParameter)generator.GenerateDerivedMacParameters(KeySize * 8))
|
||||
.GetKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -44,5 +43,4 @@ namespace RemSox.Processes
|
||||
{
|
||||
interpreter.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
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 class YesNtCommand : ICommand
|
||||
{
|
||||
public string Name => "yesnt";
|
||||
|
||||
public string Description => "Start the YesNt interpreter";
|
||||
@@ -25,5 +21,4 @@ namespace RemSox.UI.CLI.Commands
|
||||
ProcessManager.StopProcess(processId);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
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.
|
||||
///
|
||||
/// Window management:
|
||||
/// win_create "My Window" 320 240 creates a window, read back id with %win_last_id
|
||||
/// win_close ${myWinId} closes/destroys a window by id
|
||||
/// win_flush ${myWinId} forces a redraw of the window
|
||||
/// win_title ${myWinId} "New Title" changes the window title
|
||||
/// win_autoflush ${myWinId} true enables/disables auto-flush
|
||||
/// win_invalidate_all invalidates and redraws every window
|
||||
///
|
||||
/// UI element creation (read back id with %ui_last_id after each call):
|
||||
/// ui_button ${myWinId} 20 30 100 30 "Click Me"
|
||||
/// ui_checkbox ${myWinId} 20 80 "Check Me" true
|
||||
/// ui_label ${myWinId} 20 10 "Hello World"
|
||||
/// ui_textbox ${myWinId} 20 50 160 24 "placeholder"
|
||||
/// ui_line ${myWinId} 20 130 180 130 255 0 0 (x1 y1 x2 y2 R G B)
|
||||
/// ui_rect ${myWinId} 20 20 100 60 0 128 255 (x y w h R G B)
|
||||
///
|
||||
/// Inline substitutions (use inside any line, like %read_line):
|
||||
/// %win_last_id expands to the id of the last created window
|
||||
/// %ui_last_id expands to the id of the last created UI element
|
||||
/// </summary>
|
||||
public static class YesNtWindowStatements
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers all YesNt statements that expose the WindowManager / UI element API.
|
||||
///
|
||||
/// Window management:
|
||||
/// win_create "My Window" 320 240 creates a window, read back id with %win_last_id
|
||||
/// win_close ${myWinId} closes/destroys a window by id
|
||||
/// win_flush ${myWinId} forces a redraw of the window
|
||||
/// win_title ${myWinId} "New Title" changes the window title
|
||||
/// win_autoflush ${myWinId} true enables/disables auto-flush
|
||||
/// win_invalidate_all invalidates and redraws every window
|
||||
///
|
||||
/// UI element creation (read back id with %ui_last_id after each call):
|
||||
/// ui_button ${myWinId} 20 30 100 30 "Click Me"
|
||||
/// ui_checkbox ${myWinId} 20 80 "Check Me" true
|
||||
/// ui_label ${myWinId} 20 10 "Hello World"
|
||||
/// ui_textbox ${myWinId} 20 50 160 24 "placeholder"
|
||||
/// ui_line ${myWinId} 20 130 180 130 255 0 0 (x1 y1 x2 y2 R G B)
|
||||
/// ui_rect ${myWinId} 20 20 100 60 0 128 255 (x y w h R G B)
|
||||
///
|
||||
/// Inline substitutions (use inside any line, like %read_line):
|
||||
/// %win_last_id expands to the id of the last created window
|
||||
/// %ui_last_id expands to the id of the last created UI element
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user