Exemplo n.º 1
0
 public async Task TryUpdaterActionAsync(Func <Task> action, string task)
 {
     try {
         await action().ConfigureAwait(false);
     } catch (UserDeclinedLicenseException e) {} catch (LicenseRetrievalException e) {
         await UserErrorHandler.HandleUserError(new InformationalUserError(e,
                                                                           "One or more mod licenses failed to download and display correctly.",
                                                                           "Mod license retrieval failed during " + task));
     } catch (HostListExhausted e) {
         await DealWithUpdateException(e, task);
     } catch (ChecksumException e) {
         await DealWithUpdateException(e, task);
     } catch (IOException e) {
         if (await DealWithUpdateException(e, task))
         {
             await UserErrorHandler.HandleUserError(new InformationalUserError(e, "A problem occurred during " + task, null));
         }
     } catch (UnauthorizedAccessException e) {
         if (await DealWithUpdateException(e, task))
         {
             await UserErrorHandler.HandleUserError(new InformationalUserError(e, "A problem occurred during " + task, null));
         }
     } catch (Exception e) {
         if (!_busyStateHandler.IsAborted)
         {
             await UserErrorHandler.HandleUserError(new InformationalUserError(e, "A problem occurred during " + task, null));
         }
     }
 }
Exemplo n.º 2
0
        async Task <bool> TryCheckUac(IAbsoluteDirectoryPath mp, IAbsoluteFilePath path)
        {
            Exception ex;

            try {
                mp.MakeSurePathExists();
                if (path.Exists)
                {
                    File.Delete(path.ToString());
                }
                using (File.CreateText(path.ToString())) {}
                File.Delete(path.ToString());
                return(false);
            } catch (UnauthorizedAccessException e) {
                ex = e;
            } catch (Exception e) {
                this.Logger().FormattedWarnException(e);
                return(false);
            }

            var report = await UserErrorHandler.HandleUserError(new UserErrorModel("Restart the application elevated?",
                                                                                   $"The application failed to write to the path, probably indicating permission issues\nWould you like to restart the application Elevated?\n\n {mp}",
                                                                                   RecoveryCommands.YesNoCommands, null, ex)) == RecoveryOptionResultModel.RetryOperation;

            if (!report)
            {
                return(false);
            }
            RestartWithUacInclEnvironmentCommandLine();
            return(true);
        }
Exemplo n.º 3
0
        async Task TryLaunchWebserver()
        {
retry:
            try {
                var t = SetupWebServer();
            } catch (CannotOpenApiPortException ex) {
                var r = await
                        UserErrorHandler.RecoverableUserError(ex, "Unable to open required ports",
                                                              "We were unable to open the required port for the website to communicate with the client.\nAre there other instances already running on your system?\n\nIf you continue to experience this problem please contact support @ https://community.withsix.com")
                        .ConfigureAwait(false);

                if (r == RecoveryOptionResultModel.RetryOperation)
                {
                    goto retry;
                }
                _shutdownHandler.Shutdown(1);
                throw;
            } catch (Exception ex) {
                var r = await
                        UserErrorHandler.InformationalUserError(ex, "Unable to open required ports",
                                                                "We were unable to open the required port for the website to communicate with the client.\nAre there other instances already running on your system?\n\nIf you continue to experience this problem please contact support @ https://community.withsix.com")
                        .ConfigureAwait(false);

                _shutdownHandler.Shutdown(1);
                throw;
            }
        }
Exemplo n.º 4
0
        bool TryRunUpdaterIfValid(params string[] startupParams)
        {
            try {
                if (!SU.ExistsAndIsValid(Common.Paths.EntryLocation))
                {
                    return(false);
                }

                if (Common.Flags.LockDown)
                {
                    SU.PerformSelfUpdate(SelfUpdaterCommands.UpdateCommand, GetLockDownParameter());
                }
                else
                {
                    SU.PerformSelfUpdate(SelfUpdaterCommands.UpdateCommand, startupParams);
                }

                _shutdownHandler.Shutdown();
                return(true);
            } catch (Exception e) {
                UserErrorHandler.HandleUserError(new InformationalUserError(e,
                                                                            "An error occurred while trying to initiate self-update. See log file for details.\nPlease try again later...",
                                                                            null));
                return(false);
            }
        }
