Exemple #1
0
        public async void BrowserDownload(GameBananaRecord record)
        {
            DownloadWindow downloadWindow = new DownloadWindow(record);

            downloadWindow.ShowDialog();
            if (downloadWindow.YesNo)
            {
                string downloadUrl = null;
                string fileName    = null;
                if (record.Files.Count == 1)
                {
                    downloadUrl = record.Files[0].DownloadUrl;
                    fileName    = record.Files[0].FileName;
                }
                else if (record.Files.Count > 1)
                {
                    UpdateFileBox fileBox = new UpdateFileBox(record.Files, record.Title);
                    fileBox.Activate();
                    fileBox.ShowDialog();
                    downloadUrl = fileBox.chosenFileUrl;
                    fileName    = fileBox.chosenFileName;
                }
                if (downloadUrl != null && fileName != null)
                {
                    await DownloadFile(downloadUrl, fileName, new Progress <DownloadProgress>(ReportUpdateProgress),
                                       CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));

                    if (!cancelled)
                    {
                        await ExtractFile(fileName, record);
                    }
                }
            }
        }
Exemple #2
0
        public async void BrowserDownload(GameBananaRecord record, GameFilter game)
        {
            var gameName = "";

            switch (game)
            {
            case GameFilter.P3:
                gameName = "Persona 3 FES";
                break;

            case GameFilter.P4G:
                gameName = "Persona 4 Golden";
                break;

            case GameFilter.P5:
                gameName = "Persona 5";
                break;

            case GameFilter.P5S:
                gameName = "Persona 5 Strikers";
                break;
            }
            DownloadWindow downloadWindow = new DownloadWindow(record);

            downloadWindow.ShowDialog();
            if (downloadWindow.YesNo)
            {
                string downloadUrl = null;
                string fileName    = null;
                if (record.Files.Count == 1)
                {
                    downloadUrl = record.Files[0].DownloadUrl;
                    fileName    = record.Files[0].FileName;
                }
                else if (record.Files.Count > 1)
                {
                    UpdateFileBox fileBox = new UpdateFileBox(record.Files, record.Title);
                    fileBox.Activate();
                    fileBox.ShowDialog();
                    downloadUrl = fileBox.chosenFileUrl;
                    fileName    = fileBox.chosenFileName;
                }
                if (downloadUrl != null && fileName != null)
                {
                    await DownloadFile(downloadUrl, fileName, new Progress <DownloadProgress>(ReportUpdateProgress),
                                       CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));

                    if (!cancelled)
                    {
                        await ExtractFile($@"{assemblyLocation}\Downloads\{fileName}", gameName);

                        if (File.Exists($@"{assemblyLocation}\refresh.aem"))
                        {
                            FileIOWrapper.Delete($@"{assemblyLocation}\refresh.aem");
                        }
                        FileIOWrapper.WriteAllText($@"{assemblyLocation}\refresh.aem", gameName);
                    }
                }
            }
        }
