Ejemplo n.º 1
0
        public static async Task CloseSteamAsync()
        {
            try
            {
                var ActiveSteamPath = GetActiveSteamProcessPath();
                if (!string.IsNullOrEmpty(ActiveSteamPath))
                {
                    if (await Main.FormAccessor.ShowMessageAsync("Steam needs to be closed", "Steam needs to be closed for this action. Would you like SLM to close Steam?", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
                    {
                        if (File.Exists(ActiveSteamPath))
                        {
                            Process.Start(ActiveSteamPath, "-shutdown");
                        }
                        else if (await Main.FormAccessor.ShowMessageAsync("Steam needs to be closed", $"Steam.exe could not found (even it is already working?), SLM can try to terminate the Steam processes now if you want to.\n\nActive Steam process path: {ActiveSteamPath}", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
                        {
                            foreach (var SteamProcess in Process.GetProcessesByName("Steam"))
                            {
                                SteamProcess.Kill();
                            }
                        }
                        else
                        {
                            throw new OperationCanceledException("Steam.exe could not found and user doesn't wants to terminate the process.");
                        }
                    }
                    else
                    {
                        throw new OperationCanceledException("User doesn't wants to close Steam, can not continue to process.");
                    }

                    await Task.Delay(6000);
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
            }
        }
Ejemplo n.º 2
0
        public static async Task CloseSteamAsync()
        {
            try
            {
                var ActiveSteamPath = GetActiveSteamProcessPath();
                if (!string.IsNullOrEmpty(ActiveSteamPath))
                {
                    if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosed)), SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosedMessage)), MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
                    {
                        if (File.Exists(ActiveSteamPath))
                        {
                            Process.Start(ActiveSteamPath, "-shutdown");
                        }
                        else if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosed)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosedMessage2)), new { ActiveSteamPath }), MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
                        {
                            foreach (var SteamProcess in Process.GetProcessesByName("Steam"))
                            {
                                SteamProcess.Kill();
                            }
                        }
                        else
                        {
                            throw new OperationCanceledException(SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosed_NotFoundAndUserCancelled)));
                        }
                    }
                    else
                    {
                        throw new OperationCanceledException(SLM.Translate(nameof(Properties.Resources.Steam_NeedsToBeClosed_UserCancelled)));
                    }

                    await Task.Delay(6000);
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
            }
        }