コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: ninjaprawn/Mushy
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            Button           actualSender   = (Button)sender;
            UserAccountPanel parent         = (UserAccountPanel)actualSender.Parent;
            bool             isNexonRequest = actualSender.Content.ToString().Contains("Nexon");

            parent.loginGoogleButton.IsEnabled = false;
            parent.loginNexonButton.IsEnabled  = false;

            if (isNexonRequest)
            {
                parent.statusLabel.Text = "Logging in via Nexon...";

                string nexonToken = lm.getNexonIDToken();
                if (nexonToken == "")
                {
                    parent.statusLabel.Text            = "Failed to get Nexon Token";
                    parent.loginGoogleButton.IsEnabled = true;
                    parent.loginNexonButton.IsEnabled  = true;
                }
                else
                {
                    string ticket = "";
                    try
                    {
                        ticket = ut.getTicketForNexonToken(nexonToken);
                        parent.statusLabel.Text = "Obtained Ticket. Running...";
                    }
                    catch (Exception exc)
                    {
                        parent.statusLabel.Text            = "Error: " + exc.Message;
                        parent.loginGoogleButton.IsEnabled = true;
                        parent.loginNexonButton.IsEnabled  = true;
                    }

                    if (ticket != "")
                    {
                        //Console.WriteLine(ticket);
                        int pid = ut.launchMaple(ticket);
                        parent.setPID(pid);
                    }
                }
            }
            else
            {
                parent.statusLabel.Text = "Logging in via Google...";
                string googleToken = lm.getGoogleIDToken();

                if (googleToken == "")
                {
                    parent.statusLabel.Text            = "Failed to get Google Token";
                    parent.loginGoogleButton.IsEnabled = true;
                    parent.loginNexonButton.IsEnabled  = true;
                }
                else
                {
                    string ticket = "";
                    try
                    {
                        ticket = ut.getTicketForGoogleToken(googleToken);
                        parent.statusLabel.Text = "Obtained Ticket. Running...";
                    }
                    catch (Exception exc)
                    {
                        parent.statusLabel.Text            = "Error: " + exc.Message;
                        parent.loginGoogleButton.IsEnabled = true;
                        parent.loginNexonButton.IsEnabled  = true;
                    }

                    if (ticket != "")
                    {
                        int pid = ut.launchMaple(ticket);
                        parent.setPID(pid);
                    }
                }
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: ninjaprawn/Mushy
        public MainWindow()
        {
            InitializeComponent();

            if (IsElevated())
            {
                Console.WriteLine("Creating necessary users");
                if (!MS2Utils.UserExists("mushyuser1"))
                {
                    MS2Utils.CreateLocalWindowsAccount("mushyuser1", "mushypass");
                }
                if (!MS2Utils.UserExists("mushyuser2"))
                {
                    MS2Utils.CreateLocalWindowsAccount("mushyuser2", "mushypass");
                }
                if (!MS2Utils.UserExists("mushyuser3"))
                {
                    MS2Utils.CreateLocalWindowsAccount("mushyuser3", "mushypass");
                }
                MessageBox.Show("Users have been created. Application will now exit.");
                Environment.Exit(0);
            }

            ut            = new MS2Utils();
            lm            = new LoginManager(this);
            accountPanels = new List <UserAccountPanel>();

            for (int i = 0; i < 4; i++)
            {
                UserAccountPanel current = new UserAccountPanel();
                current.Margin = new Thickness(10);

                if (i % 2 == 0)
                {
                    current.SetValue(Grid.RowProperty, (i == 2 ? 1 : 0));
                    current.SetValue(Grid.ColumnProperty, 0);
                }
                else
                {
                    current.SetValue(Grid.RowProperty, (i == 3 ? 1 : 0));
                    current.SetValue(Grid.ColumnProperty, 1);
                }

                current.loginNexonButton.Click  += LoginButton_Click;
                current.loginGoogleButton.Click += LoginButton_Click;
                current.featureButton.Click     += FeatureButton_Click;
                //current.featureButton.IsEnabled = true;

                accountPanels.Add(current);

                accountGrid.Children.Add(current);
            }

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        UserAccountPanel p = accountPanels[i];
                        if (p.pid != -1)
                        {
                            if (!Process.GetProcesses().Any(x => x.Id == p.pid))
                            {
                                p.setPID(-1);
                                ut.removePID(p.pid);
                            }
                        }
                    }
                    Thread.Sleep(500);
                }
                ;
            });
        }