Exemplo n.º 1
0
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("This will permanently delete all selected plugins, are you sure you want to continue?",
                "Delete plugins", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                return;

            var refs = PluginLoader.CheckReferences(_listView.SelectedObjects, _listView.Objects.Except(_listView.SelectedObjects).ToList()).ToList();
            if (refs.Any())
            {
                if (MessageBox.Show("The following depend on the plugin(s) that you are about to delete and will most likely stop working:\n" +
                    string.Join("\n", refs.Select(x => x.Name).OrderBy(x => x)) + "\n\nDo you want to continue anyways?",
                    "Delete plugins", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
                    return;
            }

            foreach (var plug in _listView.SelectedObjects.ToList())
            {
                try
                {
                    plug.Location.Delete();
                    objectListView1.RemoveObject(plug);
                }
                catch (SystemException ex)
                {
                    Console.WriteLine(ex);
                    MessageBox.Show("Failed to remove plugin " + plug.Name + "\n\n" + ex.Message, "Delete plugins", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Need to do this since multiple mods can be in a single dll
            ReloadList();
        }
Exemplo n.º 2
0
        private void SetPluginsEnabled(IList<PluginInfo> plugins, bool enabled)
        {
            if (!enabled)
            {
                var filtered = PluginLoader.CheckReferences(_listView.SelectedObjects, _listView.Objects.Except(_listView.SelectedObjects).ToList()).ToList();
                if (filtered.Any())
                {
                    if (MessageBox.Show("The following depend on the plugin(s) that you are about to disable and will most likely stop working:\n\n" +
                                        string.Join("\n", filtered.Select(x => x.Name).OrderBy(x => x)) + "\n\nDo you want to continue?",
                            "Disable plugins", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
                        return;
                }
            }

            foreach (var plug in plugins)
            {
                try
                {
                    plug.SetEnabled(enabled);
                }
                catch (SystemException ex)
                {
                    Console.WriteLine(ex);
                    MessageBox.Show("Failed to toggle active state of " + plug.Name + "\n\n" + ex.Message, "Enable/Disable plugins", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Need to do this since multiple mods can be in a single dll
            RefreshView();
        }