コード例 #1
0
        private void buttonOK_Click(object sender, System.EventArgs args)
        {
            if (!this.checkLockAfterTime.Checked)
            {
                this.originalConfig.LockWorkspace.LockAfterTime = 0;
            }
            else
            {
                this.originalConfig.LockWorkspace.LockAfterTime = (uint)this.numericLockAfterTime.Value;
            }

            if (!this.checkLockGlobalTime.Checked)
            {
                this.originalConfig.LockWorkspace.LockGlobalTime = 0;
            }
            else
            {
                this.originalConfig.LockWorkspace.LockGlobalTime = (uint)this.numericLockGlobalTime.Value;
            }

            var tmpRequested = this.checkAutoRun.Checked;
            var currentValue = NativeShellHelper.GetStartWithWindows(ApplicationDefines.AutoRunName);

            if (tmpRequested != currentValue)
            {
                var tmpExecutablePath = WindowsUtils.GetExecutablePath().Trim();
                if (tmpExecutablePath.StartsWith("\"") == false)
                {
                    tmpExecutablePath = "\"" + tmpExecutablePath + "\"";
                }

                NativeShellHelper.SetStartWithWindows(ApplicationDefines.AutoRunName, tmpExecutablePath, tmpRequested);
            }

            this.originalConfig.SecretRank.Rank0BackColor = this.colorComboRank0.Color;
            this.originalConfig.SecretRank.Rank1BackColor = this.colorComboRank1.Color;
            this.originalConfig.SecretRank.Rank2BackColor = this.colorComboRank2.Color;
            this.originalConfig.SecretRank.Rank3BackColor = this.colorComboRank3.Color;

            ApplicationConfigSerializer.SaveApplicationConfig(Program.Config);

            var tmpNewWorkDirectory = this.textWorkDirectory.Text;
            var tmpOldWorkDirectory = NativeShellHelper.GetWorkingDirectory();

            if (System.IO.Directory.Exists(tmpNewWorkDirectory))
            {
                if (tmpNewWorkDirectory != tmpOldWorkDirectory)
                {
                    MoveDirectoryTo(System.IO.Path.Combine(tmpOldWorkDirectory, "data"), tmpNewWorkDirectory);
                    MoveDirectoryTo(System.IO.Path.Combine(tmpOldWorkDirectory, "config"), tmpNewWorkDirectory);

                    Program.Config.WorkingDirectory = tmpNewWorkDirectory;
                    NativeShellHelper.SetWorkingDirectory(tmpNewWorkDirectory);
                    HuiruiSoft.Data.Configuration.DataBaseConfig.DataSource = System.IO.Path.Combine(Program.Config.WorkingDirectory, ApplicationDefines.SafePassDbFile);
                }
            }

            this.DialogResult = DialogResult.OK;
        }
