private void buttonOK_Click(object sender, System.EventArgs args) { var tmpDialogResult = MessageBox.Show(SafePassResource.ChangeLanguageWindowMessage, SafePassResource.Info, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (tmpDialogResult == DialogResult.Yes) { string tmpLanguageFile = null; if (this.listViewLanguages.SelectedItems.Count > 0) { var tmpListViewItem = this.listViewLanguages.SelectedItems[0]; if (tmpListViewItem.Tag != null && tmpListViewItem.Tag is LanguageHeader) { tmpLanguageFile = tmpListViewItem.SubItems[2].Text; } } if (tmpLanguageFile != Program.Config.Application.LanguageFile) { Program.Config.Application.LanguageFile = tmpLanguageFile; ApplicationConfigSerializer.SaveApplicationConfig(Program.Config); } this.DialogResult = DialogResult.OK; } }
private bool CreateApplicationConfig(string configDirectory, string userName, string password) { var tmpSafePassConfig = new SafePassConfiguration(); if (System.Globalization.CultureInfo.CurrentCulture.Name == "zh-CN") { tmpSafePassConfig.Application.LanguageFile = ApplicationDefines.ChineseSimpLanguageFile; } var tmpSecurityProfile = tmpSafePassConfig.Application.Security; tmpSecurityProfile.LockWorkspace = Program.Config.Application.Security.LockWorkspace; tmpSecurityProfile.MasterPassword = Program.Config.Application.Security.MasterPassword; tmpSecurityProfile.CurrentAccount.UserName = userName; tmpSecurityProfile.CurrentAccount.Password = password; tmpSecurityProfile.CurrentAccount.PasswordStored = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpSecurityProfile.CurrentAccount.PasswordMd5); tmpSecurityProfile.Clipboard.ClipboardClearOnExit = Program.Config.Application.Security.Clipboard.ClipboardClearOnExit; tmpSecurityProfile.Clipboard.ClipboardClearAfterSeconds = Program.Config.Application.Security.Clipboard.ClipboardClearAfterSeconds; tmpSecurityProfile.SecretRank.SecretRank0Color = Program.Config.Application.Security.SecretRank.SecretRank0Color; tmpSecurityProfile.SecretRank.SecretRank1Color = Program.Config.Application.Security.SecretRank.SecretRank1Color; tmpSecurityProfile.SecretRank.SecretRank2Color = Program.Config.Application.Security.SecretRank.SecretRank2Color; tmpSecurityProfile.SecretRank.SecretRank3Color = Program.Config.Application.Security.SecretRank.SecretRank3Color; tmpSafePassConfig.MainWindow = Program.Config.MainWindow; var tmpCreateResult = ApplicationConfigSerializer.SaveApplicationConfig(Path.Combine(configDirectory, "SafePass.config.xml"), tmpSafePassConfig); return(tmpCreateResult); }
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; }
private void buttonOK_Click(object sender, System.EventArgs args) { var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError; var tmpOldPassword = this.textOldPassword.Text.Trim(); var tmpNewPassword = this.textNewPassword.Text.Trim(); if (tmpOldPassword != Account.CurrentAccount.Password) { this.textOldPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIncorrect, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(tmpNewPassword)) { this.textNewPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (!string.Equals(tmpNewPassword, this.textRepeatPassword.Text)) { this.textRepeatPassword.Focus(); MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.Equals(tmpOldPassword, tmpNewPassword, System.StringComparison.OrdinalIgnoreCase)) { this.textNewPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptSameAsOldPassword, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var tmpPasswordMd5 = Md5DigestHelper.Md5Salt(tmpNewPassword, Account.CurrentAccount.UserName); var tmpAccountService = new HuiruiSoft.Safe.Service.AccountService(); var tmpChangeResult = tmpAccountService.ChangePassword(tmpPasswordMd5); if (tmpChangeResult) { DataBaseConfig.Password = tmpPasswordMd5; Account.CurrentAccount.Password = tmpNewPassword; Account.CurrentAccount.PasswordStored = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpPasswordMd5); ApplicationConfigSerializer.SaveApplicationConfig(Program.Config); MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeSuccess, SafePassResource.Success, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } } catch (System.SystemException exception) { loger.Error(exception); MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeFailed, SafePassResource.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override void OnClosing(CancelEventArgs args) { base.OnClosing(args); if (this.WindowState != FormWindowState.Minimized) { Program.Config.MainWindow.SplitPosition = ((this.splitControls.SplitterDistance + 8) * 100) / this.splitControls.Width; } Program.Config.MainWindow.Minimized = (this.WindowState == FormWindowState.Minimized); Program.Config.MainWindow.Maximized = (this.WindowState == FormWindowState.Maximized); ApplicationConfigSerializer.SaveApplicationConfig(Program.Config); }
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); } }