public FrmRefreshToken(MCUserAccount user)
 {
     InitializeComponent();
     oUser           = user;
     TxtUser.Text    = user.username;
     TxtUser.Enabled = false;
 }
        // delete account
        public void DeleteAccount(Guid iAccountId)
        {
            MCUserAccount Account = GetAccount(iAccountId);

            Users.accounts.Remove(Account);
            if (Users.activeAccount == iAccountId)
            {
                Users.activeAccount = Guid.Empty;
            }
            SaveXML();
        }
 // get active profile from account
 public MCUserAccountProfile GetActiveProfile(MCUserAccount Account)
 {
     foreach (MCUserAccountProfile Profile in Account.profiles)
     {
         if (Profile.id == Account.activeProfile)
         {
             return(Profile);
         }
     }
     return(null);
 }
        public void SaveAccount(MCUserAccount Account)
        {
            // this needs a better way
            bool bWasDefault = false;

            if (Account.guid == Users.activeAccount)
            {
                bWasDefault = true;
            }

            DeleteAccount(Account.guid);
            AddAccount(Account);

            if (bWasDefault)
            {
                SetDefault(Account.guid);
            }
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (TxtUser.Text == "" || TxtPass.Text == "")
            {
                MessageBox.Show(this, "Eines der Felder ist leer.", "Fehlerhafte Eingabe!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Check LoginData
                AuthHandler          Auth     = new AuthHandler();
                AuthenticateResponse AuthData = new AuthenticateResponse();
                try
                {
                    AuthData = Auth.Authenticate(TxtUser.Text.ToString().Trim(), TxtPass.Text.ToString().Trim());
                }
                catch (MCInvalidCredentialsException ex)
                {
                    MessageBox.Show(this, ex.Message.ToString(), "Fehlermeldung von Minecraft.net", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TxtPass.Focus();
                    TxtPass.SelectAll();

                    return;
                }
                catch (MCUserMigratedException ex)
                {
                    MessageBox.Show(this, ex.Message.ToString(), "Fehlermeldung von Minecraft.net", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TxtPass.Focus();
                    TxtPass.SelectAll();

                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message.ToString(), "Verbindungsfehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TxtPass.Focus();
                    TxtPass.SelectAll();

                    return;
                }

                MCUserAccount newAcc = new MCUserAccount
                {
                    guid     = Guid.NewGuid(),
                    profiles = new List <MCUserAccountProfile>(),

                    accessToken   = AuthData.AccessToken,
                    clientToken   = AuthData.ClientToken,
                    username      = TxtUser.Text.ToString().Trim(),
                    activeProfile = AuthData.SelectedProfile.Id
                };

                for (int i = 0; i < AuthData.AvailableProfiles.Length; i++)
                {
                    MCUserAccountProfile newprofile = new MCUserAccountProfile
                    {
                        id     = AuthData.AvailableProfiles[i].Id,
                        name   = AuthData.AvailableProfiles[i].Name,
                        legacy = AuthData.AvailableProfiles[i].Legacy
                    };
                    newAcc.profiles.Add(newprofile);
                }

                Manager U = new Manager();
                U.AddAccount(newAcc);

                // set default user if only one given
                MCUser user = U.GetAccounts();
                if (U.GetNumAccounts() == 1)
                {
                    U.SetDefault(newAcc.guid);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
        }
 public void AddAccount(MCUserAccount Account)
 {
     Users.accounts.Add(Account);
     SaveXML();
 }