Skip to content

Commit

Permalink
add - Added full nullable support (pt. 2)
Browse files Browse the repository at this point in the history
---

We've added full nullable support to the entire Nitrocid API, fixing some bugs in the process. This needs some tweaks to ensure that the kernel works properly and that the tests pass.

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 6, 2024
1 parent f857bbe commit 4ba2eff
Show file tree
Hide file tree
Showing 134 changed files with 573 additions and 314 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
changes!
-->
<NitrocidModAPIVersionMajor>3.0.26</NitrocidModAPIVersionMajor>
<NitrocidModAPIVersionChangeset>49</NitrocidModAPIVersionChangeset>
<NitrocidModAPIVersionChangeset>50</NitrocidModAPIVersionChangeset>

<!-- The above two properties are to be installed to the file version -->
<NitrocidModAPIVersion>$(NitrocidModAPIVersionMajor).$(NitrocidModAPIVersionChangeset)</NitrocidModAPIVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void TestRemoveFromPathLookupNonNeutralizedWithRootPath()
public void TestFileExistsInPath()
{
string Path = KernelPlatform.IsOnWindows() ? "netstat.exe" : "bash";
string NeutralizedPath = "";
string? NeutralizedPath = "";
PathLookupTools.FileExistsInPath(Path, ref NeutralizedPath).ShouldBeTrue();
NeutralizedPath.ShouldNotBeNullOrEmpty();
}
Expand Down
6 changes: 3 additions & 3 deletions private/Nitrocid.Tests/Kernel/Events/KernelEventsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void TestClearEvents()
public void TestEventHandler()
{
bool acknowledged = false;
var acknowledge = new Action<object[]>((_) => acknowledged = true);
var acknowledge = new Action<object?[]?>((_) => acknowledged = true);
EventsManager.RegisterEventHandler(EventType.ShellInitialized, acknowledge);
EventsManager.FireEvent(EventType.ShellInitialized);
EventsManager.UnregisterEventHandler(EventType.ShellInitialized, acknowledge);
Expand All @@ -91,9 +91,9 @@ public void TestEventHandler()
public void TestEventHandlerParameterized()
{
bool acknowledged = false;
var acknowledge = new Action<object[]>((parameters) =>
var acknowledge = new Action<object?[]?>((parameters) =>
{
if (parameters.Contains("Hello"))
if (parameters is not null && parameters.Contains("Hello"))
acknowledged = true;
});
EventsManager.RegisterEventHandler(EventType.ShellInitialized, acknowledge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.Amusements.Settings
Expand All @@ -33,7 +35,8 @@ public class AmusementsConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// What is the minimum number to choose?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.Amusements.Settings
Expand All @@ -33,7 +35,8 @@ public class AmusementsSaversConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSaverSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSaverSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

#region Snaker
private bool snakerTrueColor = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Misc.Text;

Expand All @@ -34,7 +36,8 @@ public class AmusementsSplashesConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSplashSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("AmusementsSplashSettings.json", ResourcesType.Misc, typeof(AmusementsConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// [Quote] The progress text location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -34,7 +36,8 @@ public class ArchiveConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("ArchiveSettings.json", ResourcesType.Misc, typeof(ArchiveConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("ArchiveSettings.json", ResourcesType.Misc, typeof(ArchiveConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// Prompt Preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.BassBoom.Settings
Expand All @@ -34,7 +36,8 @@ public class BassBoomConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("BassBoomSettings.json", ResourcesType.Misc, typeof(BassBoomConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("BassBoomSettings.json", ResourcesType.Misc, typeof(BassBoomConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// Path to the lyrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.BassBoom.Settings
Expand All @@ -33,7 +35,8 @@ public class BassBoomSaversConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("BassBoomSaverSettings.json", ResourcesType.Misc, typeof(BassBoomConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("BassBoomSaverSettings.json", ResourcesType.Misc, typeof(BassBoomConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

#region Lyrics
private int lyricsDelay = 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.Calendar.Settings
Expand All @@ -33,7 +35,8 @@ public class CalendarConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("CalendarSettings.json", ResourcesType.Misc, typeof(CalendarConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("CalendarSettings.json", ResourcesType.Misc, typeof(CalendarConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// If enabled, deletes all events and/or reminders before saving all of them using the calendar command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.Forecast.Settings
Expand All @@ -34,7 +36,8 @@ public class ForecastConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("ForecastSettings.json", ResourcesType.Misc, typeof(ForecastConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("ForecastSettings.json", ResourcesType.Misc, typeof(ForecastConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// Select your preferred unit for temperature (this only applies to the "weather" command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;
using Nitrocid.Shell.ShellBase.Shells;

Expand All @@ -34,7 +36,9 @@ class DetachCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
((FTPShell)ShellManager.ShellStack[^1].ShellBase).detaching = true;
var shell = (FTPShell?)ShellManager.ShellStack[^1].ShellBase ??
throw new KernelException(KernelExceptionType.FTPShell, Translate.DoTranslation("The last shell is not this shell to detach from."));
shell.detaching = true;
ShellManager.KillShell();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -36,7 +38,8 @@ public class FtpConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("FtpSettings.json", ResourcesType.Misc, typeof(FtpConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("FtpSettings.json", ResourcesType.Misc, typeof(FtpConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// FTP Prompt Preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -34,7 +36,8 @@ public class GitConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("GitSettings.json", ResourcesType.Misc, typeof(GitConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("GitSettings.json", ResourcesType.Misc, typeof(GitConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// Prompt Preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;
using Nitrocid.Shell.ShellBase.Shells;

Expand All @@ -34,7 +36,9 @@ class DetachCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
((HTTPShell)ShellManager.ShellStack[^1].ShellBase).detaching = true;
var shell = (HTTPShell?)ShellManager.ShellStack[^1].ShellBase ??
throw new KernelException(KernelExceptionType.HTTPShell, Translate.DoTranslation("The last shell is not this shell to detach from."));
shell.detaching = true;
ShellManager.KillShell();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -34,7 +36,8 @@ public class HttpConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("HttpSettings.json", ResourcesType.Misc, typeof(HttpConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("HttpSettings.json", ResourcesType.Misc, typeof(HttpConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Nitrocid.Shell.ShellBase.Commands;
using System.Text;
using Terminaux.Images;
using Terminaux.Inputs.Styles.Editor;
using Textify.General;

namespace Nitrocid.Extras.Images.Commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -35,7 +37,8 @@ public class JsonConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("JsonSettings.json", ResourcesType.Misc, typeof(JsonConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("JsonSettings.json", ResourcesType.Misc, typeof(JsonConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

/// <summary>
/// Prompt Preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;
using Nitrocid.Shell.ShellBase.Shells;

Expand All @@ -34,7 +36,9 @@ class DetachCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
((MailShell)ShellManager.ShellStack[^1].ShellBase).detaching = true;
var shell = (MailShell?)ShellManager.ShellStack[^1].ShellBase ??
throw new KernelException(KernelExceptionType.Mail, Translate.DoTranslation("The last shell is not this shell to detach from."));
shell.detaching = true;
ShellManager.KillShell();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public override void InitializeShell(params object[] ShellArgs)
{
// Parse shell arguments
NetworkConnection connection = (NetworkConnection)ShellArgs[0];
ImapClient imapLink = (ImapClient)((object[])connection.ConnectionInstance)[0];
SmtpClient smtpLink = (SmtpClient)((object[])connection.ConnectionInstance)[1];
ImapClient imapLink = ((ImapClient)((object[]?)MailShellCommon.Client?.ConnectionInstance ?? [])[0]);
SmtpClient smtpLink = ((SmtpClient)((object[]?)MailShellCommon.Client?.ConnectionInstance ?? [])[1]);
MailShellCommon.Client = connection;

// Send ping to keep the connection alive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;
using Nitrocid.Shell.Prompts;

Expand All @@ -36,7 +38,8 @@ public class MailConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("MailSettings.json", ResourcesType.Misc, typeof(MailConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("MailSettings.json", ResourcesType.Misc, typeof(MailConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Nitrocid.Kernel.Configuration;
using Nitrocid.Kernel.Configuration.Instances;
using Nitrocid.Kernel.Configuration.Settings;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Misc.Reflection.Internal;

namespace Nitrocid.Extras.NameGen.Settings
Expand All @@ -33,7 +35,8 @@ public class NameGenSaversConfig : BaseKernelConfig, IKernelConfig
/// <inheritdoc/>
[JsonIgnore]
public override SettingsEntry[] SettingsEntries =>
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("NameGenSaverSettings.json", ResourcesType.Misc, typeof(NameGenSaversConfig).Assembly));
ConfigTools.GetSettingsEntries(ResourcesManager.GetData("NameGenSaverSettings.json", ResourcesType.Misc, typeof(NameGenSaversConfig).Assembly) ??
throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries.")));

#region PersonLookup
private int personLookupDelay = 75;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Nitrocid.Files.Editors.TextEdit;
using Textify.General;
using System.Linq;
using Terminaux.Inputs.Styles.Editor;

namespace Nitrocid.Extras.Notes.Interactive
{
Expand Down
Loading

0 comments on commit 4ba2eff

Please sign in to comment.