Ejemplo n.º 1
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Filter = "Musix Plugins|*.MusixPlugin"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                PackedPlugin pl = PackedPlugin.LoadFrom(File.OpenRead(ofd.FileName));
                Console.WriteLine($"Name: {pl.PluginName}");
                Console.WriteLine($"Author: {pl.AuthorName}");
                Console.WriteLine($"Desc: {pl.PluginDescription}");
                Console.WriteLine($"Desc: {string.Join(", ", pl.PluginTags)}");
                Console.WriteLine($"Website: {pl.WebsiteURL}");
                Console.WriteLine($"Plats: {pl.PlatformCompatability.Platforms.Count}");
                pl.PlatformCompatability.Platforms.ForEach(x => Console.WriteLine($"Plat: {x.PlatformName} [{x.MinVersion}]"));
                pl.LoadDependancies();
            }

            Application.Run(new Packer());
        }
Ejemplo n.º 2
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            Instance = this;
            DateTime Started     = DateTime.Now;
            FileInfo AppBaseInfo = new FileInfo(Application.ExecutablePath);

            Environment.CurrentDirectory = AppBaseInfo.DirectoryName;
            ConfigManager.Init();
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            CheckFolders();
            FormClosing += MainWindow_FormClosing;

            DateTime PStarted = DateTime.Now;

            foreach (string PluginFile in Directory.GetFiles("Plugins", "*.dll"))
            {
                FileInfo info = new FileInfo(PluginFile);
                try
                {
                    string SName = info.Name.Substring(0, info.Name.Length - info.Extension.Length);
                    Console.WriteLine($">{SName}");
                    Console.WriteLine($"Loading plugin {SName}...");
                    List <string> Deps = new List <string>();
                    if (Directory.Exists(Path.Combine("Plugins", SName)))
                    {
                        foreach (string Dependancy in Directory.GetFiles(Path.Combine("Plugins", SName), "*.dll"))
                        {
                            Console.WriteLine($">{Dependancy}");
                            Deps.Add(Dependancy);
                        }
                    }
                    Console.WriteLine($"Discovered {Deps.Count} dependancies");
                    Console.WriteLine($"Loading {Deps.Count} dependancies for plugin {info.Name}...");
                    foreach (string asm in Deps)
                    {
                        Assembly asmb = Assembly.LoadFrom(asm);
                        if (!PluginDependancies.ContainsKey(asmb.FullName))
                        {
                            PluginDependancies.Add(asmb.FullName, asmb);
                            AppDomain.CurrentDomain.Load(File.ReadAllBytes(asm));
                        }
                    }
                    Console.WriteLine($"Loaded {Deps.Count} for plugin {SName}");
                    Assembly Plugin = Assembly.LoadFrom(PluginFile);
                    foreach (Type t in Plugin.GetTypes())
                    {
                        if (typeof(IMusixPlugin).IsAssignableFrom(t))
                        {
                            Console.WriteLine($"Initializing plugin {info.Name}...");
                            IMusixPlugin entryPoint = ((IMusixPlugin)Activator.CreateInstance(t));
                            entryPoint.Load();
                            Plugins.Add(entryPoint.Name, entryPoint);
                            Console.WriteLine($"Initialized plugin {entryPoint.Name}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to load plugin {info.Name}; {ex.Message}");
                    Console.WriteLine(ex.Message);
                    throw;
                }
            }
            Console.WriteLine("[PluginLoader] loading packed plugins");

            foreach (string PackedPluginFile in Directory.GetFiles("Plugins", "*.mxpl").Concat(Directory.GetFiles("Plugins", "*.musixplugin")))
            {
                PackedPlugin plugin = PackedPlugin.LoadFrom(File.OpenRead(PackedPluginFile));
                Console.WriteLine($"Loading packed plugin: {plugin.PluginName} by {plugin.AuthorName}");
                foreach (Assembly LoadedDep in plugin.LoadDependancies())
                {
                    if (!PluginDependancies.ContainsKey(LoadedDep.FullName))
                    {
                        PluginDependancies.Add(LoadedDep.FullName, LoadedDep);
                    }
                }
                Assembly[] Deps = plugin.LoadDependancies();
                Console.WriteLine($"Loaded {Deps.Length} dependencies for plugin {plugin.PluginName}");

                Assembly Plugin = plugin.LoadPlugin();

                foreach (Type t in Plugin.GetTypes())
                {
                    if (typeof(IMusixPlugin).IsAssignableFrom(t))
                    {
                        Console.WriteLine($"Initializing plugin {plugin.PluginName}...");
                        IMusixPlugin entryPoint = ((IMusixPlugin)Activator.CreateInstance(t));
                        entryPoint.Load();
                        Plugins.Add(entryPoint.Name, entryPoint);
                        Console.WriteLine($"Initialized plugin {entryPoint.Name}");
                    }
                }
            }

            Console.WriteLine($"[Plugins Loaded] took {Math.Round(DateTime.Now.Subtract(PStarted).TotalMilliseconds),2} millisecond/s.");

            Client = new MusixClient("955b354ccd0e4270b6ad97f8b4003d9a", "5a008b85c33b499da7857fbdf05f08ef", "ImageCache", "AudioCache");
            Client.OnClientReady += Client_OnClientReady;
            Client.StartClient();

            AcceptButton = new Button();

            Activated  += MainWindow_Activated;
            Deactivate += MainWindow_Deactivate;
            ((Button)AcceptButton).Click += BtnAccept_Click;

            MenuItems.Add(typeof(SearchMenuItem), new SearchMenuItem());
            MenuItems.Add(typeof(DownloadsMenuItem), new DownloadsMenuItem());
            MenuItems.Add(typeof(SettingsMenuItem), new SettingsMenuItem());
            MDSSideBar.AddItem(MenuItems[typeof(SearchMenuItem)]);
            MDSSideBar.AddItem(MenuItems[typeof(DownloadsMenuItem)]);
            MDSSideBar.AddItem(MenuItems[typeof(SettingsMenuItem)]);

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type t in asm.GetTypes().Where(x => typeof(IMusixMenuItem).IsAssignableFrom(x) && !x.IsInterface))
                {
                    if (!MenuItems.ContainsKey(t))
                    {
                        IMusixMenuItem newItem = (IMusixMenuItem)Activator.CreateInstance(t);
                        MDSSideBar.AddItem(newItem);
                        MenuItems.Add(t, newItem);
                    }
                }
            }

            foreach (var item in MenuItems)
            {
                if (Attribute.GetCustomAttribute(item.Value.GetType(), typeof(AutoInitialize)) != null)
                {
                    Control ct = item.Value.GetMenuControl();
                    ct.Visible = false;
                    ct.Dock    = DockStyle.Fill;
                    if (!PNContent.Controls.Contains(ct))
                    {
                        PNContent.Controls.Add(ct);
                    }
                }
            }

            MDSSideBar.OnSelectionChanged += MDSSideBar_OnSelectionChanged;

            MDSSideBar.SelectItemAtIndex(0);
            SendStyle(EStyle.Blue);

            DateTime Finished = DateTime.Now;

            Console.WriteLine($"[Initialized] took {Math.Round(Finished.Subtract(Started).TotalMilliseconds),3} millisecond/s.");
        }