/// <summary> /// Get the default package IDs for the given version. /// </summary> /// <param name="metadata">Unity version</param> /// <param name="cachePlatform">Name of platform</param> public IEnumerable <string> GetDefaultPackages(VersionMetadata metadata, CachePlatform cachePlatform) { var platform = metadata.GetPlatform(cachePlatform); if (platform.packages == null) { throw new ArgumentException("Unity version contains no packages."); } return(platform.packages.Where(p => p.install).Select(p => p.name)); }
/// <summary> /// Extract the versions and the base URLs from the html string. /// </summary> Dictionary <UnityVersion, VersionMetadata> ExtractFromHtml(string html, Dictionary <UnityVersion, VersionMetadata> results = null) { var matches = UNIT_DOWNLOADS_RE.Matches(html); results = results ?? new Dictionary <UnityVersion, VersionMetadata>(); foreach (Match match in matches) { var version = new UnityVersion(match.Groups[4].Value); version.hash = match.Groups[2].Value; var iniUrl = match.Groups[1].Value; var componentName = match.Groups[3].Value; CachePlatform cachePlatform; if (componentName.Contains("Mac")) { cachePlatform = CachePlatform.macOS; } else if (componentName.Contains("Windows")) { cachePlatform = CachePlatform.Windows; } else if (componentName.Contains("Linux")) { cachePlatform = CachePlatform.Linux; } else { Logger.LogDebug("Platform name not found in component name: " + componentName); continue; } VersionMetadata metadata = default; if (!results.TryGetValue(version, out metadata)) { metadata.version = version; } var platform = metadata.GetPlatform(cachePlatform); platform.iniUrl = iniUrl; metadata.SetPlatform(cachePlatform, platform); results[version] = metadata; } return(results); }
/// <summary> /// Create a download and install queue from the given version and packages. /// </summary> /// <param name="metadata">The Unity version</param> /// <param name="cachePlatform">Name of platform</param> /// <param name="downloadPath">Location of the downloaded the packages</param> /// <param name="packageIds">Packages to download and/or install</param> /// <returns>The queue list with the created queue items</returns> public Queue CreateQueue(VersionMetadata metadata, CachePlatform cachePlatform, string downloadPath, IEnumerable <PackageMetadata> packages) { if (!metadata.version.IsFullVersion) { throw new ArgumentException("VersionMetadata.version needs to contain a full Unity version", nameof(metadata)); } var platform = metadata.GetPlatform(cachePlatform); if (platform.packages == null || platform.packages.Length == 0) { throw new ArgumentException("VersionMetadata.packages cannot be null or empty", nameof(metadata)); } var items = new List <QueueItem>(); foreach (var package in packages) { var fullUrl = package.url; if (platform.iniUrl != null && !fullUrl.StartsWith("http")) { fullUrl = platform.iniUrl + package.url; } var fileName = package.GetFileName(); Logger.LogDebug($"{package.name}: Using file name '{fileName}' for url '{fullUrl}'"); var outputPath = Path.Combine(downloadPath, fileName); items.Add(new QueueItem() { package = package, downloadUrl = new Uri(fullUrl), filePath = outputPath, retries = Configuration.retryCount }); } return(new Queue() { metadata = metadata, items = items }); }
/// <summary> /// Resolve package patterns to package metadata. /// This method also adds package dependencies. /// </summary> public IEnumerable <PackageMetadata> ResolvePackages( VersionMetadata metadata, CachePlatform cachePlatform, IEnumerable <string> packages, IList <string> notFound = null, bool addDependencies = true ) { var platform = metadata.GetPlatform(cachePlatform); var metas = new List <PackageMetadata>(); foreach (var id in packages) { PackageMetadata resolved = default; if (id.StartsWith('~')) { // Contains lookup var str = id.Substring(1); foreach (var package in platform.packages) { if (package.name.Contains(str, StringComparison.OrdinalIgnoreCase)) { if (resolved.name == null) { Logger.LogDebug($"Fuzzy lookup '{id}' matched package '{resolved.name}'"); resolved = package; } else { throw new Exception($"Fuzzy package match '{id}' is ambiguous between '{package.name}' and '{resolved.name}'"); } } } } else { // Exact lookup resolved = platform.GetPackage(id); } if (resolved.name != null) { if (addDependencies) { foreach (var package in platform.packages) { if (package.sync == resolved.name && !metas.Any(p => p.name == package.name)) { Logger.LogInformation($"Adding '{package.name}' which '{resolved.name}' is synced with"); metas.Add(package); } } } metas.Add(resolved); } else if (notFound != null) { notFound.Add(id); } } return(metas); }