public DownloadWindow(GameBananaItem item) { InitializeComponent(); DownloadText.Text = $"Would you like to download {item.Name} for {item.Game} submitted by {item.Owner}?"; var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = item.SubFeedImage; bitmap.EndInit(); Preview.Source = bitmap; }
private async Task GameBananaUpdate(GameBananaItem item, DisplayedMetadata row, string game, Progress <DownloadProgress> progress, CancellationTokenSource cancellationToken) { if (item.HasUpdates) { GameBananaItemUpdate[] updates = item.Updates; string updateTitle = updates[0].Title; int updateIndex = 0; Match onlineVersionMatch = Regex.Match(updateTitle, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); string onlineVersion = null; if (onlineVersionMatch.Success) { onlineVersion = onlineVersionMatch.Groups["version"].Value; } // GB Api only returns two latest updates, so if the first doesn't have a version try the second else if (updates.Length > 1) { updateTitle = updates[1].Title; onlineVersionMatch = Regex.Match(updateTitle, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); updateIndex = 1; if (onlineVersionMatch.Success) { onlineVersion = onlineVersionMatch.Groups["version"].Value; } } Match localVersionMatch = Regex.Match(row.version, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); string localVersion = null; if (localVersionMatch.Success) { localVersion = localVersionMatch.Groups["version"].Value; } if (row.skippedVersion != null) { if (row.skippedVersion == "all" || !UpdateAvailable(onlineVersion, row.skippedVersion)) { Console.WriteLine($"[INFO] No updates available for {row.name}"); return; } } if (UpdateAvailable(onlineVersion, localVersion)) { Console.WriteLine($"[INFO] An update is available for {row.name} ({onlineVersion})"); // Display the changelog and confirm they want to update ChangelogBox changelogBox = new ChangelogBox(updates[updateIndex], row.name, $"Would you like to update {row.name} to version {onlineVersion}?", row, onlineVersion, $@"{assemblyLocation}\Packages\{game}\{row.path}\Package.xml", false); changelogBox.Activate(); changelogBox.ShowDialog(); if (!changelogBox.YesNo) { Console.WriteLine($"[INFO] Cancelled update for {row.name}"); return; } // Download the update Dictionary <String, GameBananaItemFile> files = item.Files; string downloadUrl, fileName; // Work out which are Aemulus comptaible by examining the file tree Dictionary <String, GameBananaItemFile> aemulusCompatibleFiles = new Dictionary <string, GameBananaItemFile>(); foreach (KeyValuePair <string, GameBananaItemFile> file in files) { if (file.Value.FileMetadata.Values.Count > 2) { string fileTree = file.Value.FileMetadata.Values.ElementAt(3).ToString(); if (fileTree.ToLower().Contains("package.xml") || fileTree.ToLower().Contains("mod.xml") || fileTree == "[]") { aemulusCompatibleFiles.Add(file.Key, file.Value); } } } if (aemulusCompatibleFiles.Count > 1) { UpdateFileBox fileBox = new UpdateFileBox(aemulusCompatibleFiles, row.name); fileBox.Activate(); fileBox.ShowDialog(); downloadUrl = fileBox.chosenFileUrl; fileName = fileBox.chosenFileName; } else if (aemulusCompatibleFiles.Count == 1) { downloadUrl = aemulusCompatibleFiles.ElementAt(0).Value.DownloadUrl; fileName = aemulusCompatibleFiles.ElementAt(0).Value.FileName; } else { Console.WriteLine($"[INFO] An update is available for {row.name} ({onlineVersion}) but no downloadable files are available."); NotificationBox notification = new NotificationBox($"{row.name} has an update ({onlineVersion}) but no downloadable files.\nWould you like to go to the page to manually download the update?", false); notification.ShowDialog(); notification.Activate(); if (notification.YesNo) { Process.Start(row.link); } return; } if (downloadUrl != null && fileName != null) { await DownloadFile(downloadUrl, fileName, game, row, onlineVersion, progress, cancellationToken, updates[updateIndex]); } else { Console.WriteLine($"[INFO] Cancelled update for {row.name}"); } } else { Console.WriteLine($"[INFO] No updates available for {row.name}"); } // TODO Check if there was no version number } else { Console.WriteLine($"[INFO] No updates available for {row.name}"); } }
private async Task GameBananaUpdate(GameBananaItem item, DisplayedMetadata row, string game, Progress <DownloadProgress> progress, CancellationTokenSource cancellationToken) { if (item.HasUpdates) { GameBananaItemUpdate[] updates = item.Updates; string updateTitle = updates[0].Title; int updateIndex = 0; Match onlineVersionMatch = Regex.Match(updateTitle, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); string onlineVersion = null; if (onlineVersionMatch.Success) { onlineVersion = onlineVersionMatch.Groups["version"].Value; } // GB Api only returns two latest updates, so if the first doesn't have a version try the second else if (updates.Length > 1) { updateTitle = updates[1].Title; onlineVersionMatch = Regex.Match(updateTitle, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); updateIndex = 1; if (onlineVersionMatch.Success) { onlineVersion = onlineVersionMatch.Groups["version"].Value; } } Match localVersionMatch = Regex.Match(row.version, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*"); string localVersion = null; if (localVersionMatch.Success) { localVersion = localVersionMatch.Groups["version"].Value; } if (row.skippedVersion != null) { if (row.skippedVersion == "all" || !UpdateAvailable(onlineVersion, row.skippedVersion)) { Console.WriteLine($"[INFO] No updates available for {row.name}"); return; } } if (UpdateAvailable(onlineVersion, localVersion)) { Console.WriteLine($"[INFO] An update is available for {row.name} ({onlineVersion})"); // Display the changelog and confirm they want to update ChangelogBox changelogBox = new ChangelogBox(updates[updateIndex], row.name, $"Would you like to update {row.name} to version {onlineVersion}?", row, onlineVersion, $@"{assemblyLocation}\Packages\{game}\{row.path}\Package.xml", false); changelogBox.Activate(); changelogBox.ShowDialog(); if (!changelogBox.YesNo) { Console.WriteLine($"[INFO] Cancelled update for {row.name}"); return; } // Download the update Dictionary <String, GameBananaItemFile> files = item.Files; string downloadUrl, fileName; // Work out which are Aemulus comptaible by examining the file tree Dictionary <String, GameBananaItemFile> aemulusCompatibleFiles = new Dictionary <string, GameBananaItemFile>(); foreach (KeyValuePair <string, GameBananaItemFile> file in files) { if (file.Value.FileMetadata.Values.Count > 0) { string fileTree = file.Value.FileMetadata.Values.ElementAt(1).ToString(); if (!fileTree.ToLower().Contains(".disable_gb1click") && (fileTree.ToLower().Contains("package.xml") || fileTree.ToLower().Contains("mod.xml") || fileTree == "[]")) { aemulusCompatibleFiles.Add(file.Key, file.Value); } } } if (aemulusCompatibleFiles.Count > 1) { UpdateFileBox fileBox = new UpdateFileBox(aemulusCompatibleFiles.Values.ToList(), row.name); fileBox.Activate(); fileBox.ShowDialog(); downloadUrl = fileBox.chosenFileUrl; fileName = fileBox.chosenFileName; } else if (aemulusCompatibleFiles.Count == 1) { downloadUrl = aemulusCompatibleFiles.ElementAt(0).Value.DownloadUrl; fileName = aemulusCompatibleFiles.ElementAt(0).Value.FileName; } else { Console.WriteLine($"[INFO] An update is available for {row.name} ({onlineVersion}) but there are no downloads directly from GameBanana."); // Convert the url Uri uri = CreateUri(row.link); string itemType = uri.Segments[1]; itemType = char.ToUpper(itemType[0]) + itemType.Substring(1, itemType.Length - 3); string itemId = uri.Segments[2]; // Parse the response string responseString = await client.GetStringAsync($"https://gamebanana.com/apiv4/{itemType}/{itemId}"); var response = JsonConvert.DeserializeObject <GameBananaAPIV4>(responseString); new AltLinkWindow(response.AlternateFileSources, row.name, game, true).ShowDialog(); return; } if (downloadUrl != null && fileName != null) { await DownloadFile(downloadUrl, fileName, game, row, onlineVersion, progress, cancellationToken, updates[updateIndex]); } else { Console.WriteLine($"[INFO] Cancelled update for {row.name}"); } } else { Console.WriteLine($"[INFO] No updates available for {row.name}"); } } else { Console.WriteLine($"[INFO] No updates available for {row.name}"); } }