Пример #1
0
        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");
            }
        }
Пример #2
0
        private IEnumerator CheckForUpdates(MultiGameLauncherGameHolder gameHolder)
        {
            if (string.IsNullOrEmpty(gameHolder.Configuration.VersionInfoURL))
            {
                yield break;
            }

            // Check if there are any updates for the game
            SimplePatchTool patcher = InitializePatcher(Path.Combine(gamesDirectory, gameHolder.Configuration.Subdirectory), gameHolder.Configuration.VersionInfoURL);

            // = 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(true))
            {
                while (patcher.IsRunning)
                {
                    yield return(null);
                }

                if (patcher.Result == PatchResult.Success)
                {
                    Debug.Log("There is an update for " + gameHolder.Configuration.Name);
                    gameHolder.PatchButtonSetVisible(true);
                }
            }
            else
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }
Пример #3
0
        private void StartLauncherPatch()
        {
            if (string.IsNullOrEmpty(launcherVersionInfoURL))
            {
                return;
            }

            SimplePatchTool patcher         = InitializePatcher(launcherDirectory, launcherVersionInfoURL);
            PatcherListener patcherListener = new PatcherListener();

            patcherListener.OnVersionInfoFetched += (versionInfo) => versionInfo.AddIgnoredPath(gamesSubdirectory + "/");
            patcherListener.OnVersionFetched     += (currVersion, newVersion) => versionCodeText.text = "v" + currVersion;
            patcherListener.OnFinish             += () =>
            {
                if (patcher.Result == PatchResult.Success)
                {
                    updateLauncherPanel.gameObject.SetActive(true);
                    updateLauncherButton.onClick.AddListener(() => patcher.ApplySelfPatch(selfPatcherPath, PatchUtils.GetCurrentExecutablePath()));
                }
                else if (patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    Debug.Log("Launcher is up-to-date!");
                }
                else
                {
                    Debug.LogError("Something went wrong with launcher's patch: " + patcher.FailDetails);
                }
            };

            if (!patcher.SetListener(patcherListener).Run(true))                  // true: Self patching
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }
Пример #4
0
        private bool StartMainAppPatch(bool checkForUpdates)
        {
            if (string.IsNullOrEmpty(MAINAPP_VERSIONINFO_URL))
            {
                return(false);
            }

            if (patcher != null && patcher.IsRunning)
            {
                return(false);
            }

            isPatchingLauncher = false;

            patcher = new SimplePatchTool(mainAppDirectory, MAINAPP_VERSIONINFO_URL).UseRepairPatch(true).UseIncrementalPatch(true);

            if (checkForUpdates)
            {
                CheckForUpdates(true);
            }
            else
            {
                ExecutePatch();
            }

            return(true);
        }
Пример #5
0
        private static void WaitForPatcher(SimplePatchTool patcher)
        {
            while (patcher.IsRunning)
            {
                Thread.Sleep(100);
                LogPatcherToConsole(patcher);
            }

            LogPatcherToConsole(patcher);
        }
 private void OnDestroy()
 {
     if (patcher != null)
     {
         // Stop the patcher since this script can no longer control it
         patcher.SetListener(null);
         patcher.Cancel();
         patcher = null;
     }
 }
Пример #7
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!");
            }
        }
Пример #8
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));
        }
Пример #9
0
        public static PatcherWaitForFinishHandle CheckForUpdatesCoroutine(this SimplePatchTool patcher, bool checkVersionOnly = true)
        {
            if (patcher == null)
            {
                return(null);
            }

            if (!patcher.IsRunning && !patcher.CheckForUpdates(checkVersionOnly))
            {
                return(null);
            }

            return(new PatcherWaitForFinishHandle(patcher));
        }
Пример #10
0
        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));
            }
        }
Пример #11
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));
            }
        }
Пример #12
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!");
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        private static void CheckForUpdates()
        {
            bool   silent             = HasArgument("silent");
            string versionInfoKeyPath = GetArgument("versionInfoKey");

            SimplePatchTool patcher = new SimplePatchTool(GetArgument("root"), GetArgument("versionURL")).SilentMode(silent);

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

            bool hasStarted = patcher.CheckForUpdates(HasArgument("checkVersionOnly"));

            if (hasStarted)
            {
                while (patcher.IsRunning)
                {
                    Thread.Sleep(100);

                    string log = patcher.FetchLog();
                    while (log != null)
                    {
                        LogToConsole(log);
                        log = patcher.FetchLog();
                    }
                }

                if (patcher.Result == PatchResult.Failed)
                {
                    Console.WriteLine("\nOperation failed: " + patcher.FailReason + " " + (patcher.FailDetails ?? ""));
                }
                else if (patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    Console.WriteLine("\nAlready up-to-date!");
                }
                else
                {
                    Console.WriteLine("\nThere is an update!");
                }
            }
            else
            {
                Console.WriteLine("\nCould not check for updates; maybe an operation is already running?");
            }
        }
