private void InitializePatcher()
        {
            patcher = SPTUtils.CreatePatcher(Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath()), versionInfoURL);

            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));
            }

            // = checkVersionOnly =
            // true (default): only version number (e.g. 1.0) is compared against VersionInfo to see if there is an update
            // false: hashes and sizes of the local files are compared against VersionInfo (if there are any different/missing files, we'll patch the app)
            if (patcher.CheckForUpdates(checkVersionOnly))
            {
                StartCoroutine(CheckForUpdatesCoroutine());
            }
            else
            {
                Debug.LogError("Something went wrong");
            }
        }
Exemple #2
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!");
            }
        }
Exemple #3
0
        private void InitializePatcher(string rootPath, string versionInfoURL)
        {
            patcher = SPTUtils.CreatePatcher(rootPath, versionInfoURL).UseRepairPatch(true).UseIncrementalPatch(true).LogProgress(true);

            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));
            }
        }
        private void InitializePatcher(string rootPath, string versionInfoURL)
        {
            patcher = SPTUtils.CreatePatcher(rootPath, versionInfoURL).SetListener(patcherListener);

            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));
            }
        }
        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!");
            }
        }
        private SimplePatchTool InitializePatcher(string rootPath, string versionInfoURL)
        {
            SimplePatchTool patcher = SPTUtils.CreatePatcher(rootPath, versionInfoURL);

            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));
            }

            return(patcher);
        }
        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?");
            }
        }
Exemple #8
0
        private void InitializePatcher()
        {
            if (m_patcher != null)
            {
                return;
            }

            m_patcher = SPTUtils.CreatePatcher(RootPath, VersionInfoURL).CheckForMultipleRunningInstances(CheckForMultipleRunningInstances).
                        UseRepairPatch(UseRepairPatch).UseIncrementalPatch(UseIncrementalPatch).UseInstallerPatch(UseInstallerPatch).
                        VerifyFilesOnServer(VerifyFilesOnServer).SilentMode(SilentMode).LogProgress(LogProgress).LogToFile(LogToFile);

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

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

            PatcherListener listener = new PatcherListener();

            listener.OnStart += () =>
            {
                if (m_patcher.Operation == PatchOperation.CheckingForUpdates)
                {
                    CheckForUpdatesStarted.Invoke();
                }
                else if (m_patcher.Operation == PatchOperation.Patching || m_patcher.Operation == PatchOperation.SelfPatching)
                {
                    PatchStarted.Invoke();
                }
            };
            listener.OnLogReceived += (log) =>
            {
                LogReceived.Invoke(log);

                if (LogToConsole)
                {
                    Debug.Log(log);
                }
            };
            listener.OnProgressChanged += (progress) =>
            {
                CurrentProgressPercentageChanged.Invoke(progress.Percentage);
                CurrentProgressTextChanged.Invoke(progress.ProgressInfo);
            };
            listener.OnOverallProgressChanged += (progress) =>
            {
                OverallProgressPercentageChanged.Invoke(progress.Percentage);
                OverallProgressTextChanged.Invoke(progress.ProgressInfo);
            };
            listener.OnPatchStageChanged  += PatchStageChanged.Invoke;
            listener.OnPatchMethodChanged += PatchMethodChanged.Invoke;
            listener.OnVersionInfoFetched += (versionInfo) =>
            {
                for (int i = 0; i < AdditionalIgnoredPaths.Length; i++)
                {
                    if (!string.IsNullOrEmpty(AdditionalIgnoredPaths[i]))
                    {
                        versionInfo.AddIgnoredPath(AdditionalIgnoredPaths[i]);
                    }
                }

                VersionInfoFetched.Invoke(versionInfo);
            };
            listener.OnVersionFetched += (currentVersion, newVersion) =>
            {
                CurrentVersionDetermined.Invoke(currentVersion);
                NewVersionDetermined.Invoke(newVersion);
            };
            listener.OnFinish += () =>
            {
                if (m_patcher.Operation == PatchOperation.CheckingForUpdates)
                {
                    if (m_patcher.Result == PatchResult.AlreadyUpToDate)
                    {
                        AppIsUpToDate.Invoke();
                    }
                    else if (m_patcher.Result == PatchResult.Success)
                    {
                        UpdateAvailable.Invoke();
                    }
                    else
                    {
                        CheckForUpdatesFailed.Invoke(m_patcher.FailDetails);

                        if (LogToConsole)
                        {
                            Debug.LogError(m_patcher.FailDetails);
                        }
                    }
                }
                else if (m_patcher.Operation == PatchOperation.Patching || m_patcher.Operation == PatchOperation.SelfPatching)
                {
                    if (m_patcher.Result == PatchResult.AlreadyUpToDate)
                    {
                        AppIsUpToDate.Invoke();
                    }
                    else if (m_patcher.Result == PatchResult.Success)
                    {
                        PatchSuccessful.Invoke();

                        if (m_patcher.Operation == PatchOperation.Patching)
                        {
                            CurrentVersionDetermined.Invoke(m_patcher.NewVersion);
                        }
                    }
                    else
                    {
                        PatchFailed.Invoke(m_patcher.FailDetails);

                        if (LogToConsole)
                        {
                            Debug.LogError(m_patcher.FailDetails);
                        }
                    }
                }
                else
                {
                    if (m_patcher.Result == PatchResult.AlreadyUpToDate)
                    {
                        AppIsUpToDate.Invoke();
                    }
                    else if (m_patcher.Result == PatchResult.Failed)
                    {
                        SelfPatchingFailed.Invoke(m_patcher.FailDetails);

                        if (LogToConsole)
                        {
                            Debug.LogError(m_patcher.FailDetails);
                        }
                    }
                }
            };

            m_patcher.SetListener(listener);
        }