diff options
| author | Michael <[email protected]> | 2017-02-07 17:30:14 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-07 17:30:14 -0500 |
| commit | 7a29121456747651bd27d75833e28d5f7d479a1e (patch) | |
| tree | d606abe06064c29b9796a9f958a3f953ec4e2c31 /ShiftOS_TheReturn | |
| parent | aa45e10f4a023ba681f04bde72872c7e8a7aa122 (diff) | |
| download | shiftos_thereturn-7a29121456747651bd27d75833e28d5f7d479a1e.tar.gz shiftos_thereturn-7a29121456747651bd27d75833e28d5f7d479a1e.tar.bz2 shiftos_thereturn-7a29121456747651bd27d75833e28d5f7d479a1e.zip | |
Added defaulticonattribute.
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/Skinning.cs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index d155688..4cf3834 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -33,6 +33,7 @@ using Newtonsoft.Json; using System.Windows.Forms; using static ShiftOS.Engine.SaveSystem; using ShiftOS.Objects.ShiftFS; +using System.Reflection; namespace ShiftOS.Engine { public static class SkinEngine { @@ -113,13 +114,51 @@ namespace ShiftOS.Engine { Utils.WriteAllText(Paths.GetPath("skin.json"), JsonConvert.SerializeObject(LoadedSkin, Formatting.Indented)); } + private static IIconProber _iconProber = null; + + public static Image GetDefaultIcon(string id) + { + if (_iconProber == null) + { + return new Bitmap(16, 16); + } + else + { + foreach(var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + { + if(f.EndsWith(".exe") || f.EndsWith(".dll")) + { + try + { + var asm = Assembly.LoadFile(f); + foreach(var type in asm.GetTypes()) + { + if(type.Name == id) + { + foreach(var attr in type.GetCustomAttributes(true)) + { + if(attr is DefaultIconAttribute) + { + return _iconProber.GetIcon(attr as DefaultIconAttribute); + } + } + } + } + } + catch { } + } + } + return new Bitmap(16, 16); + } + } + public static Image GetIcon(string id) { if (!LoadedSkin.AppIcons.ContainsKey(id)) LoadedSkin.AppIcons.Add(id, null); if (LoadedSkin.AppIcons[id] == null) - return new Bitmap(16, 16); + return GetDefaultIcon(id); else { using (var sr = new MemoryStream(LoadedSkin.AppIcons[id])) @@ -131,6 +170,21 @@ namespace ShiftOS.Engine { } } + public interface IIconProber + { + Image GetIcon(DefaultIconAttribute attr); + } + + public class DefaultIconAttribute : Attribute + { + public DefaultIconAttribute(string id) + { + ID = id; + } + + public string ID { get; private set; } + } + public class Skin { //borrowing from the discourse theme for the default skin private static readonly Color DefaultBackground = Color.FromArgb(0, 0x44, 0x00); |
