diff --git a/SrcMod/Shell/Modules/ObjectModels/CanCancelAttribute.cs b/SrcMod/Shell/Modules/ObjectModels/CanCancelAttribute.cs new file mode 100644 index 0000000..30f2451 --- /dev/null +++ b/SrcMod/Shell/Modules/ObjectModels/CanCancelAttribute.cs @@ -0,0 +1,12 @@ +namespace SrcMod.Shell.Modules.ObjectModels; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +public class CanCancelAttribute : Attribute +{ + public readonly bool CanCancel; + + public CanCancelAttribute(bool canCancel) + { + CanCancel = canCancel; + } +} diff --git a/SrcMod/Shell/Modules/ObjectModels/CommandInfo.cs b/SrcMod/Shell/Modules/ObjectModels/CommandInfo.cs index 8505f35..0e71e6f 100644 --- a/SrcMod/Shell/Modules/ObjectModels/CommandInfo.cs +++ b/SrcMod/Shell/Modules/ObjectModels/CommandInfo.cs @@ -2,6 +2,7 @@ public class CommandInfo { + public bool CanBeCancelled { get; private set; } public required ModuleInfo Module { get; init; } public required MethodInfo Method { get; init; } public string Name { get; private set; } @@ -11,6 +12,7 @@ public class CommandInfo private CommandInfo() { + CanBeCancelled = false; Name = string.Empty; NameId = string.Empty; Parameters = Array.Empty(); @@ -34,10 +36,13 @@ public class CommandInfo CommandAttribute[] attributes = info.GetCustomAttributes().ToArray(); if (attributes.Length <= 0) return Array.Empty(); + CanCancelAttribute? cancel = info.GetCustomAttribute(); + foreach (CommandAttribute attribute in attributes) { commands.Add(new() { + CanBeCancelled = cancel is null || cancel.CanCancel, Method = info, Module = parentModule, Name = info.Name, diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index 4cb5190..a2b7cda 100644 --- a/SrcMod/Shell/Shell.cs +++ b/SrcMod/Shell/Shell.cs @@ -241,7 +241,7 @@ public class Shell activeCommand.DoWork += runCommand; activeCommand.RunWorkerAsync(); - activeCommand.WorkerSupportsCancellation = true; + activeCommand.WorkerSupportsCancellation = command.CanBeCancelled; while (activeCommand is not null && activeCommand.IsBusy) Thread.Yield();