Пример #1
0
        public ModDownload GetGameBananaReleases(ModInfo mod, string folder, List <string> errors)
        {
            GameBananaItem gbi;

            try
            {
                gbi = GameBananaItem.Load(mod.GameBananaItemType, mod.GameBananaItemId.Value);
            }
            catch (Exception ex)
            {
                errors.Add($"[{mod.Name}] Error checking for updates: {ex.Message}");
                return(null);
            }

            if (!gbi.HasUpdates)
            {
                // No releases available.
                return(null);
            }

            GameBananaItemUpdate latestUpdate = gbi.Updates[0];
            DateTime?            localVersion = GetLocalVersion(folder);

            if (!ForceUpdate && localVersion.HasValue)
            {
                if (localVersion >= latestUpdate.DateAdded)
                {
                    // No updates available.
                    return(null);
                }
            }

            string body = string.Join(Environment.NewLine, latestUpdate.Changes.Select(a => a.Category + ": " + a.Text)) + Environment.NewLine + latestUpdate.Text;

            GameBananaItemFile dl = gbi.Files.First().Value;

            return(new ModDownload(mod, Path.Combine("mods", folder), dl.DownloadUrl, body, dl.Filesize)
            {
                HomePage = gbi.ProfileUrl,
                Name = latestUpdate.Title,
                Version = latestUpdate.Title,
                Published = latestUpdate.DateAdded,
                Updated = latestUpdate.DateAdded,
                ReleaseUrl = gbi.ProfileUrl
            });
        }
Пример #2
0
        public ModDownload GetGameBananaReleases(ModInfo mod, string folder,
                                                 List <string> errors)
        {
            GameBananaItem gbi;

            try
            {
                gbi = GameBananaItem.Load(mod.GameBananaItemType, mod.GameBananaItemId.Value);
            }
            catch (Exception ex)
            {
                errors.Add($"[{mod.Name}] Error checking for updates: {ex.Message}");
                return(null);
            }

            if (!gbi.HasUpdates)
            {
                // No releases available.
                return(null);
            }

            string   versionPath  = Path.Combine("mods", folder, "mod.version");
            DateTime?localVersion = null;

            if (File.Exists(versionPath))
            {
                localVersion = DateTime.Parse(File.ReadAllText(versionPath).Trim());
            }
            else
            {
                var info = new FileInfo(Path.Combine("mods", folder, "mod.manifest"));
                if (info.Exists)
                {
                    localVersion = info.LastWriteTimeUtc;
                }
            }

            GameBananaItemUpdate latestUpdate = gbi.Updates[0];

            if (!ForceUpdate && localVersion.HasValue)
            {
                if (localVersion >= latestUpdate.DateAdded)
                {
                    // No updates available.
                    return(null);
                }
            }

            string body = string.Join(Environment.NewLine, latestUpdate.Changes.Select(a => a.Category + ": " + a.Text)) + Environment.NewLine + latestUpdate.Text;

            GameBananaItemFile dl = gbi.Files.First().Value;

            return(new ModDownload(mod, Path.Combine("mods", folder), dl.DownloadUrl, body, dl.Filesize)
            {
                HomePage = gbi.ProfileUrl,
                Name = latestUpdate.Title,
                Version = latestUpdate.Title,
                Published = latestUpdate.DateAdded.ToString(CultureInfo.CurrentCulture),
                Updated = latestUpdate.DateAdded.ToString(CultureInfo.CurrentCulture),
                ReleaseUrl = gbi.ProfileUrl
            });
        }