コード例 #1
0
        public void ParseOfflinePluginVersioning(PluginVersioning onlineVersion)
        {
            foreach (var plugin in onlineVersion.Plugins)
            {
                var offlinePlugin = new PluginDatastore();

                var strPluginNamesRaw = plugin.DownloadPath.Split('/');
                var strPluginName = strPluginNamesRaw[strPluginNamesRaw.Length - 1];

                offlinePlugin.DownloadPath = Path.Combine(Application.StartupPath, "Plugins", strPluginName);
                if (File.Exists(offlinePlugin.DownloadPath))
                {
                    offlinePlugin.Name = Path.GetFileNameWithoutExtension(offlinePlugin.DownloadPath);

                    if (offlinePlugin.DownloadPath.EndsWith(".lang"))
                    {
                        using (var sr = new StreamReader(offlinePlugin.DownloadPath))
                        {
                            var strVersionLine = sr.ReadLine();

                            if (strVersionLine != null)
                                offlinePlugin.Version = strVersionLine.Substring(1);
                        }
                    }

                    else
                    {
                        offlinePlugin.Version = FileVersionInfo.GetVersionInfo(offlinePlugin.DownloadPath).FileVersion;
                    }

                    offlinePlugin.Hash = Hashes.HashFromFile(offlinePlugin.DownloadPath, Hashes.HashAlgorithm.Md5);
                    Plugins.Add(offlinePlugin);
                }
            }
        }
コード例 #2
0
        public void ParseOfflinePluginVersioning(PluginVersioning onlineVersion)
        {
            foreach (var plugin in onlineVersion.Plugins)
            {
                var offlinePlugin = new PluginDatastore();

                var strPluginNamesRaw = plugin.DownloadPath.Split('/');
                var strPluginName     = strPluginNamesRaw[strPluginNamesRaw.Length - 1];

                offlinePlugin.DownloadPath = Path.Combine(Application.StartupPath, "Plugins", strPluginName);
                if (File.Exists(offlinePlugin.DownloadPath))
                {
                    offlinePlugin.Name = Path.GetFileNameWithoutExtension(offlinePlugin.DownloadPath);

                    if (offlinePlugin.DownloadPath.EndsWith(".lang"))
                    {
                        using (var sr = new StreamReader(offlinePlugin.DownloadPath))
                        {
                            var strVersionLine = sr.ReadLine();

                            if (strVersionLine != null)
                            {
                                offlinePlugin.Version = strVersionLine.Substring(1);
                            }
                        }
                    }

                    else
                    {
                        offlinePlugin.Version = FileVersionInfo.GetVersionInfo(offlinePlugin.DownloadPath).FileVersion;
                    }

                    offlinePlugin.Hash = Hashes.HashFromFile(offlinePlugin.DownloadPath, Hashes.HashAlgorithm.Md5);
                    Plugins.Add(offlinePlugin);
                }
            }
        }
