/// <summary> /// Update the Unity versions cache. /// </summary> /// <param name="cachePlatform">Name of platform to update (only used for loading hub JSON)</param> /// <param name="type">Undefined = update latest, others = update archive of type and higher types</param> /// <returns>Task returning the newly discovered versions</returns> public async Task <IEnumerable <VersionMetadata> > UpdateCache(CachePlatform cachePlatform, UnityVersion.Type type = UnityVersion.Type.Undefined, CancellationToken cancellation = default) { var added = new List <VersionMetadata>(); if (type == UnityVersion.Type.Undefined) { Logger.LogDebug("Loading UnityHub JSON with latest Unity versions..."); var newVersions = await Scraper.LoadLatest(cachePlatform, cancellation); Logger.LogInformation($"Loaded {newVersions.Count()} versions from UnityHub JSON"); Versions.Add(newVersions, added); Versions.SetLastUpdate(type, DateTime.Now); } else { foreach (var t in UnityVersion.EnumerateMoreStableTypes(type)) { if (t != UnityVersion.Type.Final && t != UnityVersion.Type.Beta) { continue; } Logger.LogDebug($"Updating {t} Unity Versions..."); var newVersions = await Scraper.Load(t, cancellation); Logger.LogInformation($"Scraped {newVersions.Count()} versions of type {t}"); Versions.Add(newVersions, added); Versions.SetLastUpdate(t, DateTime.Now); } } Versions.Save(); added.Sort((m1, m2) => m2.version.CompareTo(m1.version)); return(added); }