private async Task <bool> GetData() { try { string responseString = await client.GetStringAsync(URL); response = JsonConvert.DeserializeObject <GameBananaItem>(responseString); fileName = response.Files[DL_ID].FileName; return(true); } catch (Exception e) { MessageBox.Show($"Error while fetching data: {e.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } }
public async Task <IReadOnlyList <Version> > GetPackageVersionsAsync(CancellationToken cancellationToken = new CancellationToken()) { try { Item = await GameBananaItem.FromTypeAndIdAsync(Config.ItemType, Config.ItemId); if (Item.Files.Values.Count > 0) { ItemFile = Item.Files.First(x => CaseInsensitiveStringContains(x.Value.FileName, Config.FileNamePattern)).Value; var date = ItemFile.DateAdded; return(new[] { FromDateTime(date) }); } } catch (Exception) { /* Ignored */ } return(new List <Version>()); }
private void HandleUri(string uri) { if (WindowState == FormWindowState.Minimized) { WindowState = FormWindowState.Normal; } Activate(); var fields = uri.Substring("skcmm:".Length).Split(','); // TODO: lib-ify string itemType = fields.FirstOrDefault(x => x.StartsWith("gb_itemtype", StringComparison.InvariantCultureIgnoreCase)); itemType = itemType.Substring(itemType.IndexOf(":") + 1); string itemId = fields.FirstOrDefault(x => x.StartsWith("gb_itemid", StringComparison.InvariantCultureIgnoreCase)); itemId = itemId.Substring(itemId.IndexOf(":") + 1); var dummyInfo = new ModInfo(); GameBananaItem gbi = GameBananaItem.Load(itemType, long.Parse(itemId)); dummyInfo.Name = gbi.Name; dummyInfo.Author = gbi.OwnerName; DialogResult result = MessageBox.Show(this, $"Do you want to install mod \"{dummyInfo.Name}\" by {dummyInfo.Author} from {new Uri(fields[0]).DnsSafeHost}?", "Mod Download", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result != DialogResult.Yes) { return; } #region create update folder do { try { result = DialogResult.Cancel; if (!Directory.Exists(updatePath)) { Directory.CreateDirectory(updatePath); } } catch (Exception ex) { result = MessageBox.Show(this, "Failed to create temporary update directory:\n" + ex.Message + "\n\nWould you like to retry?", "Directory Creation Failed", MessageBoxButtons.RetryCancel); } } while (result == DialogResult.Retry); #endregion string dummyPath = dummyInfo.Name; foreach (char c in Path.GetInvalidFileNameChars()) { dummyPath = dummyPath.Replace(c, '_'); } dummyPath = Path.Combine("mods", dummyPath); var updates = new List <ModDownload> { new ModDownload(dummyInfo, dummyPath, fields[0], null, 0) }; using (var progress = new ModDownloadDialog(updates, updatePath)) { progress.ShowDialog(this); } do { try { result = DialogResult.Cancel; Directory.Delete(updatePath, true); } catch (Exception ex) { result = MessageBox.Show(this, "Failed to remove temporary update directory:\n" + ex.Message + "\n\nWould you like to retry? You can remove the directory manually later.", "Directory Deletion Failed", MessageBoxButtons.RetryCancel); } } while (result == DialogResult.Retry); LoadModList(); }
public GameBananaItem GetItem() { return(GameBananaItem.Load(ItemType, ItemId)); }