Ejemplo n.º 1
0
        private void Run(BaseLocale bl, ushort currentVersion)
        {
            while (true)
            {
                ushort?newVersion = bl.GetNewVersion(currentVersion);

                if (newVersion.HasValue)
                {
                    newVersion = (ushort)(currentVersion + 1);
                    while (true)
                    {
                        bw.ReportProgress(0, String.Format("Downloading {0} to {1} patch: init...", currentVersion, newVersion.Value));

                        string patchFilename = "";
                        try
                        {
                            patchFilename = bl.DownloadPatchfile(currentVersion, newVersion.Value, (progress) =>
                            {
                                bw.ReportProgress(0, String.Format("Downloading {0} to {1} patch: {2}%", currentVersion, newVersion.Value, progress));
                            });
                        }
                        catch (Exception)
                        {
                            bw.ReportProgress(0, "Failed downloading patch. Trying different version.");
                            newVersion = (ushort)(newVersion.Value - 1);
                            continue;
                        }

                        bw.ReportProgress(0, String.Format("Running patcher for {0} -> {1}", currentVersion, newVersion.Value));

                        var succeeded = RunOwnPatcher(patchFilename, currentVersion, newVersion.Value);
                        if (!succeeded)
                        {
                            if (MessageBox.Show("Failed to patch with own patcher. Try NXPatcher?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                var exitCode = OpenNXPatcher(patchFilename);

                                if (exitCode != 0)
                                {
                                    if (currentVersion + 1 != newVersion.Value)
                                    {
                                        bw.ReportProgress(0, "Trying older version...");
                                        bw.ReportProgress(0, DetectBaseWZVersion());
                                        newVersion = (ushort)(newVersion.Value - 1);
                                        continue;
                                    }
                                    else if (MessageBox.Show("NXPatcher exited with exit code " + exitCode + ". Try maple patcher instead?", "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        WritePatcherInfoFile(currentVersion, newVersion.Value);
                                        OpenPatcher();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Sorry, but I'm out of ideas now....");
                                        ToggleInputs(true);
                                        return;
                                    }
                                }
                                else
                                {
                                    if (!ApplyPatchedFiles(currentVersion, newVersion.Value))
                                    {
                                        ToggleInputs(true);
                                        return;
                                    }
                                }
                            }
                            else if (MessageBox.Show("Okay, try MaplePatcher then?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                WritePatcherInfoFile(currentVersion, newVersion.Value);
                                OpenPatcher();
                            }
                            else
                            {
                                MessageBox.Show("Sorry, but I'm out of ideas now....");
                                ToggleInputs(true);
                                return;
                            }
                        }
                        else
                        {
                            if (!ApplyPatchedFiles(currentVersion, newVersion.Value))
                            {
                                ToggleInputs(true);
                                return;
                            }
                        }

                        break;
                    }

                    currentVersion = newVersion.Value;
                    bw.ReportProgress(0, (int)nudVersion.Value);
                }
                else
                {
                    bw.ReportProgress(0, "Everything is up-to-date");
                    MessageBox.Show("Nothing to patch. Current version is " + currentVersion + " and latest version is " + bl.LatestVersion());
                    ToggleInputs(true);
                    break;
                }
            }
        }
        public ShowUpgradingList(BaseLocale locale)
        {
            InitializeComponent();

            _locale = locale;
        }