private void ThreadDisplayError(PatcherErrorMessage error, CancellationToken cancellationToken)
        {
            PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherFailed);

            try
            {
                _state.Value = PatcherState.DisplayingError;

                DebugLogger.Log(string.Format("Displaying patcher error {0}...", error.Message));

                ErrorDialog.Display(error, cancellationToken);

                DebugLogger.Log(string.Format("Patcher error {0} displayed.", error.Message));
            }
            catch (OperationCanceledException)
            {
                DebugLogger.Log(string.Format("Displaying patcher error {0} cancelled.", _userDecision));
            }
            catch (ThreadInterruptedException)
            {
                DebugLogger.Log(string.Format("Displaying patcher error {0} interrupted: thread has been interrupted. Rethrowing exception.", error.Message));
                throw;
            }
            catch (ThreadAbortException)
            {
                DebugLogger.Log(string.Format("Displaying patcher error {0} aborted: thread has been aborted. Rethrowing exception.", error.Message));
                throw;
            }
            catch (Exception)
            {
                DebugLogger.LogWarning(string.Format("Error while displaying patcher error {}: an exception has occured. Rethrowing exception.", error.Message));
                throw;
            }
        }
        private IEnumerator ForceQuit()
        {
            if (_isForceQuitting)
            {
                yield break;
            }

            _isForceQuitting = true;

            try
            {
                _canStartThread = false;

                CloseLockFile();

                yield return(StartCoroutine(KillThread()));

                if (_wasUpdateSuccessfulOrNotNecessary && !_hasGameBeenStarted)
                {
                    yield return(StartCoroutine(PatcherStatistics.SendEvent(PatcherStatistics.Event.PatcherSucceededClosed)));
                }

                if (!Application.isEditor)
                {
                    Process.GetCurrentProcess().Kill();
                }
            }
            finally
            {
                _isForceQuitting = false;
            }
        }
        private void ThreadStartApp()
        {
            _state.Value = PatcherState.StartingApp;

            var appStarter = new AppStarter(_app);

            appStarter.Start();

            PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherSucceededGameStarted);
            _hasGameBeenStarted = true;

            UnityDispatcher.Invoke(Quit);
        }
        private void ThreadUpdateApp(bool automatically, CancellationToken cancellationToken)
        {
            _state.Value = PatcherState.Connecting;

            _updateAppCancellationTokenSource = new PatchKit.Unity.Patcher.Cancellation.CancellationTokenSource();

            using (cancellationToken.Register(() => _updateAppCancellationTokenSource.Cancel()))
            {
                _appInfo.Value         = _app.RemoteMetaData.GetAppInfo(!automatically, _updateAppCancellationTokenSource.Token);
                _remoteVersionId.Value = _app.GetLatestVersionId(!automatically, _updateAppCancellationTokenSource.Token);
                if (_app.IsFullyInstalled())
                {
                    _localVersionId.Value = _app.GetInstalledVersionId();
                }

                var appUpdater = new AppUpdater.AppUpdater(new AppUpdaterContext(_app, _configuration.AppUpdaterConfiguration));

                try
                {
                    _updaterStatus.Value = appUpdater.Status;

                    using (_updaterStatus.Take(1).Subscribe((status) => _state.Value = PatcherState.UpdatingApp))
                    {
                        appUpdater.Update(_updateAppCancellationTokenSource.Token);
                        _wasUpdateSuccessfulOrNotNecessary = true;
                    }
                }
                catch (OperationCanceledException)
                {
                    PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherCanceled);

                    throw;
                }
                finally
                {
                    _state.Value = PatcherState.None;

                    _updaterStatus.Value = null;
                    _updateAppCancellationTokenSource = null;
                }
            }
        }
        private void ThreadExecution(CancellationToken cancellationToken)
        {
            try
            {
                _state.Value = PatcherState.None;

                DebugLogger.Log("Patcher thread started.");

                try
                {
                    ThreadLoadPatcherData();
                }
                catch (NonLauncherExecutionException)
                {
                    try
                    {
                        LauncherUtilities.ExecuteLauncher();
                        return;
                    }
                    catch (ApplicationException)
                    {
                        ThreadDisplayError(PatcherErrorMessage.NonLauncherExecution(), cancellationToken);
                        return;
                    }
                    finally
                    {
                        Quit();
                    }
                }

                EnsureSingleInstance();

                ThreadLoadPatcherConfiguration();

                UnityDispatcher.Invoke(() => _app = new App(_data.Value.AppDataPath, _data.Value.AppSecret, _data.Value.OverrideLatestVersionId, _requestTimeoutCalculator)).WaitOne();

                PatcherStatistics.TryDispatchSendEvent(PatcherStatistics.Event.PatcherStarted);

                while (true)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    ThreadWaitForUserDecision(cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();

                    ThreadExecuteUserDecision(cancellationToken);
                }
            }
            catch (OperationCanceledException)
            {
                DebugLogger.Log("Patcher thread finished: thread has been cancelled.");
            }
            catch (ThreadInterruptedException)
            {
                DebugLogger.Log("Patcher thread finished: thread has been interrupted.");
            }
            catch (ThreadAbortException)
            {
                DebugLogger.Log("Patcher thread finished: thread has been aborted.");
            }
            catch (MultipleInstancesException exception)
            {
                DebugLogger.LogException(exception);
                Quit();
            }
            catch (Exception exception)
            {
                DebugLogger.LogError("Patcher thread failed: an exception has occured.");
                DebugLogger.LogException(exception);
            }
            finally
            {
                _state.Value = PatcherState.None;
            }
        }
Beispiel #6
0
 public static void DispatchSendEvent(Event ev, OptionalParams?parameters = null)
 {
     UnityDispatcher.InvokeCoroutine(PatcherStatistics.SendEvent(ev, parameters));
 }