private void LoadSystemOptions( ) { this.originalConfig = Program.Config.Application.Security; var tmpLockSettings = this.originalConfig.LockWorkspace; var tmpLockAfterTime = tmpLockSettings.LockAfterTime; var tmpLockWorkspace = tmpLockAfterTime > 0; this.numericLockAfterTime.Value = (tmpLockWorkspace ? tmpLockAfterTime : 100); this.checkLockAfterTime.Checked = tmpLockWorkspace; this.numericLockAfterTime.Enabled = (this.checkLockAfterTime.Checked && this.checkLockAfterTime.Enabled); var tmpLockAfterGlobal = tmpLockSettings.LockGlobalTime; var tmpLockWorkStation = tmpLockAfterGlobal > 0; this.numericLockGlobalTime.Value = (tmpLockWorkStation ? tmpLockAfterGlobal : 200); this.checkLockGlobalTime.Checked = tmpLockWorkStation; this.numericLockGlobalTime.Enabled = (this.checkLockGlobalTime.Checked && this.checkLockGlobalTime.Enabled); this.colorComboRank0.Color = this.originalConfig.SecretRank.Rank0BackColor; this.colorComboRank1.Color = this.originalConfig.SecretRank.Rank1BackColor; this.colorComboRank2.Color = this.originalConfig.SecretRank.Rank2BackColor; this.colorComboRank3.Color = this.originalConfig.SecretRank.Rank3BackColor; this.textWorkDirectory.Text = Program.Config.WorkingDirectory; this.checkAutoRun.Checked = NativeShellHelper.GetStartWithWindows(ApplicationDefines.AutoRunName); }
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; }
protected override void OnFormClosed(FormClosedEventArgs args) { base.OnFormClosed(args); if (this.restartApplication) { NativeShellHelper.StartProcess(WindowsUtils.GetExecutablePath()); } }
public static bool CheckApplicationReadied() { var tmpWorkDirectory = NativeShellHelper.GetWorkingDirectory(); if (string.IsNullOrEmpty(tmpWorkDirectory)) { return(false); } var tmpConfigFileName = System.IO.Path.Combine(tmpWorkDirectory, MainConfigFile); if (!System.IO.File.Exists(tmpConfigFileName)) { return(false); } var tmpDataDirectory = System.IO.Path.Combine(tmpWorkDirectory, ApplicationDefines.SafePassDbFile); return(System.IO.File.Exists(tmpDataDirectory)); }
protected override void OnLoad(System.EventArgs args) { base.OnLoad(args); if (!base.DesignMode) { this.CancelButton = this.buttonCancel; this.textPassword.MaxLength = 50; this.textLoginName.MaxLength = 30; this.textSafePassName.MaxLength = 50; this.textWorkDirectory.ReadOnly = true; this.textPassword.PasswordChar = '*'; this.textPassword.ImeMode = ImeMode.Disable; this.textPwdRepeat.ImeMode = ImeMode.Disable; this.textLoginName.ImeMode = ImeMode.Disable; this.Icon = WindowsUtils.DefaultAppIcon; this.buttonOK.Text = SafePassResource.ButtonOK; this.buttonCancel.Text = SafePassResource.ButtonCancel; this.Text = SafePassResource.NewWizardWindowCaption; this.labelLoginName.Text = SafePassResource.NewWizardWindowLabelLoginName; this.labelPassword.Text = SafePassResource.NewWizardWindowLabelPassword; this.labelPwdRepeat.Text = SafePassResource.NewWizardWindowLabelPwdRepeat; this.labelPwdQuality.Text = SafePassResource.NewWizardWindowLabelPwdQuality; this.labelSafePassName.Text = SafePassResource.NewWizardWindowLabelSafePassName; this.labelWorkDirectory.Text = SafePassResource.NewWizardWindowLabelWorkDirectory; this.buttonSelectDirectory.Text = SafePassResource.NewWizardWindowButtonSelectDirectory; this.labelPromptRemember.Text = SafePassResource.NewWizardWindowPromptRememberPassword; WindowsUtils.SetShowPasswordImage(this.buttonShowPassword, true); var tmpWorkDirectory = NativeShellHelper.GetWorkingDirectory(); if (string.IsNullOrEmpty(tmpWorkDirectory)) { tmpWorkDirectory = System.IO.Path.Combine(NativeShellHelper.GetLocalDataDirectory(), @"HuiruiSoft\SafePass"); } this.textWorkDirectory.Text = tmpWorkDirectory; } }
private void UpdateControlState( ) { if (!this.blockUpdateControls) { this.blockUpdateControls = true; this.numericLockAfterTime.Enabled = (this.checkLockAfterTime.Checked && this.checkLockAfterTime.Enabled); if (WindowsUtils.IsWindows9x || NativeMethods.IsUnix()) { this.checkLockGlobalTime.Checked = false; this.checkLockGlobalTime.Enabled = false; this.numericLockGlobalTime.Enabled = false; } else { this.numericLockGlobalTime.Enabled = (this.checkLockGlobalTime.Checked && this.checkLockGlobalTime.Enabled); } this.blockUpdateControls = false; if (this.originalConfig != null) { var tmpNotModified = true; if (tmpNotModified) { tmpNotModified = (this.originalConfig.LockWorkspace.LockAfterTime == (uint)this.numericLockAfterTime.Value); } if (tmpNotModified) { tmpNotModified = this.originalConfig.LockWorkspace.LockGlobalTime == (uint)this.numericLockGlobalTime.Value; } if (tmpNotModified) { tmpNotModified = this.checkAutoRun.Checked == NativeShellHelper.GetStartWithWindows(ApplicationDefines.AutoRunName); } if (tmpNotModified) { tmpNotModified = this.originalConfig.SecretRank.Rank0BackColor == this.colorComboRank0.Color; } if (tmpNotModified) { tmpNotModified = this.originalConfig.SecretRank.Rank1BackColor == this.colorComboRank1.Color; } if (tmpNotModified) { tmpNotModified = this.originalConfig.SecretRank.Rank2BackColor == this.colorComboRank2.Color; } if (tmpNotModified) { tmpNotModified = this.originalConfig.SecretRank.Rank3BackColor == this.colorComboRank3.Color; } if (tmpNotModified) { tmpNotModified = string.Equals(this.textWorkDirectory.Text, Program.Config.WorkingDirectory, System.StringComparison.CurrentCultureIgnoreCase); } this.buttonOK.Enabled = !tmpNotModified; } } }
static void Main(string[] args) { System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); HuiruiSoft.Utils.WindowsUtils.LoadImageFromResource(typeof(ResourceFinder)); HuiruiSoft.Utils.WindowsUtils.LoadAppIconFromResource(typeof(ResourceFinder)); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); var tmpCheckResult = ApplicationDefines.CheckApplicationReadied(); if (!tmpCheckResult) { if (System.Globalization.CultureInfo.CurrentCulture.Name == "zh-CN") { var localLanguageFile = Path.Combine(Application.StartupPath, ApplicationDefines.ChineseSimpLanguageFile); HuiruiSoft.Safe.Localization.LocalizationResourceReader.ReadLocalizationResource(localLanguageFile); } var tmpInitializeWizard = new formNewSafeWizard(); if (tmpInitializeWizard.ShowDialog() == DialogResult.OK) { NativeShellHelper.StartProcess(WindowsUtils.GetExecutablePath()); } return; } applicationConfig = ApplicationConfigSerializer.Load(); if (!string.IsNullOrEmpty(applicationConfig.Application.LanguageFile)) { HuiruiSoft.Safe.Localization.LocalizationResourceReader.ReadLocalizationResource(applicationConfig.Application.LanguageFile); } try { ApplicationMessage = NativeMethods.RegisterWindowMessage(ApplicationDefines.WindowMessageId); } catch (System.Exception) { System.Diagnostics.Debug.Assert(false); } bool tmpSingleLock = HuiruiSoft.Utils.GlobalMutexPool.CreateMutex(ApplicationDefines.MutexName, true); if (!tmpSingleLock) { ActivatePreviousInstance(args); HuiruiSoft.Utils.GlobalMutexPool.ReleaseAll(); return; } log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(Application.StartupPath, ApplicationDefines.Log4NetConfigFile))); var tmpGlobalNotify = TryGlobalInstanceNotify(ApplicationDefines.MutexNameGlobal); var formLoginWindow = new formLoginWindow(); if (formLoginWindow.ShowDialog() != DialogResult.OK) { Application.Exit(); } else { var tmpMessageFilter = new CustomMessageFilter(); Application.AddMessageFilter(tmpMessageFilter); MainWindow = new formAccountManager(); Application.Run(MainWindow); Application.RemoveMessageFilter(tmpMessageFilter); } if (tmpGlobalNotify != null) { System.GC.KeepAlive(tmpGlobalNotify); } }
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; } }