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);
         }
     }
 }
Example #2
0
        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);
            }
        }
Example #3
0
        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();
            }
        }
Example #4
0
        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();
        }
Example #5
0
        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;
        }
Example #6
0
        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;
            }

            
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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 !");
            }
        }
 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);
         }
     }
 }