public static string DownloadMod(TroveMod mod, string fileId) { if (mod?.Id == null) { throw new ArgumentNullException("mod.Id"); } if (mod?.Downloads == null) { throw new ArgumentNullException("mod.Downloads"); } var download = mod.Downloads.First(m => m.FileId == fileId); string unixDate = download.Date; string fileName = string.Format("{0}+{1}.{2}", TroveMod.FilterModFilename(mod.Name), unixDate, string.IsNullOrEmpty(download.Format) ? "zip" : download.Format); string localPath = Path.Combine(SettingsDataProvider.ModsFolder, fileName); using (var client = OpenWebClient()) { string url = AddQuerystring(string.Format(ModDownloadUrl, mod.Id, fileId)); client.DownloadFile(url, localPath); } mod.CurrentFileId = fileId; try { mod.UnixTimeSeconds = Convert.ToInt64(unixDate); } catch { } return(localPath); }
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); }