/// <summary> /// Apply registry changes to the projects manifest. /// </summary> /// <param name="manifestModifier">Object that modifies the project's manifest.</param> /// <param name="availableRegistries">Registries that are available in the /// configuration.</param> /// <param name="manifestRegistries">Registries that are present in the manifest.</param> /// <param name="selectedRegistryUrls">URLs of selected registries, these should be items in /// availableRegistries.</param> /// <param name="addRegistries">Whether to add selected registries to the manifest.</param> /// <param name="removeRegistries">Whether to remove unselected registries from the /// manifest.</param> /// <param name="invertSelection">If false, adds the selected registries and removes the /// unselected registries. If true, removes the selected registries and adds the unselected /// registries.</param> /// <param name="addedRegistries">If specified, is extended with the list of registries added /// to the manifest.<param> /// <returns>true if successful, false otherwise.</returns> private static bool SyncRegistriesToManifest( PackageManifestModifier manifestModifier, Dictionary <string, PackageManagerRegistry> availableRegistries, Dictionary <string, List <PackageManagerRegistry> > manifestRegistries, HashSet <string> selectedRegistryUrls, bool addRegistries = true, bool removeRegistries = true, bool invertSelection = false, List <PackageManagerRegistry> addedRegistries = null) { List <PackageManagerRegistry> registriesToAdd; List <PackageManagerRegistry> registriesToRemove; bool manifestModified = SyncRegistriesToModifier( manifestModifier, out registriesToAdd, out registriesToRemove, availableRegistries, manifestRegistries, selectedRegistryUrls, addRegistries, removeRegistries, invertSelection); bool successful = true; if (manifestModified) { successful = manifestModifier.WriteManifest(); if (successful) { if (registriesToAdd.Count > 0) { logger.Log(String.Format( "Added registries to {0}:\n{1}", PackageManifestModifier.MANIFEST_FILE_PATH, PackageManagerRegistry.ToString(registriesToAdd))); if (addedRegistries != null) { addedRegistries.AddRange(registriesToAdd); } } if (registriesToRemove.Count > 0) { logger.Log(String.Format( "Removed registries from {0}:\n{1}", PackageManifestModifier.MANIFEST_FILE_PATH, PackageManagerRegistry.ToString(registriesToRemove))); } analytics.Report( "registry_manifest/write/success", new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("added", registriesToAdd.Count.ToString()), new KeyValuePair <string, string>("removed", registriesToRemove.Count.ToString()) }, "Project Manifest Modified"); } else { analytics.Report("registry_manifest/write/failed", "Project Manifest Write Failed"); } } return(successful); }
/// <summary> /// Apply registry changes to the projects manifest. /// </summary> /// <param name="manifestModifier">Object that modifies the project's manifest.</param> /// <param name="availableRegistries">Registries that are available in the /// configuration.</param> /// <param name="manifestRegistries">Registries that are present in the manifest.</param> /// <param name="selectedRegistryUrls">URLs of selected registries, these should be items in /// availableRegistries.</param> /// <param name="addRegistries">Whether to add selected registries to the manifest.</param> /// <param name="removeRegistries">Whether to remove unselected registries from the /// manifest.</param> /// <param name="invertSelection">If false, adds the selected registries and removes the /// unselected registries. If true, removes the selected registries and adds the unselected /// registries.</param> /// <returns>true if successful, false otherwise.</returns> private static bool SyncRegistriesToManifest( PackageManifestModifier manifestModifier, Dictionary <string, UnityPackageManagerRegistry> availableRegistries, Dictionary <string, List <UnityPackageManagerRegistry> > manifestRegistries, HashSet <string> selectedRegistryUrls, bool addRegistries = true, bool removeRegistries = true, bool invertSelection = false) { // Build a list of registries to add to and remove from the manifest. var registriesToAdd = new List <UnityPackageManagerRegistry>(); var registriesToRemove = new List <UnityPackageManagerRegistry>(); foreach (var availableRegistry in availableRegistries.Values) { var url = availableRegistry.Url; bool isSelected = selectedRegistryUrls.Contains(url); if (invertSelection) { isSelected = !isSelected; } bool currentlyInManifest = manifestRegistries.ContainsKey(url); if (isSelected) { if (addRegistries && !currentlyInManifest) { registriesToAdd.Add(availableRegistry); } } else { if (removeRegistries && currentlyInManifest) { registriesToRemove.Add(availableRegistry); } } } bool manifestModified = false; if (registriesToAdd.Count > 0) { manifestModifier.AddRegistries(registriesToAdd); manifestModified = true; } if (registriesToRemove.Count > 0) { manifestModifier.RemoveRegistries(registriesToRemove); manifestModified = true; } bool successful = true; if (manifestModified) { successful = manifestModifier.WriteManifest(); if (successful) { if (registriesToAdd.Count > 0) { logger.Log(String.Format( "Added registries to {0}:\n{1}", PackageManifestModifier.MANIFEST_FILE_PATH, UnityPackageManagerRegistry.ToString(registriesToAdd))); } if (registriesToRemove.Count > 0) { logger.Log(String.Format( "Removed registries from {0}:\n{1}", PackageManifestModifier.MANIFEST_FILE_PATH, UnityPackageManagerRegistry.ToString(registriesToRemove))); } analytics.Report( "registry_manifest/write/success", new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("added", registriesToAdd.Count.ToString()), new KeyValuePair <string, string>("removed", registriesToRemove.Count.ToString()) }, "Project Manifest Modified"); } else { analytics.Report("registry_manifest/write/failed", "Project Manifest Write Failed"); } } return(successful); }