Exemplo n.º 5
0
        public static bool SetModule(string brainUid, string moduleUid, string javascript, StringFunction handleErrors)
        {
            UserErrorHandler.Push(handleErrors);
            bool rv = SetModule(brainUid, moduleUid, javascript);

            UserErrorHandler.Pop();
            return(rv);
        }
Exemplo n.º 6
0
 static void RegisterUrlHandlers(IPlayStartupManager startupManager)
 {
     try {
         startupManager.RegisterUrlHandlers();
     } catch (UnauthorizedAccessException e) {
         MainLog.Logger.FormattedWarnException(e);
     } catch (Exception e) {
         UserErrorHandler.HandleUserError(new InformationalUserError(e, "failed to register user handlers", null));
     }
 }
Exemplo n.º 7
0
        async Task ProcessParams(IEnumerable <string> @params)
        {
            foreach (var p in @params)
            {
                this.Logger().Info("Processing Param: {0}", p);

                if (p.StartsWith("--profile="))
                {
                    var desiredProfile = p.Replace("--profile=", "");
                    _mediator.Send(new SwitchProfileByNameCommand(desiredProfile));
                    await Task.Delay(3.Seconds()).ConfigureAwait(false);
                }

                if (p.Contains("lockdown="))
                {
                    if (Common.AppCommon.IsBusy)
                    {
                        await _dialogManager.MessageBox(
                            new MessageBoxDialogParams("Cannot restart in lockdown mode, currently busy!\n" + p));

                        return;
                    }
                    _restarter.RestartWithoutElevation(p);
                    return;
                }

                if (IsPwsUrl(p))
                {
retry:
                    Exception e = null;
                    try {
                        await HanldePwsUrl(p).ConfigureAwait(false);
                    } catch (DownloadException ex) {
                        e = ex;
                    }
                    if (e != null)
                    {
                        var result = await UserErrorHandler.HandleUserError(AddRepositoryViewModel.HandleException(e));

                        if (result == RecoveryOptionResultModel.RetryOperation)
                        {
                            goto retry;
                        }
                        // TODO: Strategy
                        throw e;
                    }
                }
                if (IsWebUrl(p))
                {
                    _eventBus.PublishOnCurrentThread(new RequestOpenBrowser(p));
                }
            }
        }
Exemplo n.º 8
0
        private void RegisterToolServices()
        {
            Tools.RegisterServices(Container.GetInstance <ToolsServices>());
            Tools.FileTools.FileOps.ShouldRetry = async(s, s1, e) => {
                var result =
                    await
                    UserErrorHandler.HandleUserError(new UserErrorModel(s, s1, RecoveryCommands.YesNoCommands, null,
                                                                        e));

                return(result == RecoveryOptionResultModel.RetryOperation);
            };
            Tools.InformUserError = (s, s1, e) => UserErrorHandler.HandleUserError(new InformationalUserError(e, s1, s));
        }
Exemplo n.º 9
0
        async Task InstallToolsIfNeeded()
        {
            try {
                await TryInstallToolsIfNeeded().ConfigureAwait(false);
            } catch (Exception e) {
                await
                _dialogManager.ExceptionDialog(e,
                                               "Tools failed to download, Play withSIX will not function correctly without these files. " +
                                               "Verify that your Internet connection is working and restart to try again.",
                                               "A problem occurred during tools download").ConfigureAwait(false);

                await UserErrorHandler.HandleUserError(new InformationalUserError(e, "A problem occurred during tools download", null));
            }
        }
        public async Task <bool> TryExecuteAction(Func <Task> action, string message = null)
        {
            Exception e = null;

            try {
                await action().ConfigureAwait(false);

                return(true);
            } catch (Exception ex) {
                e = ex;
            }
            return(await UserErrorHandler.HandleUserError(HandleException(e)) != RecoveryOptionResultModel.FailOperation);

            //return false;
        }
