コード例 #1
0
ファイル: Form1.cs プロジェクト: xzkmxd/BeanfunLogin
        public bool init()
        {
            try
            {
                this.Text           = $"BeanfunLogin - v{ currentVersion.Major }.{ currentVersion.Minor }.{ currentVersion.Build }({ currentVersion.Revision })";
                this.AcceptButton   = this.loginButton;
                this.bfClient       = null;
                this.accountManager = new AccountManager();

                bool res = accountManager.init();
                if (res == false)
                {
                    errexit("帳號記錄初始化失敗,未知的錯誤。", 0);
                }
                refreshAccountList();
                // Properties.Settings.Default.Reset(); //SetToDefault.

                // Handle settings.
                if (Properties.Settings.Default.rememberAccount == true)
                {
                    this.accountInput.Text = Properties.Settings.Default.AccountID;
                }
                if (Properties.Settings.Default.rememberPwd == true)
                {
                    this.rememberAccount.Enabled = false;
                    // Load password.
                    if (File.Exists("UserState.dat"))
                    {
                        try
                        {
                            Byte[] cipher    = File.ReadAllBytes("UserState.dat");
                            string entropy   = Properties.Settings.Default.entropy;
                            byte[] plaintext = ProtectedData.Unprotect(cipher, Encoding.UTF8.GetBytes(entropy), DataProtectionScope.CurrentUser);
                            this.passwdInput.Text = System.Text.Encoding.UTF8.GetString(plaintext);
                        }
                        catch
                        {
                            File.Delete("UserState.dat");
                        }
                    }
                }
                if (Properties.Settings.Default.autoLogin == true)
                {
                    this.UseWaitCursor    = true;
                    this.panel2.Enabled   = false;
                    this.loginButton.Text = "請稍後...";
                    this.loginWorker.RunWorkerAsync(Properties.Settings.Default.loginMethod);
                }
                if (gamePaths.Get("新楓之谷") == "")
                {
                    ModifyRegistry myRegistry = new ModifyRegistry();
                    myRegistry.BaseRegistryKey = Registry.CurrentUser;
                    myRegistry.SubKey          = "Software\\Gamania\\MapleStory";
                    if (myRegistry.Read("Path") != "")
                    {
                        gamePaths.Set("新楓之谷", myRegistry.Read("Path"));
                        gamePaths.Save();
                    }
                }

                this.loginMethodInput.SelectedIndex = Properties.Settings.Default.loginMethod;
                this.textBox3.Text = "";

                if (this.accountInput.Text == "")
                {
                    this.ActiveControl = this.accountInput;
                }
                else if (this.passwdInput.Text == "")
                {
                    this.ActiveControl = this.passwdInput;
                }

                // .NET textbox full mode bug.
                //this.accountInput.ImeMode = ImeMode.OnHalf;
                //this.passwdInput.ImeMode = ImeMode.OnHalf;
                return(true);
            }
            catch (Exception e)
            {
                return(errexit("初始化失敗,未知的錯誤。" + e.Message, 0));
            }
        }
コード例 #2
0
        public bool init()
        {
            try
            {
                this.bfClient       = null;
                this.accountManager = new AccountManager();

                bool res = accountManager.init();
                if (res == false)
                {
                    errexit("帳號記錄初始化失敗,未知的錯誤。", 0);
                }
                refreshAccountList();
                // Properties.Settings.Default.Reset(); //SetToDefault.

                // Handle settings.
                if (Properties.Settings.Default.rememberAccount == true)
                {
                    this.tb_account.Text = Properties.Settings.Default.AccountID;
                }
                if (Properties.Settings.Default.rememberPwd == true)
                {
                    /* this.rememberAccount.Enabled = false;*/
                    // Load password.
                    if (File.Exists("UserState.dat"))
                    {
                        try
                        {
                            Byte[] cipher    = File.ReadAllBytes("UserState.dat");
                            string entropy   = Properties.Settings.Default.entropy;
                            byte[] plaintext = ProtectedData.Unprotect(cipher, Encoding.UTF8.GetBytes(entropy), DataProtectionScope.CurrentUser);
                            this.pb_password.Password = System.Text.Encoding.UTF8.GetString(plaintext);
                        }
                        catch
                        {
                            File.Delete("UserState.dat");
                        }
                    }
                }
                if (Properties.Settings.Default.autoLogin == true)
                {
                    /*  this.UseWaitCursor = true;
                     * this.panel2.Enabled = false;
                     * this.loginButton.Text = "請稍後...";
                     * this.loginWorker.RunWorkerAsync(Properties.Settings.Default.loginMethod);*/
                }
                if (gamePaths.Get("新楓之谷") == "")
                {
                    /* ModifyRegistry myRegistry = new ModifyRegistry();
                     * myRegistry.BaseRegistryKey = Registry.CurrentUser;
                     * myRegistry.SubKey = "Software\\Gamania\\MapleStory";
                     * if (myRegistry.Read("Path") != "")
                     * {
                     *   gamePaths.Set("新楓之谷", myRegistry.Read("Path"));
                     *   gamePaths.Save();
                     * }*/
                }

                this.cb_login_method.SelectedIndex = Properties.Settings.Default.loginMethod;

                /*                this.textBox3.Text = "";
                 *
                 *              if (this.tb_account.Text == "")
                 *                  this.ActiveControl = this.tb_account;
                 *              else if (this.pb_password.Password == "")
                 *                  this.ActiveControl = this.pb_password;*/


                this.getOtpWorker.WorkerReportsProgress      = true;
                this.getOtpWorker.WorkerSupportsCancellation = true;
                this.getOtpWorker.DoWork                   += new System.ComponentModel.DoWorkEventHandler(this.getOtpWorker_DoWork);
                this.getOtpWorker.RunWorkerCompleted       += new System.ComponentModel.RunWorkerCompletedEventHandler(this.getOtpWorker_RunWorkerCompleted);
                this.loginWorker.WorkerReportsProgress      = true;
                this.loginWorker.WorkerSupportsCancellation = true;
                this.loginWorker.DoWork                   += new System.ComponentModel.DoWorkEventHandler(this.loginWorker_DoWork);
                this.loginWorker.RunWorkerCompleted       += new System.ComponentModel.RunWorkerCompletedEventHandler(this.loginWorker_RunWorkerCompleted);
                this.pingWorker.WorkerReportsProgress      = true;
                this.pingWorker.WorkerSupportsCancellation = true;
                this.pingWorker.DoWork             += new System.ComponentModel.DoWorkEventHandler(this.pingWorker_DoWork);
                this.pingWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.pingWorker_RunWorkerCompleted);

                return(true);
            }
            catch (Exception e)
            {
                return(errexit("初始化失敗,未知的錯誤。" + e.Message, 0));
            }
        }