Exemplo n.º 1
0
        /// <summary>
        /// Gets the latest release of the mod and properly resolves extended info
        /// </summary>
        public static bool TryGetLatestRelease(this ApiModInfo info, out ModReleaseInfo release)
        {
            if (info.LatestRelease.HasValue)
            {
                release = info.LatestRelease.Value;
                return(true);
            }

            if (!(info.Releases is null) && (info.Releases.Length > 0))
            {
                ModReleaseInfo max = default;
                foreach (var r in info.Releases)
                {
                    if (r.Version > max.Version)
                    {
                        max = r;
                    }
                }
                release = max;
                return(true);
            }

            release = default;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads a mod.
        /// </summary>
        /// <param name="release">The specific release to download.</param>
        /// <param name="username">Username for authentication.</param>
        /// <param name="token">Login token for authentication.</param>
        /// <param name="fileName">Destination file name.</param>
        public static async Task <FileInfo> DownloadModReleaseAsync(ModReleaseInfo release, string username, string token, string fileName,
                                                                    CancellationToken cancellationToken = default, IProgress <double> progress = null)
        {
            var file = new FileInfo(fileName);

            await DownloadModReleaseAsync(release, username, token, file, cancellationToken, progress);

            return(file);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Downloads a mod.
 /// </summary>
 /// <param name="release">The specific release to download.</param>
 /// <param name="username">Username for authentication.</param>
 /// <param name="token">Login token for authentication.</param>
 /// <param name="file">Destination file.</param>
 public static async Task DownloadModReleaseAsync(ModReleaseInfo release, string username, string token, FileInfo file,
                                                  CancellationToken cancellationToken = default, IProgress <double> progress = null)
 {
     try
     {
         string url = $"{release.DownloadUrl}?username={username}&token={token}";
         await WebHelper.DownloadFileAsync(url, file, cancellationToken, progress);
     }
     catch (WebException ex)
     {
         throw ApiException.FromWebException(ex);
     }
 }
Exemplo n.º 4
0
        internal ApiModInfo(string displayName, int downloadCount, string name, string summary, string author, double score, string category, string thumbnailUrl, ModReleaseInfo latestRelease,
                            string description, string changelog, string faq, string homepage, string gitHubUrl, License license, ModReleaseInfo[] releases, DateTime creationDate, DateTime lastUpdateDate)
        {
            DisplayName   = displayName;
            DownloadCount = downloadCount;
            Name          = name;
            Summary       = summary;
            Author        = author;
            Score         = score;
            Category      = category;

            if (!string.IsNullOrEmpty(thumbnailUrl) && thumbnailUrl.EndsWith("/.thumb.png"))
            {
                ThumbnailUrl = null;                                                                              // No thumbnail available
            }
            else
            {
                ThumbnailUrl = "https://mods-data.factorio.com" + thumbnailUrl;
            }

            LatestRelease = latestRelease;


            // Extended data

            if (string.IsNullOrWhiteSpace(description))
            {
                Description = summary;                                         // Use summary if no separate description available
            }
            else
            {
                Description = description;
            }

            Changelog      = changelog;
            Faq            = faq;
            Homepage       = homepage;
            GitHubUrl      = gitHubUrl;
            License        = license;
            Releases       = releases;
            CreationDate   = creationDate;
            LastUpdateDate = lastUpdateDate;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Downloads a mod
 /// </summary>
 /// <param name="release">The specific release to download</param>
 /// <param name="username">Username for authentication</param>
 /// <param name="token">Login token for authentication</param>
 /// <param name="fileName">Destination file name</param>
 public static Task <FileInfo> DownloadModReleaseAsync(
     ModReleaseInfo release,
     string username, string token,
     string fileName)
 => DownloadModReleaseAsync(release, username, token, fileName, CancellationToken.None);