private void SaveRegistry(FsRegistry registry) { var xe = MapToXElement(registry); // save to disk lock (RegistryLock) { xe.Save(RegistryFile, SaveOptions.None); } }
private static XElement MapToXElement(FsRegistry registry) { var xe = new XElement("plugins"); foreach (var registryItem in registry) { xe.Add(MapToXElement(registryItem)); } return(xe); }
/// <summary> /// Synchronize the underlying registry (on the file system) with the manifests /// </summary> /// <param name="pluginManifests">A list of all the manifests installed on the system</param> public override void Initialize(List <PluginManifest> pluginManifests) { Directory.CreateDirectory(RegistrarDirectory); // load existing registry var previousRegistry = GetRegistry(); // sync manifests with existing registry foreach (var pm in pluginManifests) { var ri = previousRegistry.FirstOrDefault(m => m.PluginId.Equals(pm.PluginId, StringComparison.OrdinalIgnoreCase)); if (ri != null) { pm.RegistrationInfo.IsActivated = ri.IsActivated; pm.RegistrationInfo.ActivatedOn = ri.ActivatedOn; pm.RegistrationInfo.InstalledOn = ri.InstalledOn; } } // update registry (this will also get rid of any plugin references that were manually removed or otherwise deleted) var registry = new FsRegistry(pluginManifests.Select(m => MapToFsRegistryItem(m))); SaveRegistry(registry); // load and update plugin registry settings foreach (var manifest in pluginManifests) { manifest.RegistrationInfo.PluginSettings = manifest.PluginDefaultSettings; // merge saved settings with the plugin settings var settings = GetRegistryItemSettings(manifest.PluginId); foreach (var setting in settings) { manifest.RegistrationInfo.PluginSettings[setting.Key] = setting.Value; } SaveRegistryItemSettings(manifest.PluginId, manifest.RegistrationInfo.PluginSettings); } }