internal void Merge(ConfigFileManager configFileManager) { if (configFileManager != null && configFileManager._values != null) { for (int i = 0; i < configFileManager._values.Count; i++) { string key = configFileManager._values.GetKey(i); string settingValue = configFileManager._values[i]; SetValue(key, settingValue); } } }
static AddonsConfig() { IsInitialConfig = false; filePath = string.Format(@"{0}{1}{2}.Addons.config", ApplicationInfo.SettingsFolder, PathUtils.DirectorySeparator, ApplicationInfo.ApplicationName); //SettingsForm.InitAddonCfg += // new SettingsForm.InitAddonCfgHandler(SettingsForm_InitAddonCfg); try { ConfigFileManager config = new ConfigFileManager(filePath); UninstallMarkedItems(config); _navAddons = ReadAddonConfig(config, "NavigationAddons"); _previewAddons = ReadAddonConfig(config, "PreviewAddons"); _propAddons = ReadAddonConfig(config, "PropertyAddons"); } catch (Exception ex) { ErrorDispatcher.DispatchError(ex); } }
private static void UninstallMarkedItems(ConfigFileManager config) { string[] names = null; string namesRaw = config.GetValue("MarkedForUninstall"); if (!string.IsNullOrEmpty(namesRaw)) { names = namesRaw.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string name in names) { try { UninstallAddonLibrary(name); } catch(Exception ex) { //ErrorDispatcher.DispatchError(ex); Logger.LogException(ex); } } config.DeleteValue("MarkedForUninstall"); config.Save(); } }
internal static void MarkForUninstall(string assembly) { ConfigFileManager config = new ConfigFileManager(filePath); string markedForUninstall = config.GetValue("MarkedForUninstall", string.Empty); List<string> filesToDelete = new List<string>(); IEnumerable<string> files = Directory.EnumerateFiles(Application.StartupPath, string.Format("{0}*", assembly)); if (files != null) { foreach (string asmFile in files) { Assembly asm = Assembly.LoadFrom(asmFile); if (asm != null) { filesToDelete.Add(asmFile); foreach (CultureInfo ci in AppConfig.SupportedCultures) { try { Assembly satAsm = asm.GetSatelliteAssembly(ci); if (satAsm != null) { string path = satAsm.Location.ToLowerInvariant(); if (!filesToDelete.Contains(path)) { filesToDelete.Add(path.ToLowerInvariant()); } } } catch (Exception ex) { Logger.LogException(ex); } } foreach (string file in filesToDelete) { markedForUninstall += file; markedForUninstall += "|"; } } } } config.SetValue("MarkedForUninstall", markedForUninstall); config.Save(); }
private static string[] ReadAddonConfig(ConfigFileManager config, string keyBase) { string[] names = null; string namesRaw = config.GetValue(keyBase); if (!string.IsNullOrEmpty(namesRaw)) { names = namesRaw.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string name in names) { _assemblies.Add(name, config.GetValue(name)); } } return names; }
private void ScheduleForUninstall(string assembly) { string addons = string.Empty; List<AddonInfo> itemsToDisable = new List<AddonInfo>(); foreach (AddonInfo ai in addonList.AllAddons) { string[] codebaseParts = ai.CodeBase.Split(new char[]{'|'}); if (codebaseParts.Length > 0 && codebaseParts[0].ToLowerInvariant() == assembly.ToLowerInvariant()) { addons += ai.TranslatedName; addons += "\n"; itemsToDisable.Add(ai); } } if (itemsToDisable.Count < 1) return; if (itemsToDisable.Count == 1 || (MessageDisplay.Query(Translator.Translate("TXT_SHAREDADDONS", addons), Translator.Translate("TXT_CAUTION"), MessageBoxIcon.Question) == DialogResult.Yes)) { // Clear for uninstalling. ConfigFileManager cfgFile = new ConfigFileManager(AddonsConfig.AddonsConfigFile); foreach (AddonInfo ai in itemsToDisable) { cfgFile.DeleteValue(ai.Name); addonList.RemoveAddon(ai); } cfgFile.Save(); AddonsConfig.MarkForUninstall(assembly); _uninstallScheduled = true; } }
private void SaveGroup(ConfigFileManager cfgFile, List<AddonInfo> addonList, string groupName) { string addons = string.Empty; foreach (AddonInfo ai in addonList) { if (ai.Selected || ai.IsRequired) { addons += ai.Name; addons += "|"; cfgFile.SetValue(ai.Name, ai.CodeBase); } } if (addons.Length > 0) { cfgFile.SetValue(groupName, addons.TrimEnd(new char[] { '|' })); } else { cfgFile.SetValue(groupName, string.Empty); } }
protected override void SaveInternal() { if (GetEnabledAddonCount(addonList.NavigationAddons) > 0) { if (!IsConfigurationChanged()) { //Nothing changed, therefore nothing is to be saved. return; } if (AddonsConfig.IsInitialConfig || MessageDisplay.Query(Translator.Translate("TXT_ADDONS_CHANGED_RESTART"), Translator.Translate("TXT_APP_RESTART"), MessageBoxIcon.Question) == DialogResult.Yes) { ConfigFileManager cfgFile = new ConfigFileManager(AddonsConfig.AddonsConfigFile); SaveGroup(cfgFile, addonList.NavigationAddons, "NavigationAddons"); SaveGroup(cfgFile, addonList.PropertyAddons, "PropertyAddons"); SaveGroup(cfgFile, addonList.PreviewAddons, "PreviewAddons"); cfgFile.Save(); if (!AddonsConfig.IsInitialConfig) { Logger.LogInfo("Updated addons configuration was saved. Requesting to reload."); SettingsForm.RequestRestart(); //AddonDetector.FireReloadAddons(); } } else if (!AddonsConfig.IsInitialConfig) { MessageDisplay.Show(Translator.Translate("TXT_ADDONS_NOT_CHANGED"), "Info", MessageBoxIcon.Information); } } else { throw new SettingsSaveException("You must enable at least one navigation addon !"); } }