// Загрузка функций private void LoadFunctions() { try { var functionsKey = Registry.CurrentUser.OpenSubKey("ModPlus\\Functions"); if (functionsKey == null) { return; } using (functionsKey) { foreach (var functionKeyName in functionsKey.GetSubKeyNames()) { var functionKey = functionsKey.OpenSubKey(functionKeyName); var prForValue = functionKey?.GetValue("ProductFor"); if (prForValue != null && prForValue.Equals("Renga")) { // беру свойства функции из реестра var file = functionKey.GetValue("File") as string; var onOff = functionKey.GetValue("OnOff") as string; if (string.IsNullOrEmpty(onOff)) { continue; } var isOn = !bool.TryParse(onOff, out var b) || b; // default - true // Если "Продукт для" подходит, файл существует и функция включена - гружу if (isOn) { if (!string.IsNullOrEmpty(file) && File.Exists(file)) { // load var localFuncAssembly = Assembly.LoadFrom(file); LoadFunctionsHelper.GetDataFromFunctionInterface(localFuncAssembly, file); } else { var foundedFile = LoadFunctionsHelper.FindFile(functionKeyName); if (!string.IsNullOrEmpty(foundedFile) && File.Exists(foundedFile)) { var localFuncAssembly = Assembly.LoadFrom(foundedFile); LoadFunctionsHelper.GetDataFromFunctionInterface(localFuncAssembly, foundedFile); } } } } } } } catch (Exception exception) { RengaApplication.UI.ShowMessageBox(Renga.MessageIcon.MessageIcon_Error, "ModPlus", exception.Message); } }
private static void LoadFunctions(Editor ed) { try { var functionsKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("ModPlus\\Functions"); if (functionsKey == null) { return; } using (functionsKey) { foreach (var functionKeyName in functionsKey.GetSubKeyNames()) { var functionKey = functionsKey.OpenSubKey(functionKeyName); if (functionKey == null) { continue; } foreach (var availPrVersKeyName in functionKey.GetSubKeyNames()) { // Если версия продукта не совпадает, то пропускаю if (!availPrVersKeyName.Equals(VersionData.CurrentCadVersion)) { continue; } var availProductVersionKey = functionKey.OpenSubKey(availPrVersKeyName); if (availProductVersionKey == null) { continue; } // беру свойства функции из реестра var file = availProductVersionKey.GetValue("File") as string; var onOff = availProductVersionKey.GetValue("OnOff") as string; var productFor = availProductVersionKey.GetValue("ProductFor") as string; if (string.IsNullOrEmpty(onOff) || string.IsNullOrEmpty(productFor)) { continue; } if (!productFor.Equals("AutoCAD")) { continue; } var isOn = !bool.TryParse(onOff, out var b) || b; // default - true // Если "Продукт для" подходит, файл существует и функция включена - гружу if (isOn) { if (!string.IsNullOrEmpty(file) && File.Exists(file)) { // load if (!_quiteLoad) { ed.WriteMessage($"\n* {Language.GetItem(LangItem, "p15")} {functionKeyName}"); } var localFuncAssembly = Assembly.LoadFrom(file); LoadFunctionsHelper.GetDataFromFunctionInterface(localFuncAssembly); } else { var foundedFile = LoadFunctionsHelper.FindFile(functionKeyName); if (!string.IsNullOrEmpty(foundedFile) && File.Exists(foundedFile)) { if (!_quiteLoad) { ed.WriteMessage($"\n* {Language.GetItem(LangItem, "p15")} {functionKeyName}"); } var localFuncAssembly = Assembly.LoadFrom(foundedFile); LoadFunctionsHelper.GetDataFromFunctionInterface(localFuncAssembly); } } } } } } } catch (System.Exception exception) { ExceptionBox.Show(exception); } }