From 3c0d1f9d6ab656a3418072ed84a6d30ba27d5d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 12 Nov 2024 08:59:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=204?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/AppByPlugins/AppByPlugins.csproj | 6 -- COP/AppByPlugins/FormMain.cs | 79 ++++++++----------- .../Components/UserCheckedListBox.cs | 7 +- 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/COP/AppByPlugins/AppByPlugins.csproj b/COP/AppByPlugins/AppByPlugins.csproj index 0e3581b..0a0fe71 100644 --- a/COP/AppByPlugins/AppByPlugins.csproj +++ b/COP/AppByPlugins/AppByPlugins.csproj @@ -23,10 +23,4 @@ - - - $(SolutionDir)Plugins\System.IO.Packaging.dll - - - \ No newline at end of file diff --git a/COP/AppByPlugins/FormMain.cs b/COP/AppByPlugins/FormMain.cs index 098b013..d54c977 100644 --- a/COP/AppByPlugins/FormMain.cs +++ b/COP/AppByPlugins/FormMain.cs @@ -20,58 +20,43 @@ namespace AppByPlugins public FormMain() { InitializeComponent(); - _plugins = new(); - LoadPlugins(); + _plugins = LoadPlugins(); _selectedPlugin = string.Empty; } - private void LoadPlugins() - { - List pluginsList = GetPlugins(); + private Dictionary LoadPlugins() + { + var plugins = new Dictionary(); - foreach (var plugin in pluginsList) - { - _plugins[plugin.PluginName] = plugin; - CreateMenuItem(plugin.PluginName); - } - } + string pluginsDir = Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName + "\\Plugins"; - private List GetPlugins() - { - string currentDir = Environment.CurrentDirectory; - string pluginsDir = Directory.GetParent(currentDir).Parent.Parent.Parent.FullName + "\\Plugins"; - string[] dllFiles = Directory.GetFiles( - pluginsDir, - "*.dll", - SearchOption.AllDirectories - ); - List plugins = new(); - foreach (string dllFile in dllFiles) - { - try - { - Assembly assembly = Assembly.LoadFrom(dllFile); - Type[] types = assembly.GetTypes(); - foreach (Type type in types) - { - if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) - { - if (Activator.CreateInstance(type) is IPluginsConvention plugin) - { - plugins.Add(plugin); - } - } - } - } - catch (Exception ex) - { - MessageBox.Show( - ex.Message - ); - } - } - return plugins; - } + string[] dllFiles = Directory.GetFiles(pluginsDir, "*.dll", SearchOption.AllDirectories); + + foreach (string dllFile in dllFiles) + { + try + { + Assembly assembly = Assembly.LoadFrom(dllFile); + Type[] types = assembly.GetTypes(); + + foreach (var type in types) + { + if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) + { + var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; + plugins.Add(plugin.PluginName, plugin); + CreateMenuItem(plugin.PluginName); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка при загрузке сборки {dllFile}: {ex.Message}"); + } + } + + return plugins; + } private void CreateMenuItem(string pluginName) { diff --git a/COP/Components/Components/UserCheckedListBox.cs b/COP/Components/Components/UserCheckedListBox.cs index 0440a8c..4662e60 100644 --- a/COP/Components/Components/UserCheckedListBox.cs +++ b/COP/Components/Components/UserCheckedListBox.cs @@ -25,7 +25,11 @@ namespace Components.Components } set { - if (value != null && checkedListBox.Items.Contains(value)) checkedListBox.SelectedItem = value; + if (value != null && checkedListBox.Items.Contains(value)) + { + checkedListBox.SelectedItem = value; + checkedListBox.SetItemChecked(checkedListBox.SelectedIndex, true); + } } } @@ -53,6 +57,7 @@ namespace Components.Components if (index != checkedListBox.SelectedIndex) { checkedListBox.SetItemChecked(index, false); + checkedListBox.SetItemChecked(checkedListBox.SelectedIndex, false); } } }