コード例 #1
0
        private void EditAcct(object sender, EventArgs e)
        {
            TOTP_SecretInfo thisAcct;

            int iHasError = 1;

            this._sCurrAcctID = ((ToolStripMenuItem)sender).Owner.Items[4].Text;
            thisAcct          = this._TOTPAccounts.FindByID(this._sCurrAcctID);
            if (null == thisAcct)
            {
                this._sCurrAcctID = "";
                MessageBox.Show("Account not found!", "Error");
                return;
            }

            if (null != this._frmAddAcct)
            {
                if (!this._frmAddAcct.IsDisposed)
                {
                    this._sCurrAcctID = "";
                    return;
                }
            }

            this._frmAddAcct = new SetSecretForm(this);
            this._frmAddAcct.SetAcctID(thisAcct.ID);
            this._frmAddAcct.SetSecretText(thisAcct.Key);
            this._frmAddAcct.SetCodeLen(thisAcct.CodeLen.ToString());

            while (iHasError == 1)
            {
                this._frmAddAcct.ShowDialog();

                if (this._rsDialog != DialogResult.Cancel)
                {
                    thisAcct.ID      = this._frmAddAcct.GetAcctID();
                    thisAcct.Key     = this._frmAddAcct.GetSecretText();
                    thisAcct.CodeLen = Convert.ToInt32(this._frmAddAcct.GetCodeLen());

                    this._frmAddAcct.Dispose();

                    this._confApp.Save(ConfigurationSaveMode.Full, true);

                    // Update the hidden account ID
                    ((ToolStripMenuItem)sender).Owner.Items[4].Text = thisAcct.ID;
                    // Update the account menu item name
                    for (int i = 0; i < this.msTrayIcon.Items.Count; i++)
                    {
                        if (this.msTrayIcon.Items[i].Text == this._sCurrAcctID)
                        {
                            this.msTrayIcon.Items[i].Text = thisAcct.ID;
                            break;
                        }
                    }


                    iHasError = 0;
                }
                else
                {
                    // Form closed
                    iHasError = 0;
                    this._frmAddAcct.Dispose();
                }
            }

            this._sCurrAcctID = "";
        }
コード例 #2
0
ファイル: HiddenMain.cs プロジェクト: lihouyu/TOTPGen
        private void EditAcct(object sender, EventArgs e)
        {
            TOTP_SecretInfo thisAcct;

            int iHasError = 1;

            this._sCurrAcctID = ((ToolStripMenuItem)sender).Owner.Items[4].Text;
            thisAcct = this._TOTPAccounts.FindByID(this._sCurrAcctID);
            if (null == thisAcct) {
                this._sCurrAcctID = "";
                MessageBox.Show("Account not found!", "Error");
                return;
            }

            if (null != this._frmAddAcct) {
                if (! this._frmAddAcct.IsDisposed) {
                    this._sCurrAcctID = "";
                    return;
                }
            }

            this._frmAddAcct = new SetSecretForm(this);
            this._frmAddAcct.SetAcctID(thisAcct.ID);
            this._frmAddAcct.SetSecretText(thisAcct.Key);
            this._frmAddAcct.SetCodeLen(thisAcct.CodeLen.ToString());

            while (iHasError == 1) {
                this._frmAddAcct.ShowDialog();

                if (this._rsDialog != DialogResult.Cancel) {
                    thisAcct.ID = this._frmAddAcct.GetAcctID();
                    thisAcct.Key = this._frmAddAcct.GetSecretText();
                    thisAcct.CodeLen = Convert.ToInt32(this._frmAddAcct.GetCodeLen());

                    this._frmAddAcct.Dispose();

                    this._confApp.Save(ConfigurationSaveMode.Full, true);

                    // Update the hidden account ID
                    ((ToolStripMenuItem)sender).Owner.Items[4].Text = thisAcct.ID;
                    // Update the account menu item name
                    for (int i = 0; i < this.msTrayIcon.Items.Count; i++) {
                        if (this.msTrayIcon.Items[i].Text == this._sCurrAcctID) {
                            this.msTrayIcon.Items[i].Text = thisAcct.ID;
                            break;
                        }
                    }

                    iHasError = 0;
                } else {
                    // Form closed
                    iHasError = 0;
                    this._frmAddAcct.Dispose();
                }
            }

            this._sCurrAcctID = "";
        }
