aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/Commands.cs
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-11 17:34:38 +1000
committerRogueAI42 <[email protected]>2017-06-11 17:38:53 +1000
commit107a98686a105468b5f200ebcbd27343c1210ce4 (patch)
treef6b8403368ddf0b4be2569c0ac8c237635e7b764 /ShiftOS_TheReturn/Commands.cs
parentc3deaa23fffb7011efb2b5b0f7fc3e754d21f600 (diff)
downloadshiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.gz
shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.bz2
shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.zip
ReflectMan Saves The Day..............
Refactored every part in the code that used that damn foreach loop. All assemblies are now loaded on startup into an array, and the results of GetType() on each are concatenated into another array. The parts of the code that were loading the assemblies and scanning them themselves now look to ReflectMan.Types, and all disk I/O is limited to the first time ReflectMan is accessed. While I was there I also replaced some other foreach loops with array comprehensions and such to speed things up - there is a noticeable improvement. It doesn't seem to have broken anything, but I'd appreciate if someone could do more stress testing for me.
Diffstat (limited to 'ShiftOS_TheReturn/Commands.cs')
-rw-r--r--ShiftOS_TheReturn/Commands.cs89
1 files changed, 23 insertions, 66 deletions
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs
index f37bcb3..da4fb29 100644
--- a/ShiftOS_TheReturn/Commands.cs
+++ b/ShiftOS_TheReturn/Commands.cs
@@ -771,84 +771,41 @@ shiftorium.buy{{upgrade:""{upg.ID}""}}");
{
var app = args["app"] as string;
//ANNND now we start reflecting...
- foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
+ foreach (var type in Array.FindAll(ReflectMan.Types, t => t.BaseType == typeof(UserControl)))
{
- if (asmExec.EndsWith(".exe") || asmExec.EndsWith(".dll"))
+ var attr = type.GetCustomAttributes(false).FirstOrDefault(a => a is WinOpenAttribute && app == (a as WinOpenAttribute).ID);
+ if (attr != null)
{
- var asm = Assembly.LoadFile(asmExec);
- try
+ if (SaveSystem.CurrentSave.Upgrades.ContainsKey(app))
{
- foreach (var type in asm.GetTypes())
+ if (Shiftorium.UpgradeInstalled(app))
{
- if (type.BaseType == typeof(UserControl))
- {
- foreach (var attr in type.GetCustomAttributes(false))
- {
- if (attr is WinOpenAttribute)
- {
- if (app == (attr as WinOpenAttribute).ID)
- {
- if (SaveSystem.CurrentSave.Upgrades.ContainsKey(app))
- {
- if (Shiftorium.UpgradeInstalled(app))
- {
- IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow;
- AppearanceManager.SetupWindow(frm);
- return true;
- }
- else
- {
- throw new Exception($"{app} was not found on your system! Try looking in the shiftorium...");
- }
- }
- else
- {
- IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow;
- AppearanceManager.SetupWindow(frm);
- return true;
- }
- }
- }
- }
- }
+ IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow;
+ AppearanceManager.SetupWindow(frm);
+ return true;
+ }
+ else
+ {
+ throw new Exception($"{app} was not found on your system! Try looking in the shiftorium...");
}
}
- catch { }
-
+ else
+ {
+ IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow;
+ AppearanceManager.SetupWindow(frm);
+ return true;
+ }
}
}
}
else
{
- foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
- {
- if (asmExec.EndsWith(".exe") || asmExec.EndsWith(".dll"))
- {
- try
- {
- var asm = Assembly.LoadFile(asmExec);
-
- foreach (var type in asm.GetTypes())
- {
- if (type.GetInterfaces().Contains(typeof(IShiftOSWindow)))
- {
- foreach (var attr in type.GetCustomAttributes(false))
- {
- if (attr is WinOpenAttribute)
- {
- if (Shiftorium.UpgradeAttributesUnlocked(type))
- {
- Console.WriteLine("win.open{app:\"" + (attr as WinOpenAttribute).ID + "\"}");
- }
- }
- }
- }
- }
- }
- catch { }
- }
- }
+
+ foreach (var type in Array.FindAll(ReflectMan.Types, t => t.GetInterfaces().Contains(typeof(IShiftOSWindow)) && Shiftorium.UpgradeAttributesUnlocked(t)))
+ foreach (var attr in Array.FindAll(type.GetCustomAttributes(false), a => a is WinOpenAttribute))
+ if (Shiftorium.UpgradeAttributesUnlocked(type))
+ Console.WriteLine("win.open{app:\"" + (attr as WinOpenAttribute).ID + "\"}");
return true;