diff options
| author | Michael VanOverbeek <[email protected]> | 2017-06-11 11:57:31 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-06-11 11:57:31 +0000 |
| commit | 997a81457ebb6d6523c36ca552cee143e0d92244 (patch) | |
| tree | da98985ced112b6d238811f3ca770014d67e34fc /ShiftOS_TheReturn/TerminalBackend.cs | |
| parent | 0d75f701778a0900a58343c4c80c124279bc231f (diff) | |
| parent | 107a98686a105468b5f200ebcbd27343c1210ce4 (diff) | |
| download | shiftos_thereturn-997a81457ebb6d6523c36ca552cee143e0d92244.tar.gz shiftos_thereturn-997a81457ebb6d6523c36ca552cee143e0d92244.tar.bz2 shiftos_thereturn-997a81457ebb6d6523c36ca552cee143e0d92244.zip | |
Merge pull request #129 from RogueAI42/master
ReflectMan Saves The Day..............
Diffstat (limited to 'ShiftOS_TheReturn/TerminalBackend.cs')
| -rw-r--r-- | ShiftOS_TheReturn/TerminalBackend.cs | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 09ef3d6..81ea971 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -295,54 +295,40 @@ namespace ShiftOS.Engine public static void PopulateTerminalCommands() { Commands = new List<TerminalCommand>(); - foreach(var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + foreach(var type in ReflectMan.Types) { - if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + var ns = type.GetCustomAttributes(false).FirstOrDefault(x => x is Namespace) as Namespace; + if(ns != null) { - try + foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { - var asm = Assembly.LoadFile(exec); - foreach(var type in asm.GetTypes()) + var cmd = mth.GetCustomAttributes(false).FirstOrDefault(x => x is Command); + if(cmd != null) { - var ns = type.GetCustomAttributes(false).FirstOrDefault(x => x is Namespace) as Namespace; - if(ns != null) + var tc = new TerminalCommand(); + tc.RequiresElevation = !(type.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); + + tc.NamespaceInfo = ns; + + tc.CommandInfo = cmd as Command; + tc.RequiresElevation = tc.RequiresElevation || !(mth.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); + tc.RequiredArguments = new List<string>(); + foreach (var arg in mth.GetCustomAttributes(false).Where(x=>x is RequiresArgument)) { - foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - var cmd = mth.GetCustomAttributes(false).FirstOrDefault(x => x is Command); - if(cmd != null) - { - var tc = new TerminalCommand(); - tc.RequiresElevation = !(type.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); - - tc.NamespaceInfo = ns; - - tc.CommandInfo = cmd as Command; - tc.RequiresElevation = tc.RequiresElevation || !(mth.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); - tc.RequiredArguments = new List<string>(); - foreach (var arg in mth.GetCustomAttributes(false).Where(x=>x is RequiresArgument)) - { - var rarg = arg as RequiresArgument; - tc.RequiredArguments.Add(rarg.argument); - } - var rupg = mth.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute; - if (rupg != null) - tc.Dependencies = rupg.Upgrade; - else - tc.Dependencies = ""; - tc.CommandType = type; - tc.CommandHandler = mth; - if (!Commands.Contains(tc)) - Commands.Add(tc); - } - } + var rarg = arg as RequiresArgument; + tc.RequiredArguments.Add(rarg.argument); } + var rupg = mth.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute; + if (rupg != null) + tc.Dependencies = rupg.Upgrade; + else + tc.Dependencies = ""; + tc.CommandType = type; + tc.CommandHandler = mth; + if (!Commands.Contains(tc)) + Commands.Add(tc); } } - catch(Exception e) - { - Console.WriteLine("[termdb] Error: " + e.ToString()); - } } } Console.WriteLine("[termdb] " + Commands.Count + " commands found."); |