Пример #15
0
        private static void LogPatcherToConsole(SimplePatchTool patcher)
        {
            string log = patcher.FetchLog();

            while (log != null)
            {
                LogToConsole(log);
                log = patcher.FetchLog();
            }

            IOperationProgress progress = patcher.FetchProgress();

            if (progress != null)
            {
                LogToConsole(progress.ProgressInfo);
            }
        }
Пример #16
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?");
            }
        }
Пример #17
0
        public void Initialize(SimplePatchTool patcher)
        {
            if (patcher == null)
            {
                return;
            }

            patchPanel.SetActive(true);
            patchResultPanel.SetActive(false);

            logText.text            = string.Empty;
            progressText.text       = string.Empty;
            progressSlider.value    = 0f;
            patcherButtonLabel.text = "Cancel";

            Patcher = patcher;
            StartCoroutine(PatchCoroutine());
        }
Пример #18
0
        private bool StartLauncherPatch()
        {
            if (string.IsNullOrEmpty(LAUNCHER_VERSIONINFO_URL))
            {
                return(false);
            }

            if (patcher != null && patcher.IsRunning)
            {
                return(false);
            }

            isPatchingLauncher = true;

            patcher = new SimplePatchTool(launcherDirectory, LAUNCHER_VERSIONINFO_URL).UseRepairPatch(true).UseIncrementalPatch(true);
            CheckForUpdates(false);

            return(true);
        }
Пример #19
0
        public void Initialize(SimplePatchTool patcher, string selfPatcherExecutable = "SelfPatcher.exe")
        {
            if (patcher == null)
            {
                return;
            }

            patchPanel.SetActive(true);
            patchResultPanel.SetActive(false);

            logText.text                = string.Empty;
            progressText.text           = string.Empty;
            progressSlider.value        = 0f;
            overallProgressSlider.value = 0f;
            patcherButtonLabel.text     = "Cancel";

            Patcher = patcher;
            this.selfPatcherExecutable = selfPatcherExecutable;

            StartCoroutine(PatchCoroutine());
        }
Пример #20
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);
        }
Пример #21
0
        private void ExecutePatch(MultiGameLauncherGameHolder gameHolder)
        {
            if (string.IsNullOrEmpty(gameHolder.Configuration.VersionInfoURL))
            {
                return;
            }

            SimplePatchTool patcher         = InitializePatcher(Path.Combine(gamesDirectory, gameHolder.Configuration.Subdirectory), gameHolder.Configuration.VersionInfoURL);
            PatcherListener patcherListener = new PatcherListener();

            patcherListener.OnLogReceived += (log) =>
            {
                if (logToConsole)
                {
                    Debug.Log(log);
                }

                patcherLogText.text = log;
            };
            patcherListener.OnProgressChanged += (progress) =>
            {
                if (logToConsole)
                {
                    Debug.Log(string.Concat(progress.Percentage, "% ", progress.ProgressInfo));
                }

                patcherProgressText.text = progress.ProgressInfo;
                patcherProgressbar.value = progress.Percentage;
            };
            patcherListener.OnOverallProgressChanged += (progress) => patcherOverallProgressbar.value = progress.Percentage;
            patcherListener.OnFinish += () =>
            {
                HidePatcherProgressPanel();

                for (int i = 0; i < gameHolders.Length; i++)
                {
                    gameHolders[i].PatchButtonSetEnabled(true);
                }

                if (patcher.Result == PatchResult.Success || patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    Debug.Log(gameHolder.Configuration.Name + " is " + (patcher.Result == PatchResult.Success ? "patched!" : "already up-to-date"));
                    gameHolder.PlayButtonSetEnabled(true);
                    gameHolder.PatchButtonSetVisible(false);
                }
                else
                {
                    Debug.LogError("Something went wrong with " + gameHolder.Configuration.Name + "'s patch: " + patcher.FailDetails);
                }
            };

            if (patcher.SetListener(patcherListener).Run(false))                  // false: Not self patching
            {
                ShowPatcherProgressPanel();

                for (int i = 0; i < gameHolders.Length; i++)
                {
                    gameHolders[i].PatchButtonSetEnabled(false);
                }

                gameHolder.PlayButtonSetEnabled(false);
            }
            else
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }
Пример #22
0
 public PatcherWaitForFinishHandle(SimplePatchTool patcher)
 {
     this.patcher = patcher;
 }