コード例 #3
0
        private void AddNewAcct(object sender, EventArgs e)
        {
            int iHasError = 1;

            if (null != this._frmAddAcct)
            {
                if (!this._frmAddAcct.IsDisposed)
                {
                    return;
                }
            }

            TOTP_SecretInfo csTOTPSecret = new TOTP_SecretInfo();

            // Config the first newly created account
            this._frmAddAcct = new SetSecretForm(this);

            while (iHasError == 1)
            {
                this._frmAddAcct.ShowDialog();

                if (this._rsDialog != DialogResult.Cancel)
                {
                    csTOTPSecret.ID = this._frmAddAcct.GetAcctID();

                    if (null != this._TOTPAccounts.FindByID(csTOTPSecret.ID))
                    {
                        // Account name duplicate
                        this._frmAddAcct.SetErrTxt("Account Name exists!");
                    }
                    else
                    {
                        csTOTPSecret.Key     = this._frmAddAcct.GetSecretText();
                        csTOTPSecret.CodeLen = Convert.ToInt32(this._frmAddAcct.GetCodeLen());

                        this._frmAddAcct.Dispose();

                        this._TOTPAccounts.Add(csTOTPSecret);

                        this._confApp.Save(ConfigurationSaveMode.Full, true);

                        // Add account menu item
                        int iAcctCnt = this._TOTPAccounts.Count;

                        this._TOTPAccounts[iAcctCnt - 1].MenuItem = this.CreateAcctMenu(csTOTPSecret.ID);

                        //this.msTrayIcon.Items.Insert(iAcctCnt,
                        //                            this._TOTPAccounts[iAcctCnt - 1].MenuItem);
                        //

                        iHasError = 0;
                    }
                }
                else
                {
                    // Form closed
                    iHasError = 0;
                    this._frmAddAcct.Dispose();
                }
            }
        }
コード例 #4
0
ファイル: HiddenMain.cs プロジェクト: lihouyu/TOTPGen
        private void AddNewAcct(object sender, EventArgs e)
        {
            int iHasError = 1;

            if (null != this._frmAddAcct) {
                if (! this._frmAddAcct.IsDisposed)
                    return;
            }

            TOTP_SecretInfo csTOTPSecret = new TOTP_SecretInfo();

            // Config the first newly created account
            this._frmAddAcct = new SetSecretForm(this);

            while (iHasError == 1) {
                this._frmAddAcct.ShowDialog();

                if (this._rsDialog != DialogResult.Cancel) {
                    csTOTPSecret.ID = this._frmAddAcct.GetAcctID();

                    if (null != this._TOTPAccounts.FindByID(csTOTPSecret.ID)) {
                        // Account name duplicate
                        this._frmAddAcct.SetErrTxt("Account Name exists!");
                    } else {
                        csTOTPSecret.Key = this._frmAddAcct.GetSecretText();
                        csTOTPSecret.CodeLen = Convert.ToInt32(this._frmAddAcct.GetCodeLen());

                        this._frmAddAcct.Dispose();

                        this._TOTPAccounts.Add(csTOTPSecret);

                        this._confApp.Save(ConfigurationSaveMode.Full, true);

                        // Add account menu item
                        int iAcctCnt = this._TOTPAccounts.Count;

                        this._TOTPAccounts[iAcctCnt - 1].MenuItem = this.CreateAcctMenu(csTOTPSecret.ID);

                        this.msTrayIcon.Items.Insert(iAcctCnt,
                                                    this._TOTPAccounts[iAcctCnt - 1].MenuItem);
                        //

                        iHasError = 0;
                    }
                } else {
                    // Form closed
                    iHasError = 0;
                    this._frmAddAcct.Dispose();
                }
            }
        }