Ejemplo n.º 1
0
        private IEnumerator ExecutePatch()
        {
            patchButton.interactable = false;
            playButton.interactable  = false;

            patcher.LogProgress(true);
            if (patcher.Run(isPatchingLauncher))
            {
                Debug.Log("Executing patch...");

                while (patcher.IsRunning)
                {
                    FetchLogsFromPatcher();
                    yield return(null);
                }

                FetchLogsFromPatcher();
                playButton.interactable = true;

                if (patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    // If launcher is already up-to-date, check if there is an update for the main app
                    if (isPatchingLauncher)
                    {
                        StartMainAppPatch(true);
                    }
                }
                else if (patcher.Result == PatchResult.Success)
                {
                    // If patcher was self patching the launcher, start the self patcher executable
                    // Otherwise, we have just updated the main app successfully!
                    if (patcher.Operation == PatchOperation.SelfPatching)
                    {
                        string selfPatcherPath = SPTUtils.SelfPatcherExecutablePath;
                        if (!string.IsNullOrEmpty(selfPatcherPath) && File.Exists(selfPatcherPath))
                        {
                            patcher.ApplySelfPatch(selfPatcherPath, PatchUtils.GetCurrentExecutablePath());
                        }
                        else
                        {
                            patcherLogText.text = "Self patcher does not exist!";
                        }
                    }
                }
                else
                {
                    // An error occurred, user can click the Patch button to try again
                    patchButton.interactable = true;
                }
            }
            else
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }
Ejemplo n.º 2
0
 private void ExecutePatch()
 {
     if (patcher.Operation == PatchOperation.ApplyingSelfPatch)
     {
         ApplySelfPatch();
     }
     else if (patcher.Run(isPatchingLauncher))
     {
         ButtonSetEnabled(patchButton, false);
         ButtonSetEnabled(playButton, false);
     }
 }
Ejemplo n.º 3
0
        private void PatchButtonClicked()
        {
            bool isPatcherActive = runningPatcher != null && !runningPatcher.Equals(null);

            if (!isPatcherActive || !runningPatcher.Patcher.IsRunning)
            {
#if UNITY_EDITOR
                if (selfPatchingInput.isOn)
                {
                    Debug.LogWarning("Can't self patch while testing on editor");
                    selfPatchingInput.isOn = false;
                }
#endif

                SimplePatchTool patcher = new SimplePatchTool(rootPathInput.text, versionInfoURLInput.text).
                                          UseRepair(repairInput.isOn).UseIncrementalPatch(incrementalPatchInput.isOn).
                                          UseCustomDownloadHandler(() => new CookieAwareWebClient()). // to support https in Unity
                                          UseCustomFreeSpaceCalculator((drive) => long.MaxValue).     // DriveInfo.AvailableFreeSpace is not supported on Unity
                                          LogProgress(true);

                if (versionInfoVerifier != null)
                {
                    string versionInfoRSA = versionInfoVerifier.text;
                    patcher.UseVersionInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, versionInfoRSA));
                }

                if (patchInfoVerifier != null)
                {
                    string patchInfoRSA = patchInfoVerifier.text;
                    patcher.UsePatchInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, patchInfoRSA));
                }

                if (patcher.Run(selfPatchingInput.isOn))
                {
                    Debug.Log("Started patching...");
                    if (!isPatcherActive)
                    {
                        runningPatcher = Instantiate(patcherUiPrefab);
                    }

                    runningPatcher.Initialize(patcher);
                }
                else
                {
                    Debug.Log("Operation could not be started; maybe it is already executing?");
                }
            }
            else
            {
                Debug.LogWarning("An instance of SimplePatchTool is already running, cancel/dismiss it first!");
            }
        }
Ejemplo n.º 4
0
        private void ExecutePatch()
        {
            StartThread(() =>
            {
                ButtonSetEnabled(patchButton, false);
                ButtonSetEnabled(playButton, false);

                patcher.LogProgress(true);
                if (patcher.Run(isPatchingLauncher))
                {
                    while (patcher.IsRunning)
                    {
                        FetchLogsFromPatcher();
                        Thread.Sleep(500);
                    }

                    FetchLogsFromPatcher();
                    ButtonSetEnabled(playButton, true);

                    if (patcher.Result == PatchResult.AlreadyUpToDate)
                    {
                        // If launcher is already up-to-date, check if there is an update for the main app
                        if (isPatchingLauncher)
                        {
                            StartMainAppPatch(true);
                        }
                    }
                    else if (patcher.Result == PatchResult.Success)
                    {
                        // If patcher was self patching the launcher, start the self patcher executable
                        // Otherwise, we have just updated the main app successfully!
                        if (patcher.Operation == PatchOperation.SelfPatching)
                        {
                            if (!string.IsNullOrEmpty(selfPatcherExecutablePath) && File.Exists(selfPatcherExecutablePath))
                            {
                                patcher.ApplySelfPatch(selfPatcherExecutablePath, PatchUtils.GetCurrentExecutablePath());
                            }
                            else
                            {
                                UpdateLabel(progressText, "Self patcher does not exist!");
                            }
                        }
                    }
                    else
                    {
                        // An error occurred, user can click the Patch button to try again
                        ButtonSetEnabled(patchButton, true);
                    }
                }
            });
        }
