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); } } }