diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index a8f5693..b2f064d 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -53,7 +53,6 @@ namespace ShiftOS.WinForms SkinEngine.SetIconProber(new ShiftOSIconProvider()); ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); Localization.RegisterProvider(new WFLanguageProvider()); - Shiftorium.RegisterProvider(new WinformsShiftoriumProvider()); AppearanceManager.OnExit += () => { Environment.Exit(0); @@ -95,6 +94,7 @@ namespace ShiftOS.WinForms } } + [ShiftoriumProvider] internal class WinformsShiftoriumProvider : IShiftoriumProvider { public List GetDefaults() diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 82b7000..d689cad 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -41,8 +41,7 @@ namespace ShiftOS.Engine private static WaveOut _out = null; private static AudioFileReader _reader = null; private static IAudioProvider _provider = null; - private static bool _running = true; - + /// /// Stops the current sound if one is playing and disposes of the sound. /// diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index 007877c..2637f1b 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -280,6 +280,7 @@ namespace ShiftOS.Engine private static IShiftoriumProvider _provider = null; + [Obsolete("Please annotate your provider with a [ShiftoriumProvider] attribute instead. This function doesn't do anything.")] public static void RegisterProvider(IShiftoriumProvider p) { _provider = p; @@ -289,18 +290,6 @@ namespace ShiftOS.Engine public static List GetDefaults() { List list = new List(); - try - { - list = _provider.GetDefaults(); - } - catch (Exception ex) - { - Console.WriteLine("Couldn't get the upgrade definition list from the provider."); - Console.WriteLine("This might be able to help:"); - Console.WriteLine(ex); - list = JsonConvert.DeserializeObject>(Properties.Resources.Shiftorium); - } - //Now we probe for ShiftoriumUpgradeAttributes for mods. foreach(var file in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) { @@ -311,10 +300,20 @@ namespace ShiftOS.Engine var asm = Assembly.LoadFile(file); foreach (var type in asm.GetTypes()) { + if (type.GetInterfaces().Contains(typeof(IShiftoriumProvider))) + { + if(type.GetCustomAttributes().FirstOrDefault(x=> x is ShiftoriumProviderAttribute) != null) + { + var _p = Activator.CreateInstance(type, null) as IShiftoriumProvider; + list.AddRange(_p.GetDefaults()); + } + } + + ShiftoriumUpgradeAttribute attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; if (attrib != null) { - if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null) + if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) throw new ShiftoriumConflictException(attrib.Upgrade); list.Add(new ShiftoriumUpgrade { @@ -332,7 +331,7 @@ namespace ShiftOS.Engine attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; if (attrib != null) { - if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null) + if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) throw new ShiftoriumConflictException(attrib.Upgrade); list.Add(new ShiftoriumUpgrade { @@ -352,7 +351,7 @@ namespace ShiftOS.Engine attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; if (attrib != null) { - if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null) + if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) throw new ShiftoriumConflictException(attrib.Upgrade); list.Add(new ShiftoriumUpgrade { @@ -372,7 +371,7 @@ namespace ShiftOS.Engine attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; if (attrib != null) { - if (list.FirstOrDefault(x => x.Id == attrib.Upgrade) != null) + if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) throw new ShiftoriumConflictException(attrib.Upgrade); list.Add(new ShiftoriumUpgrade { @@ -392,6 +391,14 @@ namespace ShiftOS.Engine catch { } } } + + + + foreach(var item in list) + { + if (list.Where(x => x.ID == item.ID).Count() > 1) + throw new ShiftoriumConflictException(item.Id); + } return list; } } @@ -460,4 +467,9 @@ namespace ShiftOS.Engine } } + + public class ShiftoriumProviderAttribute : Attribute + { + + } }