Ejemplo n.º 5
0
        public static PatcherWaitForFinishHandle RunCoroutine(this SimplePatchTool patcher, bool selfPatching)
        {
            if (patcher == null)
            {
                return(null);
            }

            if (!patcher.IsRunning && !patcher.Run(selfPatching))
            {
                return(null);
            }

            return(new PatcherWaitForFinishHandle(patcher));
        }
Ejemplo n.º 6
0
        private void PatchButtonClicked()
        {
            bool isPatcherActive = runningPatcher != null && !runningPatcher.Equals(null);

            if (!isPatcherActive || !runningPatcher.Patcher.IsRunning)
            {
#if UNITY_EDITOR
                if (selfPatchingInput.isOn)
                {
                    Debug.LogWarning("Can't self patch while testing on editor");
                    selfPatchingInput.isOn = false;
                }
#endif

                SimplePatchTool patcher = SPTUtils.CreatePatcher(rootPathInput.text, versionInfoURLInput.text).
                                          UseRepairPatch(repairPatchInput.isOn).UseIncrementalPatch(incrementalPatchInput.isOn).UseInstallerPatch(installerPatchInput.isOn).
                                          VerifyFilesOnServer(verifyServerFilesInput.isOn).CheckForMultipleRunningInstances(checkMultipleInstancesInput.isOn);

                if (!string.IsNullOrEmpty(versionInfoRSA))
                {
                    patcher.UseVersionInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, versionInfoRSA));
                }

                if (!string.IsNullOrEmpty(patchInfoRSA))
                {
                    patcher.UsePatchInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, patchInfoRSA));
                }

                if (patcher.Run(selfPatchingInput.isOn))
                {
                    Debug.Log("Started patching...");
                    if (!isPatcherActive)
                    {
                        runningPatcher = Instantiate(patcherUiPrefab);
                    }

                    runningPatcher.Initialize(patcher, selfPatcherExecutable);
                }
                else
                {
                    Debug.Log("Operation could not be started; maybe it is already executing?");
                }
            }
            else
            {
                Debug.LogWarning("An instance of SimplePatchTool is already running, cancel/dismiss it first!");
            }
        }
Ejemplo n.º 7
0
        private void UpdateButtonClicked()
        {
            if (patcher != null && !patcher.IsRunning && patcher.Operation == PatchOperation.CheckingForUpdates && patcher.Result == PatchResult.Success)
            {
                if (patcher.Run(true))                                                       // Start patching in self patching mode
                {
                    Instantiate(patcherUiPrefab).Initialize(patcher, selfPatcherExecutable); // Show progress on a PatcherUI instance
                }
                else
                {
                    Debug.LogError("Something went wrong");
                }
            }

            Destroy(gameObject);
        }
Ejemplo n.º 8
0
        private static void ApplyPatch()
        {
            bool   silent             = HasArgument("silent");
            string versionInfoKeyPath = GetArgument("versionInfoKey");
            string patchInfoKeyPath   = GetArgument("patchInfoKey");

            SimplePatchTool patcher = new SimplePatchTool(GetArgument("root"), GetArgument("versionURL")).
                                      UseIncrementalPatch(!HasArgument("dontUseIncrementalPatch")).UseRepairPatch(!HasArgument("dontUseRepairPatch")).
                                      CheckForMultipleRunningInstances(false).VerifyFilesOnServer(HasArgument("verifyFiles")).LogProgress(!silent).SilentMode(silent);

            if (versionInfoKeyPath != null)
            {
                string publicKey = File.ReadAllText(versionInfoKeyPath);
                patcher.UseVersionInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, publicKey));
            }

            if (patchInfoKeyPath != null)
            {
                string publicKey = File.ReadAllText(patchInfoKeyPath);
                patcher.UsePatchInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, publicKey));
            }

            bool hasPatchStarted = patcher.Run(false);

            if (hasPatchStarted)
            {
                WaitForPatcher(patcher);

                if (patcher.Result == PatchResult.Failed)
                {
                    Console.WriteLine("\nPatch failed: " + patcher.FailReason + " " + (patcher.FailDetails ?? ""));
                }
                else if (patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    Console.WriteLine("\nAlready up-to-date!");
                }
                else
                {
                    Console.WriteLine("\nPatch is successful!");
                }
            }
            else
            {
                Console.WriteLine("\nPatch could not be started; maybe it is already executing?");
            }
        }
Ejemplo n.º 9
0
        private void ExecutePatch()
        {
            if (patcher.Operation == PatchOperation.ApplyingSelfPatch)
            {
                ApplySelfPatch();
            }
            else if (patcher.Run(isPatchingLauncher))
            {
                Debug.Log("Executing patch...");

                patchButton.interactable = false;
                playButton.interactable  = false;
            }
            else
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }