Exemplo n.º 1
0
        /// <summary>
        /// Downloads and installs a mod update.
        /// </summary>
        /// <param name="update">The update info coming from the update server</param>
        /// <param name="mod">The mod metadata from Everest for the installed mod</param>
        /// <param name="button">The button for that mod shown on the interface</param>
        private void downloadModUpdate(ModUpdateInfo update, EverestModuleMetadata mod, TextMenu.Button button)
        {
            task = new Task(() => {
                // we will download the mod to Celeste_Directory/mod-update.zip at first.
                string zipPath = Path.Combine(Everest.PathGame, "mod-update.zip");

                try {
                    // download it...
                    button.Label = $"{update.Name.SpacedPascalCase()} ({Dialog.Clean("MODUPDATECHECKER_DOWNLOADING")})";
                    downloadMod(update, button, zipPath);

                    // verify its checksum
                    ModUpdaterHelper.VerifyChecksum(update, zipPath);

                    // mark restarting as required, as we will do weird stuff like closing zips afterwards.
                    if (!shouldRestart)
                    {
                        shouldRestart       = true;
                        subHeader.TextColor = Color.OrangeRed;
                        subHeader.Title     = $"{Dialog.Clean("MODUPDATECHECKER_MENU_HEADER")} ({Dialog.Clean("MODUPDATECHECKER_WILLRESTART")})";
                    }

                    // install it
                    button.Label = $"{update.Name.SpacedPascalCase()} ({Dialog.Clean("MODUPDATECHECKER_INSTALLING")})";
                    ModUpdaterHelper.InstallModUpdate(update, mod, zipPath);

                    // done!
                    button.Label = $"{update.Name.SpacedPascalCase()} ({Dialog.Clean("MODUPDATECHECKER_UPDATED")})";

                    // select another enabled option: the next one, or the last one if there is no next one.
                    if (menu.Selection + 1 > menu.LastPossibleSelection)
                    {
                        menu.Selection = menu.LastPossibleSelection;
                    }
                    else
                    {
                        menu.MoveSelection(1);
                    }
                } catch (Exception e) {
                    // update failed
                    button.Label = $"{update.Name.SpacedPascalCase()} ({Dialog.Clean("MODUPDATECHECKER_FAILED")})";
                    Logger.Log("OuiModUpdateList", $"Updating {update.Name} failed");
                    Logger.LogDetailed(e);
                    button.Disabled = false;

                    // try to delete mod-update.zip if it still exists.
                    ModUpdaterHelper.TryDelete(zipPath);
                }

                // give the menu control back to the player
                menu.Focused = true;
            });
            task.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads and installs a mod update.
        /// </summary>
        /// <param name="update">The update info coming from the update server</param>
        /// <param name="mod">The mod metadata from Everest for the installed mod</param>
        /// <param name="button">The button for that mod shown on the interface</param>
        private void downloadModUpdate(ModUpdateInfo update, EverestModuleMetadata mod, TextMenu.Button button)
        {
            task = new Task(() => {
                // we will download the mod to Celeste_Directory/mod-update.zip at first.
                string zipPath = Path.Combine(Everest.PathGame, "mod-update.zip");

                try {
                    // download it...
                    button.Label = $"{update.Name} ({Dialog.Clean("MODUPDATECHECKER_DOWNLOADING")})";
                    downloadMod(update, button, zipPath);

                    // verify its checksum
                    string actualHash   = BitConverter.ToString(Everest.GetChecksum("mod-update.zip")).Replace("-", "").ToLowerInvariant();
                    string expectedHash = update.xxHash[0];
                    Logger.Log("OuiModUpdateList", $"Verifying checksum: actual hash is {actualHash}, expected hash is {expectedHash}");
                    if (expectedHash != actualHash)
                    {
                        throw new IOException($"Checksum error: expected {expectedHash}, got {actualHash}");
                    }

                    // mark restarting as required, as we will do weird stuff like closing zips afterwards.
                    if (!shouldRestart)
                    {
                        shouldRestart       = true;
                        subHeader.TextColor = Color.OrangeRed;
                        subHeader.Title     = $"{Dialog.Clean("MODUPDATECHECKER_MENU_HEADER")} ({Dialog.Clean("MODUPDATECHECKER_WILLRESTART")})";
                    }

                    // install it
                    button.Label = $"{update.Name} ({Dialog.Clean("MODUPDATECHECKER_INSTALLING")})";
                    installMod(update, mod, zipPath);

                    // done!
                    button.Label = $"{update.Name} ({Dialog.Clean("MODUPDATECHECKER_UPDATED")})";

                    // select another enabled option: the next one, or the last one if there is no next one.
                    if (menu.Selection + 1 > menu.LastPossibleSelection)
                    {
                        menu.Selection = menu.LastPossibleSelection;
                    }
                    else
                    {
                        menu.MoveSelection(1);
                    }
                } catch (Exception e) {
                    // update failed
                    button.Label = $"{update.Name} ({Dialog.Clean("MODUPDATECHECKER_FAILED")})";
                    Logger.Log("OuiModUpdateList", $"Updating {update.Name} failed");
                    Logger.LogDetailed(e);
                    button.Disabled = false;

                    // try to delete mod-update.zip if it still exists.
                    if (File.Exists(zipPath))
                    {
                        try {
                            Logger.Log("OuiModUpdateList", $"Deleting temp file {zipPath}");
                            File.Delete(zipPath);
                        } catch (Exception) {
                            Logger.Log("OuiModUpdateList", $"Removing {zipPath} failed");
                        }
                    }
                }

                // give the menu control back to the player
                menu.Focused = true;
            });
            task.Start();
        }