コード例 #2
0
        private void buttonOK_Click(object sender, System.EventArgs args)
        {
            var tmpCreateResult      = false;
            var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError;

            var tmpLoginName = this.textLoginName.Text.Trim();

            if (string.IsNullOrEmpty(tmpLoginName))
            {
                this.textLoginName.Focus();
                MessageBox.Show(SafePassResource.NewWizardWindowPromptLoginNameIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (tmpLoginName.Length > 30)
            {
                this.textLoginName.Focus();
                MessageBox.Show(SafePassResource.NewWizardWindowPromptLoginNameTooLong, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var tmpPassword       = this.textPassword.Text.Trim();
            var tmpMasterPassword = Program.Config.Application.Security.MasterPassword;

            if (string.IsNullOrEmpty(tmpPassword))
            {
                this.textPassword.Focus();
                MessageBox.Show(SafePassResource.NewWizardWindowPromptPasswordIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (tmpPassword.Length < tmpMasterPassword.MinimumLength)
            {
                this.textPassword.Focus();
                MessageBox.Show(string.Format(SafePassResource.MasterPasswordMinimumLengthFailed, tmpMasterPassword.MinimumLength), tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (QualityEstimation.EstimatePasswordQuality(tmpPassword) < tmpMasterPassword.MinimumQuality)
            {
                this.textPassword.Focus();
                MessageBox.Show(string.Format(SafePassResource.MasterPasswordMinimumQualityFailed, tmpMasterPassword.MinimumQuality), tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (!string.Equals(tmpPassword, this.textPwdRepeat.Text))
            {
                this.textPwdRepeat.Focus();
                MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var tmpSafePassName = this.textSafePassName.Text.Trim();

            if (string.IsNullOrEmpty(tmpSafePassName))
            {
                this.textSafePassName.Focus();
                MessageBox.Show(SafePassResource.NewWizardWindowPromptSafePassNameIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (StringHelper.GetStringBytesCount(tmpSafePassName) > 30)
            {
                this.textSafePassName.Focus();
                MessageBox.Show(SafePassResource.NewWizardWindowPromptSafePassNameTooLong, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var tmpRootDirectory = new DirectoryInfo(this.textWorkDirectory.Text);

            if (!tmpRootDirectory.Exists)
            {
                tmpRootDirectory = Directory.CreateDirectory(this.textWorkDirectory.Text);
            }

            DirectoryInfo tmpWorkDirectory;

            if (string.Equals(tmpRootDirectory.Name, tmpLoginName, System.StringComparison.OrdinalIgnoreCase))
            {
                tmpWorkDirectory = new DirectoryInfo(tmpRootDirectory.FullName);
            }
            else
            {
                tmpWorkDirectory = new DirectoryInfo(Path.Combine(tmpRootDirectory.FullName, tmpLoginName));
                if (!tmpWorkDirectory.Exists)
                {
                    tmpWorkDirectory = Directory.CreateDirectory(tmpWorkDirectory.FullName);
                }
            }


            if (tmpWorkDirectory.Exists)
            {
                var files = tmpWorkDirectory.GetFiles("*.*", SearchOption.AllDirectories);
                if (files != null && files.Length > 0)
                {
                    MessageBox.Show(string.Format(SafePassResource.NewWizardWindowWorkDirectoryNotEmpty, tmpWorkDirectory.FullName), tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                NativeShellHelper.SetWorkingDirectory(tmpWorkDirectory.FullName);
                var tmpDataDirectory = Path.Combine(tmpWorkDirectory.FullName, "data");

                if (!Directory.Exists(tmpDataDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(tmpDataDirectory);
                    }
                    catch (System.SystemException exception)
                    {
                        loger.Error(exception);
                        System.Diagnostics.Debug.WriteLine(exception.Message);
                    }
                }

                var tmpConfigDirectory = Path.Combine(tmpWorkDirectory.FullName, "config");
                if (!Directory.Exists(tmpConfigDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(tmpConfigDirectory);
                    }
                    catch (System.SystemException exception)
                    {
                        loger.Error(exception);
                        System.Diagnostics.Debug.WriteLine(exception.Message);
                    }
                }

                if (Directory.Exists(tmpConfigDirectory))
                {
                    try
                    {
                        //this.CreateLog4NetConfig( );
                        this.CreateApplicationConfig(tmpConfigDirectory, tmpLoginName, tmpPassword);
                    }
                    catch (System.SystemException exception)
                    {
                        loger.Error(exception);
                        System.Diagnostics.Debug.WriteLine(exception.Message);
                    }
                }

                if (Directory.Exists(tmpDataDirectory))
                {
                    try
                    {
                        tmpCreateResult = this.InitializeDataBase(tmpDataDirectory, tmpLoginName, tmpPassword);
                    }
                    catch (System.SystemException exception)
                    {
                        loger.Error(exception);
                        System.Diagnostics.Debug.WriteLine(exception.Message);
                    }
                }
            }

            if (tmpCreateResult)
            {
                MessageBox.Show(SafePassResource.NewWizardWindowDialogMessageCreateSuccess, SafePassResource.NewWizardWindowDialogTitleCreateSuccess, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
            }
        }