Exemple #1
0
        /// <summary>
        ///     Load all plugin data async.
        /// </summary>
        /// <remarks></remarks>
        private void LoadAsync()
        {
            try
            {
                if (InstalledPlugins == null)
                {
                    return;
                }

                _pluginLinkDictionary = new Dictionary <InstalledPlugin, BukgetPlugin>();

                for (UInt16 i = 0; i <= InstalledPlugins.Count - 1; i++)
                {
                    InstalledPlugin plugin = InstalledPlugins[i];
                    if (plugin != null && plugin.Name != null)
                    {
                        SetStatus(T.Tr("Loading plugin data:") + plugin.Name + "(" + i + 1 + "/" +
                                  InstalledPlugins.Count + ")");
                        Logger.Log(LogLevel.Info, "PluginUpdater",
                                   "Loading plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count + ")");
                        if (_pluginLinkDictionary.ContainsKey(plugin) == false)
                        {
                            try
                            {
                                _pluginLinkDictionary.Add(plugin, BukgetPlugin.CreateFromNamespace(plugin.Mainspace));
                            }
                            catch (Exception ex)
                            {
                                _pluginLinkDictionary.Add(plugin, null);
                                Logger.Log(LogLevel.Info, "PluginUpdater",
                                           "Skipped plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count +
                                           ")", ex.Message);
                            }
                            Logger.Log(LogLevel.Info, "PluginUpdater",
                                       "Added plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count + ")");
                        }
                        else
                        {
                            Logger.Log(LogLevel.Info, "PluginUpdater",
                                       "Discarded plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count +
                                       ")");
                        }

                        double tmpp = Math.Round((double)(100 * ((i + 1) / InstalledPlugins.Count)));
                        if (tmpp > 100)
                        {
                            tmpp = 100;
                        }
                        SetProgress(Convert.ToByte(tmpp));
                    }
                }
                Logger.Log(LogLevel.Info, "PluginUpdater", "Loaded plugin data (" + InstalledPlugins.Count + ")");
                LoadUi();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Severe, "PluginUpdater", "Severe exception in LoadAsync routine!", ex.Message);
            }
        }
 public PluginUpdater(InstalledPlugin plugin)
 {
     Load += PluginUpdater_Load;
     // This call is required by the designer.
     InitializeComponent();
     InstalledPlugins = new List<InstalledPlugin> {plugin};
     // Add any initialization after the InitializeComponent() call.
 }
        /// <summary>
        ///     Create a plugin list based upon the plugin.yml files, might take a while. Recommended to run async.
        /// </summary>
        /// <remarks></remarks>
        private static void CreateDetailledList()
        {
            Logger.Log(LogLevel.Info, "InstalledPlugins", "Loading full list",
                       "Pluginmanager.InstalledPluginmanager.CreateDetailledList()");
            if (Plugins == null || Plugins.Count == 0)
            {
                RaiseInstalledPluginListLoadedFullList();
                return;
            }
            try
            {
                int i = 0;
                //create dictionary
                Dictionary <string, InstalledPlugin> updatedPlugins = new Dictionary <string, InstalledPlugin>();

                foreach (KeyValuePair <string, InstalledPlugin> pair in Plugins)
                {
                    string          pluginname = pair.Key;
                    InstalledPlugin value      = pair.Value;
                    try
                    {
                        Logger.Log(LogLevel.Info, "InstalledPlugins",
                                   "Loading plugin " + (i + 1) + " of " + Plugins.Count + " : " + pluginname);
                        InstalledPlugin plugin = new InstalledPlugin().ParseAllFields(value.Path);

// ReSharper disable once AssignNullToNotNullAttribute
                        if (plugin != null)
                        {
                            updatedPlugins.Add(plugin.FileName, plugin);
                        }
                        Logger.Log(LogLevel.Info, "InstalledPlugins",
                                   "Loaded plugin " + (i + 1) + " of " + Plugins.Count + " : " + pluginname);
                    }
                    catch (Exception ex)
                    {
                        if (pluginname != null)
                        {
                            Logger.Log(LogLevel.Warning, "InstalledPlugins", "Plugin not loaded:" + pluginname,
                                       ex.Message);
                        }
                        else
                        {
                            Logger.Log(LogLevel.Warning, "InstalledPlugins", "Plugin not loaded: " + i, ex.Message);
                        }
                    }
                    i++;
                }
                Plugins = updatedPlugins;                 // move new dictionary to plugins
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Severe, "InstalledPlugins", "Couldn't create detailled list", ex.Message);
            }
            finally
            {
                RaiseInstalledPluginListLoadedFullList();
            }
        }
