/// <summary>Get metadata about a mod in the repository.</summary> /// <param name="id">The mod ID in this repository.</param> public override async Task <ModInfoModel> GetModInfoAsync(string id) { // validate ID format if (!uint.TryParse(id, out uint curseID)) { return(new ModInfoModel().SetError(RemoteModStatus.DoesNotExist, $"The value '{id}' isn't a valid CurseForge mod ID, must be an integer ID.")); } // fetch info try { CurseForgeMod mod = await this.Client.GetModAsync(curseID); if (mod == null) { return(new ModInfoModel().SetError(RemoteModStatus.DoesNotExist, "Found no CurseForge mod with this ID.")); } if (mod.Error != null) { RemoteModStatus remoteStatus = RemoteModStatus.InvalidData; return(new ModInfoModel().SetError(remoteStatus, mod.Error)); } return(new ModInfoModel(name: mod.Name, version: this.NormalizeVersion(mod.LatestVersion), url: mod.Url)); } catch (Exception ex) { return(new ModInfoModel().SetError(RemoteModStatus.TemporaryError, ex.ToString())); } }
/// <summary>Set a mod error.</summary> /// <param name="status">The mod availability status on the remote site.</param> /// <param name="error">The error message indicating why the mod is invalid (if applicable).</param> public ModInfoModel SetError(RemoteModStatus status, string error) { this.Status = status; this.Error = error; return(this); }
/// <summary>Get metadata about a mod in the repository.</summary> /// <param name="id">The mod ID in this repository.</param> public override async Task <ModInfoModel> GetModInfoAsync(string id) { // validate ID format if (!uint.TryParse(id, out uint nexusID)) { return(new ModInfoModel().SetError(RemoteModStatus.DoesNotExist, $"The value '{id}' isn't a valid Nexus mod ID, must be an integer ID.")); } // fetch info try { NexusMod mod = await this.Client.GetModAsync(nexusID); if (mod == null) { return(new ModInfoModel().SetError(RemoteModStatus.DoesNotExist, "Found no Nexus mod with this ID.")); } if (mod.Error != null) { RemoteModStatus remoteStatus = mod.Status == NexusModStatus.Hidden || mod.Status == NexusModStatus.NotPublished ? RemoteModStatus.DoesNotExist : RemoteModStatus.TemporaryError; return(new ModInfoModel().SetError(remoteStatus, mod.Error)); } return(new ModInfoModel(name: mod.Name, version: this.NormalizeVersion(mod.Version), previewVersion: mod.LatestFileVersion?.ToString(), url: mod.Url)); } catch (Exception ex) { return(new ModInfoModel().SetError(RemoteModStatus.TemporaryError, ex.ToString())); } }
/// <summary>Set a mod fetch error.</summary> /// <param name="status">The mod availability status on the remote site.</param> /// <param name="error">A user-friendly error which indicates why fetching the mod info failed (if applicable).</param> public IModPage SetError(RemoteModStatus status, string error) { this.Status = status; this.Error = error; return(this); }