public static TroveMod GetMod(string id, string name = "") { try { var ic = StringComparison.OrdinalIgnoreCase; var mod = ModList.FirstOrDefault(m => m.Id.Equals(id, ic)); if (mod == null) { mod = ModList.FirstOrDefault(m => TroveMod.FilterModFilename(m.Name).Equals(TroveMod.FilterModFilename(name), ic)); } return(mod); } catch (Exception ex) { log.ErrorFormat("Error retrieving matching mod from Trovesaurus for mod {0}: {1}", string.IsNullOrEmpty(name) ? "id " + id : name, ex.Message); } return(null); }
public static void RefreshModPackList() { try { string url = AddQuerystring(ModPacksUrl), packsHtml; using (var client = OpenWebClient()) packsHtml = client.DownloadString(url); if (_ModPackList == null) { _ModPackList = new List <TroveModPack>(); } else { _ModPackList.Clear(); } // Parse mod packs HTML foreach (Match packMatch in Regex.Matches(packsHtml, ModPackRegex, RegexOptions.Singleline)) { var mods = Regex.Matches(packMatch.Groups["Details"].Value, PackModsRegex, RegexOptions.Singleline); if (mods.Count > 0) { TroveModPack pack = new TroveModPack(); pack.PackId = packMatch.Groups["PackId"].Value; pack.Url = packMatch.Groups["Url"].Value; pack.Name = packMatch.Groups["Name"].Value; pack.Author = packMatch.Groups["Author"].Value; pack.Source = "Trovesaurus"; foreach (Match modMatch in mods) { var mod = ModList.FirstOrDefault(m => m.Id == modMatch.Groups["ModId"].Value); if (mod != null) { pack.Mods.Add(mod); } } _ModPackList.Add(pack); } } } catch (Exception ex) { log.Error("Error refreshing Trovesaurus mod pack list", ex); } finally { if (_ModPackList == null) { _ModPackList = new List <TroveModPack>(); } } }