Exemple #4
0
 public PluginUpdater(InstalledPlugin plugin)
 {
     Load += PluginUpdater_Load;
     // This call is required by the designer.
     InitializeComponent();
     InstalledPlugins = new List <InstalledPlugin> {
         plugin
     };
     // Add any initialization after the InitializeComponent() call.
 }
 private void btnRemove_Click(object sender, EventArgs e)
 {
     if (slvPlugins.SelectedItems.Count < 0)
     {
         return;
     }
     foreach (ListViewItem item in slvPlugins.SelectedItems)
     {
         InstalledPlugin plugin = (InstalledPlugin)item.Tag;
         if (
             MetroMessageBox.Show(Application.OpenForms[0],
                                  "Are you sure you want to delete this plugin?" + Environment.NewLine + plugin.Name,
                                  "Delete this plugin?",
                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             plugin.Remove();
         }
     }
     slvPlugins_SelectedIndexChanged(null, null);            // force index check to disable buttons if needed
 }
        private void btnVersions_Click(object sender, EventArgs e)
        {
            if (slvPlugins.SelectedItems.Count < 0)
            {
                return;
            }
            string          filename = ((InstalledPlugin)(slvPlugins.SelectedItems[0].Tag)).FileName;
            InstalledPlugin plugin   = InstalledPluginManager.Plugins[filename];

            try
            {
                BukgetPlugin.CreateFromNamespace(plugin.Mainspace).ShowVersionDialog(plugin.Path);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugins", "Couldn't get versions dialog for plugin", ex.Message);
                MetroMessageBox.Show(Application.OpenForms[0],
                                     "Couldn't retrieve plugin data for this plugin. Maybe this plugin or version is not in the database",
                                     "Couldn't retrieve data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #7
0
        private void ShowSelectedPluginsWebpage(object sender, EventArgs e)
        {
            if (slvPlugins.SelectedItems.Count < 0)
            {
                return;
            }
            foreach (ListViewItem item in slvPlugins.SelectedItems)
            {
                string          filename = ((InstalledPlugin)(item.Tag)).FileName;
                InstalledPlugin plugin   = InstalledPluginManager.Plugins[filename];
                try
                {
                    BukgetPlugin.CreateFromNamespace(plugin.Mainspace).OpenBukkitdevPage();
                }

                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Warning, "InstalledPlugins", "Couldn't get website for plugin", ex.Message);
                    MetroMessageBox.Show(Application.OpenForms[0],
                                         "Couldn't retrieve plugin information for " + filename + ". Maybe this plugin or version is not in the database.",
                                         "Couldn't retrieve data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemple #8
0
        /// <summary>
        ///     Update each plugin, if it's checked
        /// </summary>
        /// <remarks></remarks>
        private void Plugins_Update(object sender, EventArgs e)
        {
            try
            {
                if (InvokeRequired)
                {
                    Invoke((MethodInvoker)(() => Plugins_Update(sender, e)));
                }
                else
                {
                    Logger.Log(LogLevel.Info, "PluginUpdater", "Starting plugins update");
                    if (SlvPlugins.CheckedItems.Count < 1)
                    {
                        return;
                    }
                    UInt16 i = 1;
                    foreach (ListViewItem item in SlvPlugins.CheckedItems)
                    {
                        if (item.Tag != null)
                        {
                            InstalledPlugin     plugin  = (InstalledPlugin)item.Tag;
                            BukgetPluginVersion version = _pluginLinkDictionary[plugin].LastVersion;

                            if (version == null)
                            {
                                continue;
                            }


                            SetStatus(T.Tr("Updating plugin") + " " + plugin.Name + " " +
                                      T.Tr("to version") + " " + version.VersionNumber +
                                      " (" + i + "/" + SlvPlugins.CheckedItems.Count + ")");

                            Logger.Log(LogLevel.Info, "PluginUpdater", "Updating plugin:" + plugin.Name);
                            BukgetPluginInstaller.Install(version, plugin.Path, false,
                                                          false);
                        }

                        else
                        {
                            SetStatus(T.Tr("Skipping plugin") + " " + item.SubItems[0].Text + " - " +
                                      T.Tr("cannot update") + "(" + i +
                                      1 + " / " + _pluginLinkDictionary.Count + ")");
                            Logger.Log(LogLevel.Info, "PluginUpdater", "Skipping plugin:" + item.SubItems[0].Text);
                        }
                        double tmpp = Math.Round(100 * ((i + 1) / (double)_pluginLinkDictionary.Count));
                        if (tmpp > 100)
                        {
                            tmpp = 100;
                        }
                        SetProgress(Convert.ToByte(tmpp));
                        i++;
                    }


                    SetStatus(T.Tr("Idle"));

                    if (BtnClose != null && !(Disposing || IsDisposed) && !(BtnClose.Disposing || BtnClose.IsDisposed))
                    {
                        BtnClose.Enabled = true;
                    }

                    InstalledPluginManager.RefreshAllInstalledPluginsAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(T.Tr("Something went wrong while updating. Please check if all plugins are updated."),
                                T.Tr("Something went wrong"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Logger.Log(LogLevel.Warning, "PluginUpdater", "Severe exception in Update routine!", ex.Message);
            }
            CloseThisForm(null, null);
        }
		/// <summary>
		///     Create a plugin list based upon the plugin.yml files, might take a while. Recommended to run async.
		/// </summary>
		/// <remarks></remarks>
		private static void CreateDetailledList()
		{
			Logger.Log(LogLevel.Info, "InstalledPlugins", "Loading full list",
				"Pluginmanager.InstalledPluginmanager.CreateDetailledList()");
			if (Plugins == null || Plugins.Count == 0)
			{
				RaiseInstalledPluginListLoadedFullList();
				return;
			}
			try
			{
				int i = 0;
				//create dictionary
				Dictionary<string, InstalledPlugin> updatedPlugins = new Dictionary<string, InstalledPlugin>();

				foreach (KeyValuePair<string, InstalledPlugin> pair in Plugins)
				{
					string pluginname = pair.Key;
					InstalledPlugin value = pair.Value;
					try
					{
						Logger.Log(LogLevel.Info, "InstalledPlugins",
							"Loading plugin " + (i + 1) + " of " + Plugins.Count + " : " + pluginname);
						InstalledPlugin plugin = new InstalledPlugin().ParseAllFields(value.Path);

// ReSharper disable once AssignNullToNotNullAttribute
						if (plugin != null) updatedPlugins.Add(plugin.FileName, plugin);
						Logger.Log(LogLevel.Info, "InstalledPlugins",
							"Loaded plugin " + (i + 1) + " of " + Plugins.Count + " : " + pluginname);
					}
					catch (Exception ex)
					{
						if (pluginname != null)
							Logger.Log(LogLevel.Warning, "InstalledPlugins", "Plugin not loaded:" + pluginname,
								ex.Message);
						else
							Logger.Log(LogLevel.Warning, "InstalledPlugins", "Plugin not loaded: " + i, ex.Message);
					}
					i++;
				}
				Plugins = updatedPlugins; // move new dictionary to plugins
			}
			catch (Exception ex)
			{
				Logger.Log(LogLevel.Severe, "InstalledPlugins", "Couldn't create detailled list", ex.Message);
			}
			finally
			{
				RaiseInstalledPluginListLoadedFullList();
			}
		}