コード例 #3
0
        private void PluginsLocalLoadPlugins()
        {
            if (!Directory.Exists(Constants.StrPluginFolder))
                Directory.CreateDirectory(Constants.StrPluginFolder);

            _lPluginContainer.Clear();
            _lPlugins.Clear();
            _lPluginDatastores.Clear();

            var files = Directory.GetFiles(Constants.StrPluginFolder, "*.dll");

            for (var i = 0; i < files.Length; i++)
            {
                var tmpAppDomain = AppDomain.CreateDomain(files[i].Substring(files[i].LastIndexOf("\\", StringComparison.Ordinal)));

                try
                {
                    var foo =
                        (IPlugins)
                            tmpAppDomain.CreateInstanceFromAndUnwrap(files[i], "Plugin.Extensions.AnotherSc2HackPlugin");

                    if (_lPlugins.Exists(x => x.Plugin.GetPluginName() == foo.GetPluginName()))
                       throw new TypeLoadException("Plugin Load Error"); //:D

                    _lPlugins.Add(new LocalPlugins(foo, files[i]));
                    _lPluginContainer.Add(tmpAppDomain);
                }

                catch (TypeLoadException)
                {
                    //If we are here, we couldn't load illegal .dll- files
                    //It's all good here!
                    AppDomain.Unload(tmpAppDomain);
                }

                catch (Exception)
                {
                    MessageBox.Show("Couldn't load plugin '" + files[i] + "'");
                }
            }

            var languageFiles = Directory.GetFiles(Constants.StrPluginFolder, "*.lang");

            foreach (var languageFile in languageFiles)
            {
                var plugin = new PluginDatastore();
                plugin.Name = Path.GetFileNameWithoutExtension(languageFile);

                using (var sr = new StreamReader(languageFile))
                {
                    var strVersion = sr.ReadLine();

                    if (strVersion != null && strVersion.Length > 2)
                        plugin.Version = strVersion.Substring(1);

                    else
                        plugin.Version = "0.0.0.0";
                }

                plugin.Hash = Hashes.HashFromFile(languageFile, Hashes.HashAlgorithm.Md5);
                plugin.DownloadPath = languageFile;

                _lPluginDatastores.Add(plugin);
            }
            InitializeLanguageFiles();

            PluginsLocalLoadedPluginsRefresh();

            //Launch Plugins
            foreach (var plugin in _lPlugins)
            {
                plugin.Plugin.StartPlugin();
            }

            //Mark Plugins "checked"
            foreach (ListViewItem item in lstvPluginsLoadedPlugins.Items)
            {
                item.Checked = true;
            }

            //Init the clickable panels for the plugins (if needed)
            foreach (var localPlugins in _lPlugins)
            {
                if (localPlugins.Plugin.GetPluginEntryName() != null && localPlugins.Plugin.GetPluginEntryName().Length > 0)
                {
                    //Remove plugin from cliclable container
                    var clickControls = pnlLeftSelection.Controls.Find(localPlugins.Hash, false);
                    var clickPanels = pnlMainArea.Controls.Find(localPlugins.Hash, false);

                    foreach (var clickControl in clickControls)
                    {
                        pnlLeftSelection.Controls.Remove(clickControl);
                    }

                    foreach (var clickPanel in clickPanels)
                    {
                        pnlMainArea.Controls.Remove(clickPanel);
                    }

                    var cntrls = pnlLeftSelection.Controls;
                    var iHeight = cpnlApplication.Height;

                    foreach (var cntrl in cntrls)
                    {
                        var cont = cntrl as ClickablePanel;

                        if (cont != null)
                            iHeight += cont.Height;
                    }

                    #region Create Panel

                    var panel = new Panel();

                    panel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
                    panel.Location = new System.Drawing.Point(0, 80);
                    panel.Name = localPlugins.Hash;
                    panel.Size = new System.Drawing.Size(1029, 450);
                    panel.TabIndex = 0;

                    pnlMainArea.Controls.Add(panel);

                    #endregion

                    #region Clickable Panel

                    var click = new ClickablePanel();
                    click.Parent = pnlLeftSelection;

                    click.ActiveBackgroundColor = Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(63)))), ((int)(((byte)(72)))));
                    click.ActiveBorderPosition = ActiveBorderPosition.Left;
                    click.ActiveForegroundColor = Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(242)))));
                    click.BackColor = Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(79)))), ((int)(((byte)(90)))));
                    click.DisplayColor = Color.FromArgb(((int)(((byte)(193)))), ((int)(((byte)(193)))), ((int)(((byte)(193)))));
                    click.DisplayText = localPlugins.Plugin.GetPluginEntryName();
                    click.Font = new Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    click.HoverBackgroundColor = Color.FromArgb(((int)(((byte)(94)))), ((int)(((byte)(105)))), ((int)(((byte)(114)))));
                    click.InactiveBackgroundColor = Color.FromArgb(((int)(((byte)(66)))), ((int)(((byte)(79)))), ((int)(((byte)(90)))));
                    click.InactiveForegroundColor = Color.FromArgb(((int)(((byte)(193)))), ((int)(((byte)(193)))), ((int)(((byte)(193)))));
                    click.IsClicked = false;
                    click.IsHovering = false;
                    click.Location = new Point(0, iHeight);
                    click.Name = localPlugins.Hash;
                    click.Size = new Size(152, 40);

                    click.Icon = HelpFunctions.ByteArrayToImage(localPlugins.Plugin.GetPluginIcon()) ?? Properties.Resources.icon_default_plugin;

                    click.TabIndex = 0;
                    click.TextSize = 11F;
                    click.SettingsPanel = panel;

                    click.Click += cpnl_Click;

                    #endregion

                }
            }
        }