Exemplo n.º 11
0
        public async Task <bool> DealWithUpdateException(Exception e, string task, string message = StrHostListExhausted,
                                                         string title = null)
        {
            if (_busyStateHandler.IsAborted)
            {
                return(false);
            }

            if (title == null)
            {
                title = "A problem occurred during " + task;
            }
            await UserErrorHandler.HandleUserError(new InformationalUserError(e, message, title));

            return(true);
        }
Exemplo n.º 12
0
        public async Task <bool> ShouldMoveServerMods(Game currentGame)
        {
            var folders = GetServerModFolders(currentGame).ToArray();

            if (!folders.Any())
            {
                return(false);
            }

            var report =
                await
                UserErrorHandler.HandleUserError(new UserErrorModel("Migrate server mods?",
                                                                    "It appears you still have a deprecated 'servermods' folder\nThis folder is no longer relevant, would you like to merge the mods to the mod installation path?\n\nPlease make sure the Game is closed, and no other mod files (incl readmes) or utilities are open before proceeding",
                                                                    RecoveryCommands.YesNoCommands))
                == RecoveryOptionResultModel.RetryOperation;

            return(report);
        }
Exemplo n.º 13
0
        async void HandleAction <TEvt>(Func <TEvt, Task> action, TEvt x)
        {
retry:
            try {
                await action(x).ConfigureAwait(false);
            } catch (Exception ex) {
                var r = await UserErrorHandler.HandleUserError(_exHandler.HandleException(ex, "API action"));

                if (r == RecoveryOptionResultModel.RetryOperation)
                {
                    goto retry;
                }
                if (r == RecoveryOptionResultModel.FailOperation)
                {
                    throw;
                }
            }
        }
Exemplo n.º 14
0
        protected virtual void ConfigureUiInstances()
        {
            AppBootstrapperExt.StartSQLite();
            RequestScopeService.Instance = new RequestScopeService(Container);
            var bridge = Container.GetInstance <IBridge>();

            GameContextJsonImplementation.Settings = bridge.GameContextSettings();
            Cheat.SetServices(Container.GetInstance <ICheatImpl>());
            Tools.FileTools.FileOps.ShouldRetry = async(s, s1, e) => {
                var result =
                    await
                    UserErrorHandler.HandleUserError(new UserErrorModel(s, s1, RecoveryCommands.YesNoCommands, null,
                                                                        e));

                return(result == RecoveryOptionResultModel.RetryOperation);
            };
            Tools.InformUserError = (s, s1, e) => UserErrorHandler.HandleUserError(new InformationalUserError(e, s1, s));
            _initializers         = Container.GetAllInstances <IInitializer>();
        }
