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?");
            }
        }
        private void PatchButtonClicked(MultiGameLauncherGameHolder gameHolder)
        {
#if UNITY_EDITOR
            Debug.LogWarning("Can't test the launcher on Editor!");
            return;
#else
            ExecutePatch(gameHolder);
#endif
        }
        private void Awake()
        {
            launcherVersionInfoURL = launcherVersionInfoURL.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;

            forumButton.onClick.AddListener(ForumButtonClicked);
            websiteButton.onClick.AddListener(WebsiteButtonClicked);

            launcherDirectory = Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath());
            gamesDirectory    = Path.Combine(launcherDirectory, gamesSubdirectory);
            selfPatcherPath   = PatchUtils.GetDefaultSelfPatcherExecutablePath(selfPatcherExecutable);

            string currentVersion = PatchUtils.GetCurrentAppVersion();

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

            gameHolders = new MultiGameLauncherGameHolder[games.Length];
            for (int i = 0; i < games.Length; i++)
            {
                games[i].TrimLinks();

                MultiGameLauncherGameHolder gameHolder = (MultiGameLauncherGameHolder)Instantiate(gameHolderPrefab, gameHolderParent, false);
                gameHolder.Initialize(games[i]);
                gameHolder.OnPlayButtonClicked  += PlayButtonClicked;
                gameHolder.OnPatchButtonClicked += PatchButtonClicked;
                gameHolder.PlayButtonSetEnabled(File.Exists(Path.Combine(gamesDirectory, games[i].ExecutablePath)));
                gameHolders[i] = gameHolder;

                StartCoroutine(CheckForUpdates(gameHolder));
            }

            // To resolve a Unity bug
            gamesPanel.gameObject.SetActive(false);
            gamesPanel.gameObject.SetActive(true);

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

            // Can't test the launcher on Editor
#if !UNITY_EDITOR
            StartLauncherPatch();
#endif
        }
        private void PlayButtonClicked(MultiGameLauncherGameHolder gameHolder)
        {
            FileInfo game = new FileInfo(Path.Combine(gamesDirectory, gameHolder.Configuration.ExecutablePath));

            if (game.Exists)
            {
                Process.Start(new ProcessStartInfo(game.FullName)
                {
                    WorkingDirectory = game.DirectoryName
                });
            }
            else
            {
                Debug.LogError(game.FullName + " does not exist!");
            }
        }
        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?");
            }
        }
Beispiel #6
0
 private void PatchButtonClicked(MultiGameLauncherGameHolder gameHolder)
 {
     ExecutePatch(gameHolder);
 }