Esempio n. 1
0
 private void LoadChangelogText()
 {
     if (!File.Exists("changelog.log"))
     {
         ChangelogBox.AppendText("Changelog not found!");
         return;
     }
     string[] _changelog = File.ReadAllLines("changelog.log");
     foreach (string line in _changelog)
     {
         TextRange fLine = new TextRange(ChangelogBox.Document.ContentEnd, ChangelogBox.Document.ContentEnd)
         {
             Text = $"{line}\n"
         };
         if (line.StartsWith("PATCH"))
         {
             fLine.ApplyPropertyValue(TextElement.FontWeightProperty, "Bold");
         }
         else
         {
             fLine.ApplyPropertyValue(TextElement.FontWeightProperty, "Light");
         }
         fLine.ApplyPropertyValue(TextElement.ForegroundProperty, GetLineColor(line));
     }
 }
Esempio n. 2
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);
                    }
                }
            }
        }
Esempio n. 3
0
        public static async Task <bool> CheckForFileDaddyUpdate(CancellationTokenSource cancellationToken)
        {
            // Get Version Number
            var localVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

            try
            {
                var requestUrl = $"https://api.gamebanana.com/Core/Item/Data?itemtype=Tool&itemid=7015&fields=Updates().bSubmissionHasUpdates()," +
                                 $"Updates().aGetLatestUpdates(),Files().aFiles()&return_keys=1";
                GameBananaItem response = JsonSerializer.Deserialize <GameBananaItem>(await client.GetStringAsync(requestUrl));
                if (response == null)
                {
                    MessageBox.Show("Error whilst checking for FileDaddy update: No response from GameBanana API");
                    return(false);
                }
                if (response.HasUpdates)
                {
                    GameBananaItemUpdate[] updates = response.Updates;
                    string updateTitle             = updates[0].Title;
                    Match  onlineVersionMatch      = Regex.Match(updateTitle, @"(?<version>([1-9]+\.?)+)[^a-zA-Z]");
                    string onlineVersion           = null;
                    if (onlineVersionMatch.Success)
                    {
                        onlineVersion = onlineVersionMatch.Value;
                    }
                    if (UpdateAvailable(onlineVersion, localVersion))
                    {
                        ChangelogBox notification = new ChangelogBox(updates[0], "FileDaddy", $"A new version of FileDaddy is available (v{onlineVersion})!", null);
                        notification.ShowDialog();
                        notification.Activate();
                        if (notification.YesNo)
                        {
                            Dictionary <String, GameBananaItemFile> files = response.Files;
                            string downloadUrl = files.ElementAt(0).Value.DownloadUrl;
                            string fileName    = files.ElementAt(0).Value.FileName;
                            // Download the update
                            await DownloadFileDaddy(downloadUrl, fileName, onlineVersion, new Progress <DownloadProgress>(ReportUpdateProgress), cancellationToken);

                            // Notify that the update is about to happen
                            MessageBox.Show($"Finished downloading {fileName}!\nFileDaddy will now restart.", "Notification", MessageBoxButton.OK);
                            // Update FileDaddy
                            UpdateManager updateManager = new UpdateManager(new LocalPackageResolver($"{assemblyLocation}/Downloads/FileDaddyUpdate"), new ZipExtractor());
                            if (!Version.TryParse(onlineVersion, out Version version))
                            {
                                MessageBox.Show($"Error parsing {onlineVersion}!\nCancelling update.", "Notification", MessageBoxButton.OK);
                                return(false);
                            }
                            // Updates and restarts FileDaddy
                            await updateManager.PrepareUpdateAsync(version);

                            updateManager.LaunchUpdater(version);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(false);
        }
Esempio n. 4
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}");
            }
        }