Exemplo n.º 15
0
        private async Task <bool> HandleError(QueueItem item, Exception ex)
        {
            var result =
                await UserErrorHandler.HandleUserError(ErrorHandlerr.HandleException(ex, "Queue action: " + item.Title));

            switch (result)
            {
            case RecoveryOptionResultModel.RetryOperation:
                item.Retry(() => _messenger.Update(item));
                BuildContinuation(item);
                return(true);

            case RecoveryOptionResultModel.CancelOperation:
                item.UpdateState(CompletionState.Canceled);
                await Update(item).ConfigureAwait(false);

                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        async Task <Uri> HandleError(Uri uri, Exception ex)
        {
            var currentAuthInfo = _authProvider.GetAuthInfoFromUriWithCache(uri);
            var userError       = new UsernamePasswordUserError(ex, "Username password required", "Please enter the info",
                                                                new Dictionary <string, object> {
                { "userName", currentAuthInfo.Username ?? "" },
                { "password", "" }   // , currentAuthInfo.Password ?? "" .. lets think about this ;-)
            });
            var r = await UserErrorHandler.HandleUserError(userError);

            if (r != RecoveryOptionResultModel.RetryOperation)
            {
                return(null);
            }
            var userName = userError.ContextInfo["userName"] as string;
            var password = userError.ContextInfo["password"] as string;

            _authProvider.SetNonPersistentAuthInfo(uri, new AuthInfo(userName, password));
            return(_authProvider.HandleUriAuth(uri, userName, password));
        }
Exemplo n.º 17
0
        public async Task <TResponse> ExecuteCommand <TResponse>(Func <Task <TResponse> > action, object command,
                                                                 Func <string, Exception, Exception> createException)
        {
retry:
            try {
                return(await TryExecuteCommand(action).ConfigureAwait(false));
            } catch (AlreadyExistsException e) {
                // don't log
                throw createException(e.Message, e);
            } catch (ValidationException e) {
                // don't log
                throw createException(e.Message, e);
            } catch (UserException e) {
                MainLog.Logger.FormattedWarnException(e,
                                                      "UserException catched during hub action: " + command.GetType().Name);
                throw createException(e.Message, e);
                // TODO: A better way to handle this actually from within frontends...
            }

            // TODO: More general ignore when is shutting down?
            catch (OperationCanceledException ex) when(Common.Flags.ShuttingDown)
            {
                throw createException("The system is shutting down",
                                      new CanceledException("The operation was aborted because the system is shutting down", ex));
            } catch (ObjectDisposedException ex) when(Common.Flags.ShuttingDown)
            {
                throw createException("The system is shutting down",
                                      new CanceledException("The operation was aborted because the system is shutting down", ex));
            } catch (Exception ex) {
                var handleException = ErrorHandlerr.HandleException(ex, "Action: " + command.GetType().Name);
                var result          =
                    await UserErrorHandler.HandleUserError(handleException);

                if (result == RecoveryOptionResultModel.RetryOperation)
                {
                    goto retry;
                }
                throw createException("Operation aborted", new CanceledException("The operation was aborted", ex));
            }
        }
Exemplo n.º 18
0
 static void ProcessNotificationException(Exception e)
 {
     UserErrorHandler.HandleUserError(new InformationalUserError(e,
                                                                 "A problem occurred while trying to create a popup notification", null));
 }
Exemplo n.º 19
0
        public static Util.Maybe <TResponse> UpdateAgent <TRequest, TResponse>(string brainUid, string agentUid,
                                                                               TRequest input, byte[] bytes,
                                                                               UpdateCallbacks callbacks)
        {
            using (new UpdateAgentLock())
                using (InGameProfiler.Section("Native.UpdateAgent"))
                    using (var pinnedBytes = Util.Pin(bytes))
                    {
                        NumUpdateCalls++;
                        bool   ok         = false;
                        string inputJson  = null;
                        string outputJson = null;

                        using (InGameProfiler.Section("ToJson"))
                        {
                            inputJson = JsonUtility.ToJson(input, false);
                        }
                        using (InGameProfiler.Section("UpdateAgentJsonNative"))
                        {
                            UserErrorHandler.Push(callbacks.handleError);
                            UserLogMessageHandler.Push(callbacks.handleLog);

                            userActorStringGetter = callbacks.getActorString;
                            userActorStringSetter = callbacks.setActorString;

                            using (InGameProfiler.Section("setting callbacks"))
                            {
                                // Avoid unnecessary calls to the Set... delegate bind functions,
                                // since those can take ~0.2ms each! Also, any pinning is
                                // unnecessary, since the life time of use is limited to this
                                // function. See:
                                // https://blogs.msdn.microsoft.com/cbrumme/2003/05/06/asynchronous-operations-pinning/

                                if (lastCallServiceFunction != callbacks.callService)
                                {
                                    SetCallServiceFunction(callbacks.callService);
                                    lastCallServiceFunction = callbacks.callService;
                                }

                                // BEGIN_GAME_BUILDER_CODE_GEN ACTOR_ACCESSOR_DELEGATE_MAYBE_SETS
                                if (lastBooleanGetterCallback != callbacks.getActorBoolean) // GENERATED
                                {
                                    SetActorBooleanGetter(callbacks.getActorBoolean);       // GENERATED
                                    lastBooleanGetterCallback = callbacks.getActorBoolean;  // GENERATED
                                }

                                if (lastBooleanSetterCallback != callbacks.setActorBoolean) // GENERATED
                                {
                                    SetActorBooleanSetter(callbacks.setActorBoolean);       // GENERATED
                                    lastBooleanSetterCallback = callbacks.setActorBoolean;  // GENERATED
                                }

                                if (lastVector3GetterCallback != callbacks.getActorVector3) // GENERATED
                                {
                                    SetActorVector3Getter(callbacks.getActorVector3);       // GENERATED
                                    lastVector3GetterCallback = callbacks.getActorVector3;  // GENERATED
                                }

                                if (lastVector3SetterCallback != callbacks.setActorVector3) // GENERATED
                                {
                                    SetActorVector3Setter(callbacks.setActorVector3);       // GENERATED
                                    lastVector3SetterCallback = callbacks.setActorVector3;  // GENERATED
                                }

                                if (lastQuaternionGetterCallback != callbacks.getActorQuaternion) // GENERATED
                                {
                                    SetActorQuaternionGetter(callbacks.getActorQuaternion);       // GENERATED
                                    lastQuaternionGetterCallback = callbacks.getActorQuaternion;  // GENERATED
                                }

                                if (lastQuaternionSetterCallback != callbacks.setActorQuaternion) // GENERATED
                                {
                                    SetActorQuaternionSetter(callbacks.setActorQuaternion);       // GENERATED
                                    lastQuaternionSetterCallback = callbacks.setActorQuaternion;  // GENERATED
                                }

                                if (lastFloatGetterCallback != callbacks.getActorFloat) // GENERATED
                                {
                                    SetActorFloatGetter(callbacks.getActorFloat);       // GENERATED
                                    lastFloatGetterCallback = callbacks.getActorFloat;  // GENERATED
                                }

                                if (lastFloatSetterCallback != callbacks.setActorFloat) // GENERATED
                                {
                                    SetActorFloatSetter(callbacks.setActorFloat);       // GENERATED
                                    lastFloatSetterCallback = callbacks.setActorFloat;  // GENERATED
                                }

                                // END_GAME_BUILDER_CODE_GEN
                            }
                            // Safe callback passing: https://docs.microsoft.com/en-us/dotnet/framework/interop/marshaling-a-delegate-as-a-callback-method
                            StringFunction captureJsonFunction = new StringFunction(json => outputJson = json);
                            ok = UpdateAgentJsonBytes(brainUid, agentUid,
                                                      inputJson, pinnedBytes.GetPointer(), bytes.Length,
                                                      captureJsonFunction);

                            UserErrorHandler.Pop();
                            UserLogMessageHandler.Pop();
                        }

                        if (!ok)
                        {
                            // TODO consider using the JSON return value for communicating the
                            // exception from JS...and throwing an exception!!
                            Debug.LogError("UpdateAgent failed. inputJson: " + inputJson);
                            return(Util.Maybe <TResponse> .CreateEmpty());
                        }
                        else
                        {
                            using (InGameProfiler.Section("FromJson"))
                            {
#if UNITY_EDITOR
                                if (outputJson.Length > 5 * 1024 * 1024)
                                {
                                    Util.LogError($"JSON response from VOOS update is getting dangerously large..exceeding 5MB. Full content: {outputJson}");
                                    Debug.Assert(false, "Editor-only JSON size check. See log for more details.");
                                }
#endif
                                TResponse response = JsonUtility.FromJson <TResponse>(outputJson);
                                return(Util.Maybe <TResponse> .CreateWith(response));
                            }
                        }
                    }
        }