Ejemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //var io = Icon.ExtractAssociatedIcon(Riot.GetRiotClientPath());
            //using (FileStream fs = new FileStream("riot.ico", FileMode.Create))
            //    io.Save(fs);
            try
            {
                Assembly executingAssembly     = Assembly.GetExecutingAssembly();
                string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
                string   str = "server.pfx";

                using (var sourceStream = executingAssembly.GetManifestResourceStream(manifestResourceNames.Single(m => m.Contains(str))))
                    using (var memoryStream = new MemoryStream())
                    {
                        sourceStream.CopyTo(memoryStream);
                        CertificateBytes = memoryStream.ToArray();
                    }

                NotifyIcon      = new TaskbarIcon();
                NotifyIcon.Icon = Icon.ExtractAssociatedIcon(Riot.GetRiotClientPath());

                this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                EnsureRiotNotRunning();
                SetupConfigProxy();

                SetupTrayIcon();

                DispatcherTimer timer = new DispatcherTimer();
                timer.Tick += (s, ev) =>
                {
                    SetupTrayIcon();
                    RightAlignGame();
                };
                timer.Interval = TimeSpan.FromSeconds(5);
                timer.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Shutdown();
            }
        }
Ejemplo n.º 2
0
        void EnsureRiotNotRunning()
        {
            if (Riot.IsAnyRunning())
            {
                using (TaskDialog dialog = new TaskDialog())
                {
                    dialog.WindowTitle     = AppName;
                    dialog.MainInstruction = $"Riot processes detected";
                    dialog.Content         = AppName + " has detected Riot processes running, but LeagueTools must be started before League. Would you like to automatically kill Riot Processes?";
                    dialog.MainIcon        = TaskDialogIcon.Warning;

                    TaskDialogButton kill         = new TaskDialogButton("Kill Processes");
                    TaskDialogButton cancelButton = new TaskDialogButton("Exit");
                    dialog.Buttons.Add(kill);
                    dialog.Buttons.Add(cancelButton);

                    var clicked = dialog.Show();
                    if (clicked == kill)
                    {
                        Riot.KillRiotClientProcesses();
                        Thread.Sleep(3000);
                        if (Riot.IsAnyRunning())
                        {
                            using (TaskDialog err = new TaskDialog())
                            {
                                err.WindowTitle     = AppName;
                                err.MainInstruction = "Unable to kill riot processes";
                                err.Content         = "Unable to kill riot processes. Please kill processes manually and restart " + AppName;
                                err.MainIcon        = TaskDialogIcon.Error;
                                TaskDialogButton exitButton = new TaskDialogButton(ButtonType.Ok);
                                err.Buttons.Add(exitButton);
                                err.Show();
                            }
                            Environment.Exit(0);
                        }
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void SetupTrayIcon()
        {
            ContextMenu context = new ContextMenu();

            foreach (var e in Enum.GetValues(typeof(RiotClient)).Cast <RiotClient>())
            {
                var name = Enum.GetName(typeof(RiotClient), e);

                if (Riot.ClientIsRunning(e))
                {
                    var game = new MenuItem()
                    {
                        Header = name + " (Running)"
                    };
                    game.Click += (s, ev) => Riot.ClientFocus(e);
                    context.Items.Add(game);

                    var gameRestart = new MenuItem()
                    {
                        Header = "Restart"
                    };
                    gameRestart.Click += (s, ev) => Riot.ClientRestart(e, ConfigProxyPort);
                    game.Items.Add(gameRestart);

                    var gameExit = new MenuItem()
                    {
                        Header = "Exit"
                    };
                    gameExit.Click += (s, ev) => Riot.ClientKill(e);
                    game.Items.Add(gameExit);
                }
                else
                {
                    var game = new MenuItem()
                    {
                        Header = $"Start " + name
                    };
                    game.Click += (s, ev) => Riot.ClientStart(e, ConfigProxyPort);
                    context.Items.Add(game);
                }
            }

            context.Items.Add(new Separator());

            var logs = new MenuItem()
            {
                Header = "Presence Logs"
            };

            logs.IsEnabled = false;
            foreach (var p in Presence.ListOfPresence)
            {
                logs.IsEnabled = true;
                var name = "log." + p.Id;
                if (p.Observer.IsCompleted)
                {
                    name += " (exited)";
                }
                var pres = new MenuItem()
                {
                    Header = name
                };
                pres.Click += (s, e) =>
                {
                    Util.ShowMessage(Util.FormatXml(p.Log));
                };
                logs.Items.Add(pres);
            }
            context.Items.Add(logs);

            context.Items.Add(new Separator());

            var align = new MenuItem()
            {
                Header = "Right-align game client?"
            };

            align.IsChecked   = RightAlign;
            align.IsCheckable = true;
            align.Click      += (s, e) =>
            {
                RightAlign = !RightAlign;
            };
            context.Items.Add(align);

            var offline = new MenuItem()
            {
                Header = "Appear offline?"
            };

            offline.IsChecked   = AppearOffline;
            offline.IsCheckable = true;
            offline.Click      += (s, e) =>
            {
                AppearOffline = !AppearOffline;
                Presence.UpdateAllPresence(AppearOffline);
            };
            context.Items.Add(offline);

            context.Items.Add(new Separator());

            var exit = new MenuItem()
            {
                Header = "Exit"
            };

            exit.Click += (s, e) =>
            {
                Riot.KillRiotClientProcesses();
                NotifyIcon.Dispose();
                Environment.Exit(0);
            };
            context.Items.Add(exit);

            NotifyIcon.ContextMenu = context;
        }