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?");
            }
        }
        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?");
            }
        }
        private void Awake()
        {
            if (isEditor)
            {
                Debug.LogWarning("Can't test the launcher on Editor!");
                Destroy(this);

                return;
            }

            launcherVersionInfoURL = launcherVersionInfoURL.Trim();
            mainAppVersionInfoURL  = mainAppVersionInfoURL.Trim();
            patchNotesURL          = patchNotesURL.Trim();
            forumURL       = forumURL.Trim();
            websiteURL     = websiteURL.Trim();
            versionInfoRSA = versionInfoRSA.Trim();
            patchInfoRSA   = patchInfoRSA.Trim();

            patchNotesText.text             = "";
            patcherLogText.text             = "";
            patcherProgressText.text        = "";
            patcherProgressbar.value        = 0;
            patcherOverallProgressbar.value = 0;

            patchButton.onClick.AddListener(PatchButtonClicked);
            repairButton.onClick.AddListener(RepairButtonClicked);
            playButton.onClick.AddListener(PlayButtonClicked);
            forumButton.onClick.AddListener(ForumButtonClicked);
            websiteButton.onClick.AddListener(WebsiteButtonClicked);

            launcherDirectory = Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath());
            mainAppDirectory  = Path.Combine(launcherDirectory, mainAppSubdirectory);
            selfPatcherPath   = PatchUtils.GetDefaultSelfPatcherExecutablePath(selfPatcherExecutable);

            string currentVersion = PatchUtils.GetCurrentAppVersion();

            versionCodeText.text = string.IsNullOrEmpty(currentVersion) ? "" : ("v" + currentVersion);

            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.OnVersionInfoFetched     += (versionInfo) =>
            {
                if (isPatchingLauncher)
                {
                    versionInfo.AddIgnoredPath(mainAppSubdirectory + "/");
                }
            };
            patcherListener.OnVersionFetched += (currVersion, newVersion) =>
            {
                if (isPatchingLauncher)
                {
                    versionCodeText.text = "v" + currVersion;
                }
            };
            patcherListener.OnFinish += () =>
            {
                if (patcher.Operation == PatchOperation.CheckingForUpdates)
                {
                    CheckForUpdatesFinished();
                }
                else
                {
                    PatchFinished();
                }
            };

            if (!string.IsNullOrEmpty(patchNotesURL))
            {
                StartCoroutine(FetchPatchNotes());
            }

            if (!StartLauncherPatch())
            {
                StartMainAppPatch(true);
            }
        }
Exemple #4
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);
        }