Exemple #3
0
        private static async Task ModUpdate(GameBananaItem item, string mod, Metadata metadata, Progress <DownloadProgress> progress, CancellationTokenSource cancellationToken)
        {
            // If lastupdate doesn't exist, add one
            if (metadata.lastupdate == null)
            {
                if (item.HasUpdates)
                {
                    metadata.lastupdate = item.Updates[0].DateAdded;
                }
                else
                {
                    metadata.lastupdate = new DateTime(1970, 1, 1);
                }
                string metadataString = JsonSerializer.Serialize(metadata, new JsonSerializerOptions {
                    WriteIndented = true
                });
                File.WriteAllText($@"{mod}/mod.json", metadataString);
                return;
            }
            if (item.HasUpdates)
            {
                var update = item.Updates[0];
                // Compares dates of last update to current
                if (DateTime.Compare((DateTime)metadata.lastupdate, update.DateAdded) < 0)
                {
                    ++updateCounter;
                    // Display the changelog and confirm they want to update
                    _logger.WriteLine($"An update is available for {Path.GetFileName(mod)}!", LoggerType.Info);
                    ChangelogBox changelogBox = new ChangelogBox(update, Path.GetFileName(mod), $"A new update is available for {Path.GetFileName(mod)}", item.EmbedImage, true);
                    changelogBox.Activate();
                    changelogBox.ShowDialog();
                    if (changelogBox.Skip)
                    {
                        if (File.Exists($@"{mod}/mod.json"))
                        {
                            _logger.WriteLine($"Skipped update for {Path.GetFileName(mod)}...", LoggerType.Info);
                            metadata.lastupdate = update.DateAdded;
                            string metadataString = JsonSerializer.Serialize(metadata, new JsonSerializerOptions {
                                WriteIndented = true
                            });
                            File.WriteAllText($@"{mod}/mod.json", metadataString);
                        }
                        return;
                    }
                    if (!changelogBox.YesNo)
                    {
                        _logger.WriteLine($"Declined update for {Path.GetFileName(mod)}...", LoggerType.Info);
                        return;
                    }
                    // Download the update
                    var    files = item.Files;
                    string downloadUrl, fileName;

                    if (files.Count > 1)
                    {
                        UpdateFileBox fileBox = new UpdateFileBox(files.Values.ToList(), Path.GetFileName(mod));
                        fileBox.Activate();
                        fileBox.ShowDialog();
                        downloadUrl = fileBox.chosenFileUrl;
                        fileName    = fileBox.chosenFileName;
                    }
                    else if (files.Count == 1)
                    {
                        downloadUrl = files.ElementAt(0).Value.DownloadUrl;
                        fileName    = files.ElementAt(0).Value.FileName;
                    }
                    else
                    {
                        _logger.WriteLine($"An update is available for {Path.GetFileName(mod)} but no downloadable files are available.", LoggerType.Warning);
                        return;
                    }
                    if (downloadUrl != null && fileName != null)
                    {
                        await DownloadFile(downloadUrl, fileName, mod, update.DateAdded, progress, cancellationToken);
                    }
                    else
                    {
                        _logger.WriteLine($"Cancelled update for {Path.GetFileName(mod)}", LoggerType.Info);
                    }
                }
            }
        }
Exemple #4
0
        private async Task GitHubUpdate(Release release, DisplayedMetadata row, string game, Progress <DownloadProgress> progress, CancellationTokenSource cancellationToken)
        {
            Match  onlineVersionMatch = Regex.Match(release.TagName, @"(?<version>([0-9]+\.?)+)[^a-zA-Z]*");
            string onlineVersion      = null;

            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} ({release.TagName})");
                NotificationBox notification = new NotificationBox($"{row.name} has an update ({release.TagName}):\n{release.Body}\n\nWould you like to update?", false);
                notification.ShowDialog();
                notification.Activate();
                if (!notification.YesNo)
                {
                    return;
                }
                string downloadUrl, fileName;
                if (release.Assets.Count > 1)
                {
                    UpdateFileBox fileBox = new UpdateFileBox(release.Assets, row.name);
                    fileBox.Activate();
                    fileBox.ShowDialog();
                    downloadUrl = fileBox.chosenFileUrl;
                    fileName    = fileBox.chosenFileName;
                }
                else if (release.Assets.Count == 1)
                {
                    downloadUrl = release.Assets.First().BrowserDownloadUrl;
                    fileName    = release.Assets.First().Name;
                }
                else
                {
                    Console.WriteLine($"[INFO] An update is available for {row.name} ({release.TagName}) but no downloadable files are available.");
                    notification = new NotificationBox($"{row.name} has an update ({release.TagName}) 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, release.TagName, progress, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));
                }
                else
                {
                    Console.WriteLine($"[INFO] Cancelled update for {row.name}");
                }
            }
            else
            {
                Console.WriteLine($"[INFO] No updates available for {row.name}");
            }
        }
Exemple #5
0
        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}");
            }
        }