/// <summary>Get update keys based on the available mod metadata, while maintaining the precedence order.</summary> /// <param name="specifiedKeys">The specified update keys.</param> /// <param name="record">The mod's entry in SMAPI's internal database.</param> /// <param name="entry">The mod's entry in the wiki list.</param> private IEnumerable <UpdateKey> GetUpdateKeys(string[] specifiedKeys, ModDataRecord record, WikiModEntry entry) { IEnumerable <string> GetRaw() { // specified update keys if (specifiedKeys != null) { foreach (string key in specifiedKeys) { yield return(key?.Trim()); } } // default update key string defaultKey = record?.GetDefaultUpdateKey(); if (defaultKey != null) { yield return(defaultKey); } // wiki metadata if (entry != null) { if (entry.NexusID.HasValue) { yield return($"{ModRepositoryKey.Nexus}:{entry.NexusID}"); } if (entry.ModDropID.HasValue) { yield return($"{ModRepositoryKey.ModDrop}:{entry.ModDropID}"); } if (entry.CurseForgeID.HasValue) { yield return($"{ModRepositoryKey.CurseForge}:{entry.CurseForgeID}"); } if (entry.ChucklefishID.HasValue) { yield return($"{ModRepositoryKey.Chucklefish}:{entry.ChucklefishID}"); } } } HashSet <UpdateKey> seen = new HashSet <UpdateKey>(); foreach (string rawKey in GetRaw()) { if (string.IsNullOrWhiteSpace(rawKey)) { continue; } UpdateKey key = UpdateKey.Parse(rawKey); if (seen.Add(key)) { yield return(key); } } }
/// <summary>Get every available update key based on the available mod metadata, including duplicates and keys which should be filtered.</summary> /// <param name="specifiedKeys">The specified update keys.</param> /// <param name="record">The mod's entry in SMAPI's internal database.</param> /// <param name="entry">The mod's entry in the wiki list.</param> private IEnumerable <string> GetUnfilteredUpdateKeys(string[] specifiedKeys, ModDataRecord record, WikiModEntry entry) { // specified update keys foreach (string key in specifiedKeys ?? Array.Empty <string>()) { if (!string.IsNullOrWhiteSpace(key)) { yield return(key.Trim()); } } // default update key { string defaultKey = record?.GetDefaultUpdateKey(); if (!string.IsNullOrWhiteSpace(defaultKey)) { yield return(defaultKey); } } // wiki metadata if (entry != null) { if (entry.NexusID.HasValue) { yield return(UpdateKey.GetString(ModSiteKey.Nexus, entry.NexusID.ToString())); } if (entry.ModDropID.HasValue) { yield return(UpdateKey.GetString(ModSiteKey.ModDrop, entry.ModDropID.ToString())); } if (entry.CurseForgeID.HasValue) { yield return(UpdateKey.GetString(ModSiteKey.CurseForge, entry.CurseForgeID.ToString())); } if (entry.ChucklefishID.HasValue) { yield return(UpdateKey.GetString(ModSiteKey.Chucklefish, entry.ChucklefishID.ToString())); } } // overrides from wiki foreach (string key in entry?.ChangeUpdateKeys ?? Array.Empty <string>()) { if (key.StartsWith('+')) { yield return(key.Substring(1)); } else if (!key.StartsWith("-")) { yield return(key); } } }
/// <summary>Get update keys based on the available mod metadata, while maintaining the precedence order.</summary> /// <param name="specifiedKeys">The specified update keys.</param> /// <param name="record">The mod's entry in SMAPI's internal database.</param> /// <param name="entry">The mod's entry in the wiki list.</param> public IEnumerable <string> GetUpdateKeys(string[] specifiedKeys, ModDataRecord record, WikiModEntry entry) { IEnumerable <string> GetRaw() { // specified update keys if (specifiedKeys != null) { foreach (string key in specifiedKeys) { yield return(key?.Trim()); } } // default update key string defaultKey = record?.GetDefaultUpdateKey(); if (defaultKey != null) { yield return(defaultKey); } // wiki metadata if (entry != null) { if (entry.NexusID.HasValue) { yield return($"Nexus:{entry.NexusID}"); } if (entry.ChucklefishID.HasValue) { yield return($"Chucklefish:{entry.ChucklefishID}"); } if (entry.ModDropID.HasValue) { yield return($"ModDrop:{entry.ModDropID}"); } } } HashSet <string> seen = new HashSet <string>(StringComparer.InvariantCulture); foreach (string key in GetRaw()) { if (!string.IsNullOrWhiteSpace(key) && seen.Add(key)) { yield return(key); } } }