Esempio n. 1
0
        void SelfPatch()
        {
            try
            {
                Fingerprint myFingerprint = new Fingerprint(Settings.GamePath, "Bourbon.exe");

                if (DontSelfUpdate)
                {
                    return;
                }
                MyToolkit.ActivityLog("Starting self-patch process.");

                // Before we go far... lets see if there are any old temp files hanging around and get rid of them

                string[] oldFiles = Directory.GetFiles(Settings.GamePath, "*.old");
                foreach (string oldFile in oldFiles)
                {
                    try { File.Delete(oldFile); }
                    catch (Exception ex) { }
                }

                // OK now thats out of the way, lets determine if we need to self patch or not!!
                IEnumerable <XElement> launchers = m_manifest.Descendants("launcher");
                m_Status = "Self patching";
                foreach (XElement launcher in launchers)
                {
                    if (launcher.Attribute("id").Value == "Bourbon")
                    {
                        long size = 0;
                        long.TryParse(launcher.Attribute("size").Value.ToString(), out size);
                        string md5 = launcher.Attribute("md5").Value;

                        Fingerprint remoteLauncher = new Fingerprint(Settings.GamePath, "Bourbon.exe", md5, size);

                        if (!myFingerprint.Equals(remoteLauncher))
                        {
                            MyToolkit.ActivityLog("Patcher out of date...");

                            // We need to update!!! yay...
                            IEnumerable <XElement> urls = launcher.Descendants("url");

                            // Get every possible download URL into the remoteLauncher fingerprint
                            foreach (XElement url in urls)
                            {
                                remoteLauncher.AddDownloadURL(url.Value);
                            }


                            // Start the download process
                            HTTP selfPatcherClient = new HTTP();

                            m_DownloadSize = remoteLauncher.Size;
                            string downloadURL = remoteLauncher.DownloadURL;
                            MyToolkit.ActivityLog("Downloading new version from \"" + downloadURL + "\"");
                            if (selfPatcherClient.StartDownload(new AsyncCompletedEventHandler(DownloadFileComplete),
                                                                new DownloadProgressChangedEventHandler(dlProgress),
                                                                downloadURL,
                                                                remoteLauncher.FullName + ".download"))
                            {
                                m_Status         = "Downloading";
                                m_DownloadActive = true;
                            }

                            m_current = remoteLauncher.FullName;

                            // Wait until download is complete

                            MyToolkit.ActivityLog("Waiting for patcher download to complete...");
                            while (selfPatcherClient.Active)
                            {
                                if (Kill)
                                {
                                    selfPatcherClient.CancelDownload();
                                    return;
                                }
                                System.Threading.Thread.Sleep(10);
                            }
                            m_DownloadActive = false;
                            MyToolkit.ActivityLog("New patcher version downloaded...");

                            // Make sure the downloaded file is not corrupted

                            Fingerprint downloadedFile = new Fingerprint(remoteLauncher.RootPath, remoteLauncher.FileName + ".download");

                            if (!downloadedFile.Equals(remoteLauncher))
                            {
                                string error = "Was unable to self patch. Downloaded file did not match expected checksum.";
                                error += "\r\n" + remoteLauncher.FileName
                                         + "\r\n md5: " + remoteLauncher.Checksum + " vs " + downloadedFile.Checksum
                                         + "\r\n size: " + remoteLauncher.Size + " vs " + downloadedFile.Size;

                                MyToolkit.ActivityLog(error);

                                File.Delete(downloadedFile.FullName + ".download");
                                m_ErrorLog.Add(error);
                                m_Status = "Done";
                                return;
                            }
                            else
                            {
                                // Find an available _#.old file name
                                long   i         = 0;
                                string TrashName = myFingerprint.FullName + "_";
                                while (File.Exists(TrashName + i.ToString() + ".old"))
                                {
                                    i++;
                                }

                                TrashName = TrashName + i.ToString() + ".old";
                                File.Move(myFingerprint.FullName, TrashName);
                                File.Move(myFingerprint.FullName + ".download", myFingerprint.FullName);

                                var startInfo = new ProcessStartInfo();
                                startInfo.FileName  = myFingerprint.FullName;
                                startInfo.Arguments = MyToolkit.AllArgs();

                                MyToolkit.ActivityLog("Bourbon has been patched successfuly. Restarting.");

                                Process.Start(startInfo);

                                Application.Exit();
                                return;
                            }
                        }
                    }
                }

                MyToolkit.ActivityLog("Self patching process complete.");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "WorkThread.SelfPatch()");
            }
        }
Esempio n. 2
0
        private void ScanParameters()
        {
            if (MyToolkit.AllArgs().Trim() != "")
            {
                MyToolkit.ActivityLog("Launched with following parameters: " + MyToolkit.AllArgs());
            }

            for (int i = 0; i < MyToolkit.args.Length; i++)
            {
                // Check for parameters overriding the download of a new manifest
                if (MyToolkit.args[i].Trim() == "-o")
                {
                    WorkThread.DontDownloadManifest = true;
                }
                // Check for parameters overriding self patching
                else if (MyToolkit.args[i].Trim() == "-noselfpatch" ||
                         MyToolkit.args[i].Trim() == "-noselfupdate" ||
                         MyToolkit.args[i].Trim() == "-nodisassemblejohnny5")
                {
                    WorkThread.DontSelfUpdate = true;
                }
                // Check for parameters overriding self patching
                else if (MyToolkit.args[i].Trim() == "-md5")
                {
                    NoMove = true;
                    WorkThread.DontSelfUpdate = true;
                    //WorkThread.GenerageChecksumToClipboard = true;

                    Fingerprint myFingerprint = new Fingerprint(Application.StartupPath, Application.ExecutablePath.Replace(Application.StartupPath + "\\", ""));
                    Clipboard.SetText("md5=\"" + myFingerprint.Checksum + "\" size=\"" + myFingerprint.Size + "\"");
                }
                // Check for parameters disabling self relocate (this option also makes it not self patch)
                else if (MyToolkit.args[i].Trim() == "-nomove")
                {
                    NoMove = true;
                    WorkThread.DontSelfUpdate = true;
                }
                // Check for parameters disabling self relocate (this option also makes it not self patch)
                else if (MyToolkit.args[i].Trim() == "-devmode" ||
                         MyToolkit.args[i].Trim() == "-dev")
                {
                    DevMode = true;
                }
                // Pick up manifest download override
                else if (MyToolkit.args.Length > i + 1)
                {
                    if (MyToolkit.args[i].Trim() == "-m")
                    {
                        if (MyToolkit.args[i + 1].Trim() == "")
                        {
                            MessageBox.Show("No manifest specified in parameter -m, using default.");
                        }
                        else
                        {
                            ManifestURL = MyToolkit.args[i + 1];

                            // Get a list of currently registered manifests                                 //
                            List <string> Manifests = Settings.Manifests;

                            // Find out if this manifest is already in the list                             //
                            bool ManifestExists = false;
                            foreach (string Manifest in Manifests)
                            {
                                if (Manifest.Equals(ManifestURL, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    ManifestExists = true;
                                    break;
                                }
                            }

                            // If manifest is not in the list, add it                                       //
                            if (!ManifestExists)
                            {
                                Manifests.Add(ManifestURL);
                                Settings.Manifests = Manifests;
                            }

                            // Make this the default manifest                                               //
                            Settings.LastManifest = ManifestURL;
                        }
                    }
                }
            }
        }