programs are treated as commands

This commit is contained in:
Michael 2017-06-16 21:10:13 -04:00
parent 79fe2101ae
commit 764cdc940f
2 changed files with 39 additions and 5 deletions

View file

@ -248,11 +248,11 @@ namespace ShiftOS.Engine
var sb = new StringBuilder();
sb.AppendLine("Retrieving help data.");
//print all unique namespaces.
foreach (var n in TerminalBackend.Commands.Select(x => x.CommandInfo).Distinct().OrderBy(x=>x.name))
foreach (var n in TerminalBackend.Commands.Where(x=>!(x is TerminalBackend.WinOpenCommand) && Shiftorium.UpgradeInstalled(x.Dependencies) && x.CommandInfo.hide == false).OrderBy(x=>x.CommandInfo.name))
{
sb.Append(n.name);
sb.Append(n.CommandInfo.name);
if (Shiftorium.UpgradeInstalled("help_descriptions"))
sb.Append(" - " + n.description);
sb.Append(" - " + n.CommandInfo.description);
sb.AppendLine();
}
@ -411,7 +411,7 @@ shiftorium.buy{{upgrade:""{upg.ID}""}}");
return true;
}
[Command("shiftorium", description ="Lists all available Shiftorium upgrades.")]
[Command("upgrades", description ="Lists all available Shiftorium upgrades.")]
public static bool ListAll(Dictionary<string, object> args)
{
try

View file

@ -180,7 +180,7 @@ namespace ShiftOS.Engine
public bool RequiresElevation { get; set; }
public void Invoke(Dictionary<string, object> args)
public virtual void Invoke(Dictionary<string, object> args)
{
List<string> errors = new List<string>();
bool requiresAuth = false;
@ -237,6 +237,19 @@ namespace ShiftOS.Engine
}
}
public class WinOpenCommand : TerminalCommand
{
public Type ShiftOSWindow { get; set; }
public override void Invoke(Dictionary<string, object> args)
{
AppearanceManager.SetupWindow((IShiftOSWindow)Activator.CreateInstance(ShiftOSWindow, null));
}
}
public class MemoryTextWriter : System.IO.TextWriter
{
public override Encoding Encoding
@ -294,6 +307,27 @@ namespace ShiftOS.Engine
Commands = new List<TerminalCommand>();
foreach (var type in ReflectMan.Types)
{
if (type.GetInterfaces().Contains(typeof(IShiftOSWindow)))
{
var winopenattrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is WinOpenAttribute) as WinOpenAttribute;
if(winopenattrib != null)
{
var winc = new WinOpenCommand();
winc.CommandType = type;
var rupg = type.GetCustomAttributes().FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute;
if (rupg != null)
winc.Dependencies = rupg.Upgrade;
winc.CommandInfo = new Engine.Command(winopenattrib.ID, "", "Opens the \"" + winopenattrib.ID + " program.");
winc.RequiredArguments = new List<string>();
winc.RequiresElevation = false;
winc.ShiftOSWindow = type;
var ambiguity = Commands.FirstOrDefault(x => x.CommandInfo.name == winc.CommandInfo.name);
if (ambiguity != null)
throw new Exception("Ambiguity error. The program " + winc.CommandInfo.name + " collides with another program or terminal command with the same name. Please either change the already-existing program/command, or change this one's WinOpenAttribute value to compensate.");
Commands.Add(winc);
}
}
foreach (var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
{
var cmd = mth.GetCustomAttributes(false).FirstOrDefault(x => x is Command);