/// <summary> /// Retrieve information about the /// wrapped mod from the workhop asynchronously /// via the Steam web API. /// </summary> /// <returns></returns> public async Task <bool> UpdateModInfoAsync() { if (UgcService.ToLower() == "mod.io") { return(true); } var msg = ""; var workshopService = WebAPI.Instance; PublishedItemDetails modInfo = null; try { modInfo = (await workshopService.GetPublishedFileDetails(new ulong[] { PublishedFileId }))?[PublishedFileId]; } catch (Exception e) { Log.Error(e.Message); } if (modInfo == null) { Log.Error($"Failed to retrieve mod with workshop id '{PublishedFileId}'!"); return(false); } //else if (!modInfo.Tags.Contains("")) else { Log.Info($"Mod Info successfully retrieved!"); FriendlyName = modInfo.Title; Description = modInfo.Description; //Name = modInfo.FileName; return(true); } }
public async Task DownloadPublishedFile(PublishedItemDetails fileDetails, string dir, string name = null) { var fullPath = Path.Combine(dir, name); if (name == null) { name = fileDetails.FileName; } var expectedSize = (fileDetails.FileSize == 0) ? -1 : fileDetails.FileSize; using (var client = new WebClient()) { try { var downloadTask = client.DownloadFileTaskAsync(fileDetails.FileUrl, Path.Combine(dir, name)); DateTime start = DateTime.Now; for (int i = 0; i < 30; i++) { await Task.Delay(1000); if (downloadTask.IsCompleted) { break; } } if (!downloadTask.IsCompleted) { client.CancelAsync(); throw new Exception("Timeout while attempting to downloading published workshop item!"); } //var text = await client.DownloadStringTaskAsync(url); //File.WriteAllText(fullPath, text); } catch (Exception e) { throw new Exception($"{e.Message} - url: {fileDetails.FileUrl}, path: {Path.Combine(dir, name)}"); } } }