/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { m_bDesignMode = false; // Again, for the ones not calling Main m_rndGlobal = CryptoRandom.NewWeakRandom(); InitEnvSecurity(); MonoWorkarounds.Initialize(); // try { NativeMethods.SetProcessDPIAware(); } // catch(Exception) { } // Do not run as AppX, because of compatibility problems // (unless we're a special compatibility build) if (WinUtil.IsAppX && !IsBuildType( "CDE75CF0D4CA04D577A5A2E6BF5D19BFD5DDBBCF89D340FBBB0E4592C04496F1")) { return(false); } try { SelfTest.TestFipsComplianceProblems(); } catch (Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return(false); } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; KdbxFile.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); if (m_appConfig.Security.ProtectProcessWithDacl) { KeePassLib.Native.NativeMethods.ProtectProcessWithDacl(); } m_appConfig.Apply(AceApplyFlags.All); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; // InitEnvWorkarounds(); LoadTranslation(); CustomResourceManager.Override(typeof(KeePass.Properties.Resources)); return(true); }
private void OnFormLoad(object sender, EventArgs e) { if (m_aceOvr == null) { throw new InvalidOperationException(); } m_aceTmp = m_aceOvr.CloneDeep(); GlobalWindowManager.AddWindow(this); this.Icon = Properties.Resources.KeePass; this.Text = KPRes.UrlOverrides; UIUtil.SetExplorerTheme(m_lvOverrides, false); int nWidth = m_lvOverrides.ClientSize.Width - UIUtil.GetVScrollBarWidth(); m_lvOverrides.Columns.Add(KPRes.Scheme, nWidth / 4); m_lvOverrides.Columns.Add(KPRes.UrlOverride, (nWidth * 3) / 4); m_bEnfSch = AppConfigEx.IsOptionEnforced(Program.Config.Integration, "UrlSchemeOverrides"); m_bEnfAll = AppConfigEx.IsOptionEnforced(Program.Config.Integration, "UrlOverride"); UpdateOverridesList(false, false); m_cbOverrideAll.Checked = (m_strUrlOverrideAll.Length > 0); m_tbOverrideAll.Text = m_strUrlOverrideAll; EnableControlsEx(); }
private void OnFormLoad(object sender, EventArgs e) { if (m_triggers == null) { Debug.Assert(false); return; } GlobalWindowManager.AddWindow(this); GlobalWindowManager.CustomizeControl(m_ctxTools); BannerFactory.CreateBannerEx(this, m_bannerImage, Properties.Resources.B48x48_Make_KDevelop, KPRes.Triggers, KPRes.TriggersDesc); this.Text = KPRes.Triggers; this.Icon = AppIcons.Default; int nWidth = (m_lvTriggers.ClientSize.Width - UIUtil.GetVScrollBarWidth() - 1); m_lvTriggers.Columns.Add(KPRes.Triggers, nWidth); m_lvTriggers.SmallImageList = m_ilIcons; m_cbEnableTriggers.Checked = m_triggers.Enabled; UpdateTriggerListEx(false); EcasTriggerSystem ts = Program.TriggerSystem; EcasTriggerSystem tsCfg = Program.Config.Application.TriggerSystem; if (object.ReferenceEquals(m_triggersInOut, ts) && AppConfigEx.IsOptionEnforced(tsCfg, "Enabled")) { m_cbEnableTriggers.Enabled = false; } }
internal static void ApplyToConfig() { try { AppConfigEx cfg = Program.Config; if (!AppPolicy.Current.UnhidePasswords) { List <AceColumn> l = cfg.MainWindow.EntryListColumns; foreach (AceColumn c in l) { if (c == null) { Debug.Assert(false); continue; } if (c.Type == AceColumnType.Password) { c.HideWithAsterisks = true; } } } } catch (Exception) { Debug.Assert(false); } }
private void LoadIntegrationOptions() { Keys kAT = (Keys)Program.Config.Integration.HotKeyGlobalAutoType; m_hkGlobalAutoType.HotKey = (kAT & Keys.KeyCode); m_hkGlobalAutoType.HotKeyModifiers = (kAT & Keys.Modifiers); m_hkGlobalAutoType.RenderHotKey(); m_kPrevATHKKey = (m_hkGlobalAutoType.HotKey | m_hkGlobalAutoType.HotKeyModifiers); if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "HotKeyGlobalAutoType")) { m_hkGlobalAutoType.Enabled = false; } Keys kATS = (Keys)Program.Config.Integration.HotKeySelectedAutoType; m_hkSelectedAutoType.HotKey = (kATS & Keys.KeyCode); m_hkSelectedAutoType.HotKeyModifiers = (kATS & Keys.Modifiers); m_hkSelectedAutoType.RenderHotKey(); m_kPrevATSHKKey = (m_hkSelectedAutoType.HotKey | m_hkSelectedAutoType.HotKeyModifiers); if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "HotKeySelectedAutoType")) { m_hkSelectedAutoType.Enabled = false; } Keys kSW = (Keys)Program.Config.Integration.HotKeyShowWindow; m_hkShowWindow.HotKey = (kSW & Keys.KeyCode); m_hkShowWindow.HotKeyModifiers = (kSW & Keys.Modifiers); m_hkShowWindow.RenderHotKey(); m_kPrevSWHKKey = (m_hkShowWindow.HotKey | m_hkShowWindow.HotKeyModifiers); if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "HotKeyShowWindow")) { m_hkShowWindow.Enabled = false; } m_cbAutoRun.Checked = ShellUtil.GetStartWithWindows(AppDefs.AutoRunName); m_cbSingleClickTrayAction.Checked = Program.Config.UI.TrayIcon.SingleClickDefault; if (AppConfigEx.IsOptionEnforced(Program.Config.UI.TrayIcon, "SingleClickDefault")) { m_cbSingleClickTrayAction.Enabled = false; } string strOverride = Program.Config.Integration.UrlOverride; m_cbUrlOverride.Checked = (strOverride.Length > 0); m_tbUrlOverride.Text = strOverride; if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "UrlOverride")) { m_cbUrlOverride.Enabled = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "UrlSchemeOverrides")) { m_btnSchemeOverrides.Enabled = false; } }
/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { m_bDesignMode = false; // Again, for the ones not calling Main int nRandomSeed = (int)DateTime.UtcNow.Ticks; // Prevent overflow (see Random class constructor) if (nRandomSeed == int.MinValue) { nRandomSeed = 17; } m_rndGlobal = new Random(nRandomSeed); InitEnvSecurity(); MonoWorkarounds.Initialize(); // try { NativeMethods.SetProcessDPIAware(); } // catch(Exception) { } try { SelfTest.TestFipsComplianceProblems(); } catch (Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return(false); } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; KdbxFile.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); m_appConfig.Apply(AceApplyFlags.All); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; // InitEnvWorkarounds(); LoadTranslation(); CustomResourceManager.Override(typeof(KeePass.Properties.Resources)); return(true); }
private void CleanUpEx() { int nTab = m_tabMain.SelectedIndex; if ((nTab >= 0) && (nTab < m_tabMain.TabPages.Count)) { Program.Config.Defaults.OptionsTabIndex = (uint)nTab; } m_cdxSecurityOptions.Release(); m_cdxPolicy.Release(); m_cdxGuiOptions.Release(); m_cdxAdvanced.Release(); AppConfigEx.ClearXmlPathCache(); }
private void DetermineReadOnlyState(ClviInfo clvi) { if (clvi == null) { Debug.Assert(false); return; } if (!m_bUseEnforcedConfig) { clvi.ReadOnly = false; } else { clvi.ReadOnly = AppConfigEx.IsOptionEnforced(clvi.Object, clvi.PropertyInfo); } }
/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { int nRandomSeed = (int)DateTime.UtcNow.Ticks; // Prevent overflow (see Random class constructor) if (nRandomSeed == int.MinValue) { nRandomSeed = 17; } m_rndGlobal = new Random(nRandomSeed); InitEnvSecurity(); try { SelfTest.TestFipsComplianceProblems(); } catch (Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return(false); } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); IOConnection.SetProxy(m_appConfig.Integration.ProxyType, m_appConfig.Integration.ProxyAddress, m_appConfig.Integration.ProxyPort, m_appConfig.Integration.ProxyUserName, m_appConfig.Integration.ProxyPassword); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; LoadTranslation(); return(true); }
private void OnFormLoad(object sender, EventArgs e) { GlobalWindowManager.AddWindow(this, this); BannerFactory.CreateBannerEx(this, m_bannerImage, Properties.Resources.B48x48_Folder_Download, KPRes.HelpSourceSelection, KPRes.HelpSourceSelectionDesc); this.Icon = AppIcons.Default; this.Text = KPRes.HelpSourceSelection; FontUtil.AssignDefaultBold(m_radioLocal); FontUtil.AssignDefaultBold(m_radioOnline); Debug.Assert(!m_lblLocal.AutoSize); // For RTL support if (!AppHelp.LocalHelpAvailable) { UIUtil.SetEnabledFast(false, m_radioLocal, m_lblLocal); m_lblLocal.Text = KPRes.HelpSourceNoLocalOption; AppHelp.PreferredHelpSource = AppHelpSource.Online; } bool bOverride = !string.IsNullOrEmpty(Program.Config.Application.HelpUrl); bool bEnforced = AppConfigEx.IsOptionEnforced(Program.Config.Application, "HelpUseLocal"); if (!bOverride) { if (AppHelp.PreferredHelpSource == AppHelpSource.Local) { m_radioLocal.Checked = true; } else { m_radioOnline.Checked = true; } } if (bOverride || bEnforced) { UIUtil.SetEnabledFast(false, m_radioLocal, m_lblLocal, m_radioOnline, m_lblOnline, m_btnOK); UIUtil.SetFocus(m_btnCancel, this); } }
private void CleanUpEx() { int nTab = m_tabMain.SelectedIndex; if ((nTab >= 0) && (nTab < m_tabMain.TabPages.Count)) { Program.Config.Defaults.OptionsTabIndex = (uint)nTab; } m_tabMain.ImageList = null; // Detach event handlers UIUtil.DisposeButtonImage(m_btnCustomAltColor, ref m_imgAltItemBg); m_cdxSecurityOptions.Release(); m_cdxPolicy.Release(); m_cdxGuiOptions.Release(); m_cdxAdvanced.Release(); AppConfigEx.ClearXmlPathCache(); }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); } catch(FileNotFoundException) { } // Ignore catch(Exception) { Debug.Assert(false); } } m_cmdLineArgs = new CommandLineArgs(args); if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch(Exception) { Debug.Assert(false); } if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { try { NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, m_nAppMessage, (IntPtr)AppMessage.Exit, IntPtr.Zero); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch(Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
private void LoadAdvancedOptions() { bool?obNoMin = null; if (MonoWorkarounds.IsRequired(1418)) { obNoMin = true; } m_lvAdvanced.Columns.Add(string.Empty); // Resize below m_cdxAdvanced = new CheckedLVItemDXList(m_lvAdvanced, true); ListViewGroup lvg = new ListViewGroup(KPRes.StartAndExit); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "OpenLastFile", lvg, KPRes.AutoRememberOpenLastFile); m_cdxAdvanced.CreateItem(Program.Config.Integration, "LimitToSingleInstance", lvg, KPRes.LimitSingleInstance); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "CheckForUpdate", lvg, KPRes.CheckForUpdAtStart); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "MinimizedAndLocked", lvg, KPRes.StartMinimizedAndLocked, obNoMin); m_cdxAdvanced.CreateItem(Program.Config.Application.FileClosing, "AutoSave", lvg, KPRes.AutoSaveAtExit); m_cdxAdvanced.CreateItem(Program.Config.Application, "AutoSaveAfterEntryEdit", lvg, KPRes.AutoSaveAfterEntryEdit); lvg = new ListViewGroup(KPRes.AfterDatabaseOpen); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Application.FileOpening, "ShowExpiredEntries", lvg, KPRes.AutoShowExpiredEntries); m_cdxAdvanced.CreateItem(Program.Config.Application.FileOpening, "ShowSoonToExpireEntries", lvg, KPRes.AutoShowSoonToExpireEntries); lvg = new ListViewGroup(KPRes.AutoType); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByTitle", lvg, KPRes.AutoTypeMatchByTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByUrlInTitle", lvg, KPRes.AutoTypeMatchByUrlInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByUrlHostInTitle", lvg, KPRes.AutoTypeMatchByUrlHostInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByTagInTitle", lvg, KPRes.AutoTypeMatchByTagInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeExpiredCanMatch", lvg, KPRes.ExpiredEntriesCanMatch); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeAlwaysShowSelDialog", lvg, KPRes.AutoTypeAlwaysShowSelDialog); lvg = new ListViewGroup(KPRes.AutoType + " - " + KPRes.SendingNoun); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypePrependInitSequenceForIE", lvg, KPRes.AutoTypePrependInitSeqForIE); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeReleaseAltWithKeyPress", lvg, KPRes.AutoTypeReleaseAltWithKeyPress); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeAdjustKeyboardLayout", lvg, KPRes.SameKeybLayout); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeAllowInterleaved", lvg, KPRes.InterleavedKeySending); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeCancelOnWindowChange", lvg, KPRes.AutoTypeCancelOnWindowChange); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeCancelOnTitleChange", lvg, KPRes.AutoTypeCancelOnTitleChange); lvg = new ListViewGroup(KPRes.IOConnectionLong); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Application, "VerifyWrittenFileAfterSaving", lvg, KPRes.VerifyWrittenFileAfterSave); m_cdxAdvanced.CreateItem(Program.Config.Application, "UseTransactedFileWrites", lvg, KPRes.UseTransactedDatabaseWrites); m_cdxAdvanced.CreateItem(Program.Config.Application, "FileTxExtra", lvg, KPRes.FileTxExtra + " (" + KPRes.Slow + ")"); m_cdxAdvanced.CreateItem(Program.Config.Application, "UseFileLocks", lvg, KPRes.UseFileLocks + " " + KPRes.NotRecommended); m_cdxAdvanced.CreateItem(Program.Config.Application, "SaveForceSync", lvg, KPRes.SaveForceSync); m_cdxAdvanced.CreateItem(Program.Config.Security, "SslCertsAcceptInvalid", lvg, KPRes.SslCertsAcceptInvalid); lvg = new ListViewGroup(KPRes.Advanced); m_lvAdvanced.Groups.Add(lvg); if (!Program.Config.Integration.SearchKeyFiles) { Program.Config.Integration.SearchKeyFilesOnRemovableMedia = false; } ListViewItem lviSearch = m_cdxAdvanced.CreateItem( Program.Config.Integration, "SearchKeyFiles", lvg, KPRes.SearchKeyFiles); ListViewItem lviSearchRmv = m_cdxAdvanced.CreateItem( Program.Config.Integration, "SearchKeyFilesOnRemovableMedia", lvg, KPRes.SearchKeyFilesAlsoOnRemovable); m_cdxAdvanced.AddLink(lviSearch, lviSearchRmv, CheckItemLinkType.UncheckedUnchecked); m_cdxAdvanced.AddLink(lviSearchRmv, lviSearch, CheckItemLinkType.CheckedChecked); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "RememberKeySources", lvg, KPRes.RememberKeySources); m_cdxAdvanced.CreateItem(Program.Config.Application, "RememberWorkingDirectories", lvg, KPRes.RememberWorkingDirectories); m_cdxAdvanced.CreateItem(Program.Config.UI.Hiding, "SeparateHidingSettings", lvg, KPRes.RememberHidingSettings); m_cdxAdvanced.CreateItem(Program.Config.UI.Hiding, "UnhideButtonAlsoUnhidesSource", lvg, KPRes.UnhideSourceCharactersToo); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "TanExpiresOnUse", lvg, KPRes.TanExpiresOnUse); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "RecycleBinCollapse", lvg, KPRes.RecycleBinCollapse); m_cdxAdvanced.CreateItem(Program.Config.UI, "SecureDesktopPlaySound", lvg, KPRes.SecDeskPlaySound); m_cdxAdvanced.CreateItem(Program.Config.UI, "OptimizeForScreenReader", lvg, KPRes.OptimizeForScreenReader); m_cdxAdvanced.UpdateData(false); UIUtil.ResizeColumns(m_lvAdvanced, true); if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "ProxyType") || AppConfigEx.IsOptionEnforced(Program.Config.Integration, "ProxyAddress")) { m_btnProxy.Enabled = false; } }
private void LoadGuiOptions() { m_strInitialTsRenderer = Program.Config.UI.ToolStripRenderer; bool?obNoMin = null; if (MonoWorkarounds.IsRequired(1418)) { obNoMin = true; } m_lvGuiOptions.Columns.Add(KPRes.Options); // Resize below ListViewGroup lvg = new ListViewGroup(KPRes.MainWindow); m_lvGuiOptions.Groups.Add(lvg); Debug.Assert(lvg.ListView == m_lvGuiOptions); m_cdxGuiOptions = new CheckedLVItemDXList(m_lvGuiOptions, true); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeToTray", lvg, KPRes.MinimizeToTray); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "DropToBackAfterClipboardCopy", lvg, KPRes.DropToBackOnCopy); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterClipboardCopy", lvg, KPRes.MinimizeAfterCopy); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterAutoType", lvg, KPRes.MinimizeAfterAutoType); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterLocking", lvg, KPRes.MinimizeAfterLocking); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterOpeningDatabase", lvg, KPRes.MinimizeAfterOpeningDatabase, obNoMin); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "CloseButtonMinimizesWindow", lvg, KPRes.CloseButtonMinimizes); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EscMinimizesToTray", lvg, KPRes.EscMinimizesToTray); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "ShowFullPathInTitle", lvg, KPRes.ShowFullPathInTitleBar); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "DisableSaveIfNotModified", lvg, KPRes.DisableSaveIfNotModified); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "HideCloseDatabaseButton", lvg, KPRes.HideCloseDatabaseTb); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ShowAdvAutoTypeCommands", lvg, KPRes.ShowAdvAutoTypeCommands); lvg = new ListViewGroup(KPRes.EntryList); m_lvGuiOptions.Groups.Add(lvg); // m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "ShowGridLines", // m_lvGuiOptions, lvg, KPRes.ShowGridLines); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntryListAutoResizeColumns", lvg, KPRes.EntryListAutoResizeColumns); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntryListAlternatingBgColors", lvg, KPRes.AlternatingBgColors); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "CopyUrlsInsteadOfOpening", lvg, KPRes.CopyUrlsInsteadOfOpening); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntrySelGroupSel", lvg, KPRes.EntrySelGroupSel); if (!Program.Config.MainWindow.EntryListShowDerefData) { Debug.Assert(!Program.Config.MainWindow.EntryListShowDerefDataAsync); Program.Config.MainWindow.EntryListShowDerefDataAsync = false; } ListViewItem lviDeref = m_cdxGuiOptions.CreateItem( Program.Config.MainWindow, "EntryListShowDerefData", lvg, KPRes.ShowDerefData + " (" + KPRes.Slow + ")"); ListViewItem lviDerefAsync = m_cdxGuiOptions.CreateItem( Program.Config.MainWindow, "EntryListShowDerefDataAsync", lvg, KPRes.ShowDerefDataAsync + " (" + KPRes.IncompatibleWithSorting + ")"); m_cdxGuiOptions.AddLink(lviDeref, lviDerefAsync, CheckItemLinkType.UncheckedUnchecked); m_cdxGuiOptions.AddLink(lviDerefAsync, lviDeref, CheckItemLinkType.CheckedChecked); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntryListShowDerefDataAndRefs", lvg, KPRes.ShowDerefDataAndRefs); // lvg = new ListViewGroup(KPRes.EntryView); // m_lvGuiOptions.Groups.Add(lvg); // m_cdxGuiOptions.CreateItem(Program.Config.MainWindow.EntryView, "HideProtectedCustomStrings", // lvg, KPRes.EntryViewHideProtectedCustomStrings); lvg = new ListViewGroup(KPRes.QuickSearchTb); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindSearchInPasswords", lvg, KPRes.QuickSearchInPwFields); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindExcludeExpired", lvg, KPRes.QuickSearchExclExpired); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindDerefData", lvg, KPRes.QuickSearchDerefData + " (" + KPRes.Slow + ")"); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusResultsAfterQuickFind", lvg, KPRes.FocusResultsAfterQuickSearch); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusQuickFindOnRestore", lvg, KPRes.FocusQuickFindOnRestore); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusQuickFindOnUntray", lvg, KPRes.FocusQuickFindOnUntray); lvg = new ListViewGroup(KPRes.TrayIcon); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.UI.TrayIcon, "ShowOnlyIfTrayed", lvg, KPRes.ShowTrayOnlyIfTrayed); m_cdxGuiOptions.CreateItem(Program.Config.UI.TrayIcon, "GrayIcon", lvg, KPRes.TrayIconGray); m_cdxGuiOptions.CreateItem(Program.Config.UI.TrayIcon, "SingleClickDefault", lvg, KPRes.TrayIconSingleClick); lvg = new ListViewGroup(KPRes.Dialogs); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ShowRecycleConfirmDialog", lvg, KPRes.RecycleShowConfirm); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ShowDbMntncResultsDialog", lvg, KPRes.DbMntncResults); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ShowEmSheetDialog", lvg, KPRes.EmergencySheetAsk); lvg = new ListViewGroup(KPRes.Advanced); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.UI, "RepeatPasswordOnlyWhenHidden", lvg, KPRes.RepeatOnlyWhenHidden); // m_cdxGuiOptions.CreateItem(Program.Config.UI, "UseCustomToolStripRenderer", // lvg, KPRes.UseCustomToolStripRenderer); m_cdxGuiOptions.CreateItem(Program.Config.UI, "TreeViewShowLines", lvg, KPRes.TreeViewShowLines); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ForceSystemFontUnix", lvg, KPRes.ForceSystemFontUnix); m_cdxGuiOptions.UpdateData(false); UIUtil.ResizeColumns(m_lvGuiOptions, true); try { m_numMruCount.Value = Program.Config.Application.MostRecentlyUsed.MaxItemCount; } catch (Exception) { Debug.Assert(false); m_numMruCount.Value = AceMru.DefaultMaxItemCount; } if (AppConfigEx.IsOptionEnforced(Program.Config.Application.MostRecentlyUsed, "MaxItemCount")) { m_lblMruCount.Enabled = false; m_numMruCount.Enabled = false; } m_argbAltItemBg = Program.Config.MainWindow.EntryListAlternatingBgColor; m_cbCustomAltColor.Checked = (m_argbAltItemBg != 0); UpdateButtonImages(); if (AppConfigEx.IsOptionEnforced(Program.Config.UI, "StandardFont")) { m_btnSelFont.Enabled = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.UI, "PasswordFont") || MonoWorkarounds.IsRequired(5795)) { m_btnSelPwFont.Enabled = false; } }
private void LoadSecurityOptions() { AceWorkspaceLocking aceWL = Program.Config.Security.WorkspaceLocking; uint uLockTime = aceWL.LockAfterTime; bool bLockTime = (uLockTime > 0); m_numLockAfterTime.Value = (bLockTime ? uLockTime : 300); m_cbLockAfterTime.Checked = bLockTime; if (AppConfigEx.IsOptionEnforced(aceWL, "LockAfterTime")) { m_cbLockAfterTime.Enabled = false; } uLockTime = aceWL.LockAfterGlobalTime; bLockTime = (uLockTime > 0); m_numLockAfterGlobalTime.Value = (bLockTime ? uLockTime : 240); m_cbLockAfterGlobalTime.Checked = bLockTime; if (AppConfigEx.IsOptionEnforced(aceWL, "LockAfterGlobalTime")) { m_cbLockAfterGlobalTime.Enabled = false; } int nDefaultExpireDays = Program.Config.Defaults.NewEntryExpiresInDays; if (nDefaultExpireDays < 0) { m_cbDefaultExpireDays.Checked = false; } else { m_cbDefaultExpireDays.Checked = true; try { m_numDefaultExpireDays.Value = nDefaultExpireDays; } catch (Exception) { Debug.Assert(false); } } if (AppConfigEx.IsOptionEnforced(Program.Config.Defaults, "NewEntryExpiresInDays")) { m_cbDefaultExpireDays.Enabled = false; } int nClipClear = Program.Config.Security.ClipboardClearAfterSeconds; if (nClipClear >= 0) { m_cbClipClearTime.Checked = true; m_numClipClearTime.Value = nClipClear; } else { m_cbClipClearTime.Checked = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.Security, "ClipboardClearAfterSeconds")) { m_cbClipClearTime.Enabled = false; } m_lvSecurityOptions.Columns.Add(string.Empty); // Resize below ListViewGroup lvg = new ListViewGroup(KPRes.Options); m_lvSecurityOptions.Groups.Add(lvg); Debug.Assert(lvg.ListView == m_lvSecurityOptions); m_cdxSecurityOptions = new CheckedLVItemDXList(m_lvSecurityOptions, true); bool? obNoSEv = null; // Allow read-only by enforced config string strSEvSuffix = string.Empty; if (MonoWorkarounds.IsRequired(1378)) { obNoSEv = true; strSEvSuffix = " (" + KPRes.UnsupportedByMono + ")"; } m_cdxSecurityOptions.CreateItem(aceWL, "LockOnWindowMinimize", lvg, KPRes.LockOnMinimizeTaskbar); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnWindowMinimizeToTray", lvg, KPRes.LockOnMinimizeTray); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnSessionSwitch", lvg, KPRes.LockOnSessionSwitch + strSEvSuffix, obNoSEv); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnSuspend", lvg, KPRes.LockOnSuspend + strSEvSuffix, obNoSEv); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnRemoteControlChange", lvg, KPRes.LockOnRemoteControlChange + strSEvSuffix, obNoSEv); m_cdxSecurityOptions.CreateItem(aceWL, "ExitInsteadOfLockingAfterTime", lvg, KPRes.ExitInsteadOfLockingAfterTime); m_cdxSecurityOptions.CreateItem(aceWL, "AlwaysExitInsteadOfLocking", lvg, KPRes.ExitInsteadOfLockingAlways); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "ClipboardClearOnExit", lvg, KPRes.ClipboardClearOnExit); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "UseClipboardViewerIgnoreFormat", lvg, KPRes.ClipboardViewerIgnoreFormat + " " + KPRes.NotRecommended); if (NativeLib.IsLibraryInstalled()) { m_cdxSecurityOptions.CreateItem(Program.Config.Native, "NativeKeyTransformations", lvg, KPRes.NativeLibUse); } bool?obNoWin = null; // Allow read-only by enforced config if (NativeLib.IsUnix()) { obNoWin = true; } m_cdxSecurityOptions.CreateItem(Program.Config.Security, "MasterKeyOnSecureDesktop", lvg, KPRes.MasterKeyOnSecureDesktop, obNoWin); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "ClearKeyCommandLineParams", lvg, KPRes.ClearKeyCmdLineParams); m_cdxSecurityOptions.CreateItem(Program.Config.Security.MasterPassword, "RememberWhileOpen", lvg, KPRes.MasterPasswordRmbWhileOpen); m_cdxSecurityOptions.UpdateData(false); UIUtil.ResizeColumns(m_lvSecurityOptions, true); }
public static AppConfigEx Load() { AppConfigSerializer.GetConfigPaths(); // AppConfigEx cfgEnf = LoadConfigFileEx(m_strEnforcedConfigFile); // if(cfgEnf != null) // { // cfgEnf.Meta.IsEnforcedConfiguration = true; // return cfgEnf; // } XmlDocument xdEnforced = LoadEnforcedConfigFile(); AppConfigEx cfgGlobal = LoadConfigFileEx(m_strGlobalConfigFile, xdEnforced); AppConfigEx cfgUser = LoadConfigFileEx(m_strUserConfigFile, xdEnforced); if((cfgGlobal == null) && (cfgUser == null)) { if(xdEnforced != null) { XmlSerializerEx xmlSerial = new XmlSerializerEx(typeof(AppConfigEx)); try { MemoryStream msEnf = new MemoryStream(); xdEnforced.Save(msEnf); MemoryStream msRead = new MemoryStream(msEnf.ToArray(), false); AppConfigEx cfgEnf = (AppConfigEx)xmlSerial.Deserialize(msRead); cfgEnf.OnLoad(); msRead.Close(); msEnf.Close(); return cfgEnf; } catch(Exception) { Debug.Assert(false); } } AppConfigEx cfgNew = new AppConfigEx(); cfgNew.OnLoad(); // Create defaults return cfgNew; } else if((cfgGlobal != null) && (cfgUser == null)) return cfgGlobal; else if((cfgGlobal == null) && (cfgUser != null)) return cfgUser; cfgUser.Meta.PreferUserConfiguration = cfgGlobal.Meta.PreferUserConfiguration; return (cfgGlobal.Meta.PreferUserConfiguration ? cfgUser : cfgGlobal); }
private static bool SaveConfigFileEx(AppConfigEx tConfig, string strFilePath, bool bRemoveConfigPref) { tConfig.OnSavePre(); XmlSerializerEx xmlSerial = new XmlSerializerEx(typeof(AppConfigEx)); bool bResult = true; // FileStream fs = null; IOConnectionInfo iocPath = IOConnectionInfo.FromPath(strFilePath); FileTransactionEx fts = new FileTransactionEx(iocPath, true); Stream fs = null; // Temporarily remove user file preference (restore after saving) bool bConfigPref = tConfig.Meta.PreferUserConfiguration; if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = false; XmlWriterSettings xws = new XmlWriterSettings(); xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; try { // fs = new FileStream(strFilePath, FileMode.Create, // FileAccess.Write, FileShare.None); fs = fts.OpenWrite(); if(fs == null) throw new InvalidOperationException(); XmlWriter xw = XmlWriter.Create(fs, xws); xmlSerial.Serialize(xw, tConfig); xw.Close(); } catch(Exception) { bResult = false; } // Do not assert if(fs != null) { fs.Close(); fs = null; } if(bResult) { try { fts.CommitWrite(); } catch(Exception) { Debug.Assert(false); } } if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = bConfigPref; tConfig.OnSavePost(); return bResult; }
private void LoadAdvancedOptions() { m_lvAdvanced.Columns.Add(string.Empty, 200); // Resize below m_cdxAdvanced = new CheckedLVItemDXList(m_lvAdvanced, true); ListViewGroup lvg = new ListViewGroup(KPRes.StartAndExit); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "OpenLastFile", lvg, KPRes.AutoRememberOpenLastFile); m_cdxAdvanced.CreateItem(Program.Config.Integration, "LimitToSingleInstance", lvg, KPRes.LimitSingleInstance); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "CheckForUpdate", lvg, KPRes.CheckForUpdAtStart); m_cdxAdvanced.CreateItem(Program.Config.Application.Start, "MinimizedAndLocked", lvg, KPRes.StartMinimizedAndLocked); m_cdxAdvanced.CreateItem(Program.Config.Application.FileClosing, "AutoSave", lvg, KPRes.AutoSaveAtExit); lvg = new ListViewGroup(KPRes.AfterDatabaseOpen); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Application.FileOpening, "ShowExpiredEntries", lvg, KPRes.AutoShowExpiredEntries); m_cdxAdvanced.CreateItem(Program.Config.Application.FileOpening, "ShowSoonToExpireEntries", lvg, KPRes.AutoShowSoonToExpireEntries); lvg = new ListViewGroup(KPRes.AutoType); m_lvAdvanced.Groups.Add(lvg); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByTitle", lvg, KPRes.AutoTypeMatchByTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByUrlInTitle", lvg, KPRes.AutoTypeMatchByUrlInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByUrlHostInTitle", lvg, KPRes.AutoTypeMatchByUrlHostInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeMatchByTagInTitle", lvg, KPRes.AutoTypeMatchByTagInTitle); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypePrependInitSequenceForIE", lvg, KPRes.AutoTypePrependInitSeqForIE); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeReleaseAltWithKeyPress", lvg, KPRes.AutoTypeReleaseAltWithKeyPress); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeAdjustKeyboardLayout", lvg, KPRes.SameKeybLayout); m_cdxAdvanced.CreateItem(Program.Config.Integration, "AutoTypeCancelOnWindowChange", lvg, KPRes.AutoTypeCancelOnWindowChange); lvg = new ListViewGroup(KPRes.Advanced); m_lvAdvanced.Groups.Add(lvg); if (!Program.Config.Integration.SearchKeyFiles) { Program.Config.Integration.SearchKeyFilesOnRemovableMedia = false; } ListViewItem lviSearch = m_cdxAdvanced.CreateItem( Program.Config.Integration, "SearchKeyFiles", lvg, KPRes.SearchKeyFiles); ListViewItem lviSearchRmv = m_cdxAdvanced.CreateItem( Program.Config.Integration, "SearchKeyFilesOnRemovableMedia", lvg, KPRes.SearchKeyFilesAlsoOnRemovable); m_cdxAdvanced.AddLink(lviSearch, lviSearchRmv, CheckItemLinkType.UncheckedUnchecked); m_cdxAdvanced.AddLink(lviSearchRmv, lviSearch, CheckItemLinkType.CheckedChecked); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "RememberKeySources", lvg, KPRes.RememberKeySources); m_cdxAdvanced.CreateItem(Program.Config.UI.Hiding, "SeparateHidingSettings", lvg, KPRes.RememberHidingSettings); m_cdxAdvanced.CreateItem(Program.Config.UI.Hiding, "UnhideButtonAlsoUnhidesSource", lvg, KPRes.UnhideSourceCharactersToo); m_cdxAdvanced.CreateItem(Program.Config.Application, "VerifyWrittenFileAfterSaving", lvg, KPRes.VerifyWrittenFileAfterSave); m_cdxAdvanced.CreateItem(Program.Config.Application, "UseTransactedFileWrites", lvg, KPRes.UseTransactedDatabaseWrites); m_cdxAdvanced.CreateItem(Program.Config.Application, "UseFileLocks", lvg, KPRes.UseFileLocks + " " + KPRes.NotRecommended); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "TanExpiresOnUse", lvg, KPRes.TanExpiresOnUse); m_cdxAdvanced.CreateItem(Program.Config.Defaults, "RecycleBinCollapse", lvg, KPRes.RecycleBinCollapse); m_cdxAdvanced.CreateItem(Program.Config.UI, "SecureDesktopPlaySound", lvg, KPRes.SecDeskPlaySound); m_cdxAdvanced.CreateItem(Program.Config.UI, "OptimizeForScreenReader", lvg, KPRes.OptimizeForScreenReader); m_cdxAdvanced.UpdateData(false); m_lvAdvanced.Columns[0].Width = m_lvAdvanced.ClientRectangle.Width - UIUtil.GetVScrollBarWidth() - 1; if (AppConfigEx.IsOptionEnforced(Program.Config.Integration, "ProxyType") || AppConfigEx.IsOptionEnforced(Program.Config.Integration, "ProxyAddress")) { m_btnProxy.Enabled = false; } }
/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { int nRandomSeed = (int)DateTime.UtcNow.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); InitEnvSecurity(); try { SelfTest.TestFipsComplianceProblems(); } catch(Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return false; } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; KdbxFile.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); IOConnection.SetProxy(m_appConfig.Integration.ProxyType, m_appConfig.Integration.ProxyAddress, m_appConfig.Integration.ProxyPort, m_appConfig.Integration.ProxyUserName, m_appConfig.Integration.ProxyPassword); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; LoadTranslation(); return true; }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if (nRandomSeed == int.MinValue) { nRandomSeed = 17; } m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if ((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); } catch (FileNotFoundException) { } // Ignore catch (Exception) { Debug.Assert(false); } } m_cmdLineArgs = new CommandLineArgs(args); if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if ((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch (Exception) { Debug.Assert(false); } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { try { NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, m_nAppMessage, (IntPtr)AppMessage.Exit, IntPtr.Zero); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if ((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch (Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if (mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if (mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
private void LoadGuiOptions() { m_bInitialTsRenderer = Program.Config.UI.UseCustomToolStripRenderer; m_lvGuiOptions.Columns.Add(KPRes.Options, 200); // Resize below ListViewGroup lvg = new ListViewGroup(KPRes.MainWindow); m_lvGuiOptions.Groups.Add(lvg); Debug.Assert(lvg.ListView == m_lvGuiOptions); m_cdxGuiOptions = new CheckedLVItemDXList(m_lvGuiOptions, true); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "CloseButtonMinimizesWindow", lvg, KPRes.CloseButtonMinimizes); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeToTray", lvg, KPRes.MinimizeToTray); m_cdxGuiOptions.CreateItem(Program.Config.UI.TrayIcon, "ShowOnlyIfTrayed", lvg, KPRes.ShowTrayOnlyIfTrayed); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "ShowFullPathInTitle", lvg, KPRes.ShowFullPathInTitleBar); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "DropToBackAfterClipboardCopy", lvg, KPRes.DropToBackOnCopy); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterClipboardCopy", lvg, KPRes.MinimizeAfterCopy); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterLocking", lvg, KPRes.MinimizeAfterLocking); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "MinimizeAfterOpeningDatabase", lvg, KPRes.MinimizeAfterOpeningDatabase); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "DisableSaveIfNotModified", lvg, KPRes.DisableSaveIfNotModified); lvg = new ListViewGroup(KPRes.EntryList); m_lvGuiOptions.Groups.Add(lvg); // m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "ShowGridLines", // m_lvGuiOptions, lvg, KPRes.ShowGridLines); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntryListAutoResizeColumns", lvg, KPRes.EntryListAutoResizeColumns); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "EntryListAlternatingBgColors", lvg, KPRes.AlternatingBgColors); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "CopyUrlsInsteadOfOpening", lvg, KPRes.CopyUrlsInsteadOfOpening); if (!Program.Config.MainWindow.EntryListShowDerefData) { Debug.Assert(!Program.Config.MainWindow.EntryListShowDerefDataAsync); Program.Config.MainWindow.EntryListShowDerefDataAsync = false; } ListViewItem lviDeref = m_cdxGuiOptions.CreateItem( Program.Config.MainWindow, "EntryListShowDerefData", lvg, KPRes.ShowDerefData + " (" + KPRes.Slow + ")"); ListViewItem lviDerefAsync = m_cdxGuiOptions.CreateItem( Program.Config.MainWindow, "EntryListShowDerefDataAsync", lvg, KPRes.ShowDerefDataAsync + " (" + KPRes.IncompatibleWithSorting + ")"); m_cdxGuiOptions.AddLink(lviDeref, lviDerefAsync, CheckItemLinkType.UncheckedUnchecked); m_cdxGuiOptions.AddLink(lviDerefAsync, lviDeref, CheckItemLinkType.CheckedChecked); // lvg = new ListViewGroup(KPRes.EntryView); // m_lvGuiOptions.Groups.Add(lvg); // m_cdxGuiOptions.CreateItem(Program.Config.MainWindow.EntryView, "HideProtectedCustomStrings", // lvg, KPRes.EntryViewHideProtectedCustomStrings); lvg = new ListViewGroup(KPRes.QuickSearchTb); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindSearchInPasswords", lvg, KPRes.QuickSearchInPwFields); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindExcludeExpired", lvg, KPRes.QuickSearchExclExpired); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "QuickFindDerefData", lvg, KPRes.QuickSearchDerefData + " (" + KPRes.Slow + ")"); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusResultsAfterQuickFind", lvg, KPRes.FocusResultsAfterQuickSearch); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusQuickFindOnRestore", lvg, KPRes.FocusQuickFindOnRestore); m_cdxGuiOptions.CreateItem(Program.Config.MainWindow, "FocusQuickFindOnUntray", lvg, KPRes.FocusQuickFindOnUntray); lvg = new ListViewGroup(KPRes.Advanced); m_lvGuiOptions.Groups.Add(lvg); m_cdxGuiOptions.CreateItem(Program.Config.UI, "RepeatPasswordOnlyWhenHidden", lvg, KPRes.RepeatOnlyWhenHidden); m_cdxGuiOptions.CreateItem(Program.Config.UI, "UseCustomToolStripRenderer", lvg, KPRes.UseCustomToolStripRenderer); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ForceSystemFontUnix", lvg, KPRes.ForceSystemFontUnix); m_cdxGuiOptions.CreateItem(Program.Config.UI, "ShowDbMntncResultsDialog", lvg, KPRes.DbMntncResults); m_cdxGuiOptions.UpdateData(false); m_lvGuiOptions.Columns[0].Width = m_lvGuiOptions.ClientRectangle.Width - UIUtil.GetVScrollBarWidth() - 1; try { m_numMruCount.Value = Program.Config.Application.MostRecentlyUsed.MaxItemCount; } catch (Exception) { Debug.Assert(false); m_numMruCount.Value = AceMru.DefaultMaxItemCount; } if (AppConfigEx.IsOptionEnforced(Program.Config.Application.MostRecentlyUsed, "MaxItemCount")) { m_lblMruCount.Enabled = false; m_numMruCount.Enabled = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.UI, "StandardFont")) { m_btnSelFont.Enabled = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.UI, "PasswordFont")) { m_btnSelPwFont.Enabled = false; } }
private void LoadSecurityOptions() { AceWorkspaceLocking aceWL = Program.Config.Security.WorkspaceLocking; uint uLockTime = aceWL.LockAfterTime; bool bLockTime = (uLockTime > 0); m_numLockAfterTime.Value = (bLockTime ? uLockTime : 300); m_cbLockAfterTime.Checked = bLockTime; if (AppConfigEx.IsOptionEnforced(aceWL, "LockAfterTime")) { m_cbLockAfterTime.Enabled = false; } uLockTime = aceWL.LockAfterGlobalTime; bLockTime = (uLockTime > 0); m_numLockAfterGlobalTime.Value = (bLockTime ? uLockTime : 240); m_cbLockAfterGlobalTime.Checked = bLockTime; if (AppConfigEx.IsOptionEnforced(aceWL, "LockAfterGlobalTime")) { m_cbLockAfterGlobalTime.Enabled = false; } int nDefaultExpireDays = Program.Config.Defaults.NewEntryExpiresInDays; if (nDefaultExpireDays < 0) { m_cbDefaultExpireDays.Checked = false; } else { m_cbDefaultExpireDays.Checked = true; try { m_numDefaultExpireDays.Value = nDefaultExpireDays; } catch (Exception) { Debug.Assert(false); } } if (AppConfigEx.IsOptionEnforced(Program.Config.Defaults, "NewEntryExpiresInDays")) { m_cbDefaultExpireDays.Enabled = false; } int nClipClear = Program.Config.Security.ClipboardClearAfterSeconds; if (nClipClear >= 0) { m_cbClipClearTime.Checked = true; m_numClipClearTime.Value = nClipClear; } else { m_cbClipClearTime.Checked = false; } if (AppConfigEx.IsOptionEnforced(Program.Config.Security, "ClipboardClearAfterSeconds")) { m_cbClipClearTime.Enabled = false; } m_lvSecurityOptions.Columns.Add(string.Empty, 200); // Resize below ListViewGroup lvg = new ListViewGroup(KPRes.Options); m_lvSecurityOptions.Groups.Add(lvg); Debug.Assert(lvg.ListView == m_lvSecurityOptions); m_cdxSecurityOptions = new CheckedLVItemDXList(m_lvSecurityOptions, true); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnWindowMinimize", lvg, KPRes.LockOnMinimize); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnSessionSwitch", lvg, KPRes.LockOnSessionSwitch); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnSuspend", lvg, KPRes.LockOnSuspend); m_cdxSecurityOptions.CreateItem(aceWL, "LockOnRemoteControlChange", lvg, KPRes.LockOnRemoteControlChange); m_cdxSecurityOptions.CreateItem(aceWL, "ExitInsteadOfLockingAfterTime", lvg, KPRes.ExitInsteadOfLockingAfterTime); m_cdxSecurityOptions.CreateItem(aceWL, "AlwaysExitInsteadOfLocking", lvg, KPRes.ExitInsteadOfLockingAlways); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "ClipboardClearOnExit", lvg, KPRes.ClipboardClearOnExit); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "UseClipboardViewerIgnoreFormat", lvg, KPRes.ClipboardViewerIgnoreFormat + " " + KPRes.NotRecommended); if (NativeLib.IsLibraryInstalled()) { m_cdxSecurityOptions.CreateItem(Program.Config.Native, "NativeKeyTransformations", lvg, KPRes.NativeLibUse); } m_cdxSecurityOptions.CreateItem(Program.Config.Security, "MasterKeyOnSecureDesktop", lvg, KPRes.MasterKeyOnSecureDesktop); m_cdxSecurityOptions.CreateItem(Program.Config.Security, "ClearKeyCommandLineParams", lvg, KPRes.ClearKeyCmdLineParams); m_cdxSecurityOptions.UpdateData(false); m_lvSecurityOptions.Columns[0].Width = m_lvSecurityOptions.ClientRectangle.Width - UIUtil.GetVScrollBarWidth() - 1; }
private void OnFormLoad(object sender, EventArgs e) { // Can be invoked by tray command; don't use CenterParent Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen); GlobalWindowManager.AddWindow(this); this.Icon = Properties.Resources.KeePass; Debug.Assert(m_ilIcons != null); if (m_ilIcons != null) { m_tabMain.ImageList = m_ilIcons; m_tabSecurity.ImageIndex = (int)PwIcon.TerminalEncrypted; m_tabPolicy.ImageIndex = (int)PwIcon.List; m_tabGui.ImageIndex = (int)PwIcon.Screen; m_tabIntegration.ImageIndex = (int)PwIcon.Console; m_tabAdvanced.ImageIndex = (int)PwIcon.ClipboardReady; } uint uTab = Program.Config.Defaults.OptionsTabIndex; if (uTab < (uint)m_tabMain.TabPages.Count) { m_tabMain.SelectedTab = m_tabMain.TabPages[(int)uTab]; } m_aceUrlSchemeOverrides = Program.Config.Integration.UrlSchemeOverrides.CloneDeep(); m_cmbBannerStyle.Items.Add("(" + KPRes.CurrentStyle + ")"); m_cmbBannerStyle.Items.Add("WinXP Login"); m_cmbBannerStyle.Items.Add("WinVista Black"); m_cmbBannerStyle.Items.Add("KeePass Win32"); m_cmbBannerStyle.Items.Add("Blue Carbon"); CreateDialogBanner(BannerStyle.Default); // Default forces generation m_cmbBannerStyle.SelectedIndex = (int)BannerStyle.Default; if ((BannerFactory.CustomGenerator != null) || AppConfigEx.IsOptionEnforced(Program.Config.UI, "BannerStyle")) { m_lblBannerStyle.Enabled = false; m_cmbBannerStyle.Enabled = false; } int nWidth = m_lvPolicy.ClientRectangle.Width - UIUtil.GetVScrollBarWidth() - 1; m_lvPolicy.Columns.Add(KPRes.Feature, (nWidth * 10) / 29); m_lvPolicy.Columns.Add(KPRes.Description, (nWidth * 19) / 29); m_hkGlobalAutoType = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbGlobalAutoType, true); m_hkSelectedAutoType = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbSelAutoTypeHotKey, true); m_hkShowWindow = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbShowWindowHotKey, true); if (!NativeLib.IsUnix()) { UIUtil.SetShield(m_btnFileExtCreate, true); UIUtil.SetShield(m_btnFileExtRemove, true); m_linkHotKeyHelp.Visible = false; } else // Unix { Program.Config.Integration.HotKeyGlobalAutoType = (ulong)Keys.None; Program.Config.Integration.HotKeySelectedAutoType = (ulong)Keys.None; Program.Config.Integration.HotKeyShowWindow = (ulong)Keys.None; m_hkGlobalAutoType.Enabled = m_hkSelectedAutoType.Enabled = m_hkShowWindow.Enabled = false; m_btnFileExtCreate.Enabled = m_btnFileExtRemove.Enabled = false; m_cbAutoRun.Enabled = false; } UIUtil.SetExplorerTheme(m_lvSecurityOptions, false); UIUtil.SetExplorerTheme(m_lvPolicy, false); UIUtil.SetExplorerTheme(m_lvGuiOptions, false); UIUtil.SetExplorerTheme(m_lvAdvanced, false); AppConfigEx.ClearXmlPathCache(); LoadOptions(); // if(Program.Config.Meta.IsEnforcedConfiguration) // m_lvPolicy.Enabled = false; UpdateUIState(); }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // Required InitEnvSecurity(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true, false) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft; } catch(FileNotFoundException) { } // Ignore catch(Exception) { Debug.Assert(false); } } if(m_appConfig.Application.Start.PluginCacheClearOnce) { PlgxCache.Clear(); m_appConfig.Application.Start.PluginCacheClearOnce = false; AppConfigSerializer.Save(Program.Config); } m_cmdLineArgs = new CommandLineArgs(args); if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null) { // All important .NET assemblies are in memory now already try { SelfTest.Perform(); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } /* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null) { string strPreLoadPath = WinUtil.GetExecutable().Trim(); if(strPreLoadPath.StartsWith("\"") == false) strPreLoadPath = "\"" + strPreLoadPath + "\""; ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath, @"--" + AppDefs.CommandLineOptions.PreLoad, true); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null) { ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty, string.Empty, false); MainCleanUp(); return; } */ else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null) { Program.Config.Integration.UrlOverride = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetUrlOverride]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null) { Program.Config.Integration.UrlOverride = string.Empty; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null) { try { string strFileOut = UrlUtil.EnsureTerminatingSeparator( Path.GetTempPath(), false) + "KeePass_UrlOverride.tmp"; string strContent = ("[KeePass]\r\nKeeURLOverride=" + Program.Config.Integration.UrlOverride + "\r\n"); File.WriteAllText(strFileOut, strContent); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null) { Program.Config.Application.LanguageFile = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetLanguageFile]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null) { PlgxPlugin.CreateFromCommandLine(); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null) { PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName); MainCleanUp(); return; } #if (DEBUG && !KeePassLibSD) else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null) { PopularPasswords.MakeList(); MainCleanUp(); return; } #endif try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch(Exception) { Debug.Assert(false); } if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Exit); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoType); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null) { string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid]; if(!string.IsNullOrEmpty(strEntryUuid)) { IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl, strEntryUuid, null, null, null, null); IpcUtilEx.SendGlobalMessage(ipUrl); } MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Lock); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Unlock); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); AutoType.InitStatic(); UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter(); Application.AddMessageFilter(nfActivity); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch(Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Application.RemoveMessageFilter(nfActivity); Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // Required InitEnvSecurity(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if (nRandomSeed == int.MinValue) { nRandomSeed = 17; } m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if ((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true, false) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft; } catch (FileNotFoundException) { } // Ignore catch (Exception) { Debug.Assert(false); } } if (m_appConfig.Application.Start.PluginCacheClearOnce) { PlgxCache.Clear(); m_appConfig.Application.Start.PluginCacheClearOnce = false; AppConfigSerializer.Save(Program.Config); } m_cmdLineArgs = new CommandLineArgs(args); if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null) { // All important .NET assemblies are in memory now already try { SelfTest.Perform(); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } /* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null) * { * string strPreLoadPath = WinUtil.GetExecutable().Trim(); * if(strPreLoadPath.StartsWith("\"") == false) * strPreLoadPath = "\"" + strPreLoadPath + "\""; * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath, * @"--" + AppDefs.CommandLineOptions.PreLoad, true); * MainCleanUp(); * return; * } * else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null) * { * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty, * string.Empty, false); * MainCleanUp(); * return; * } */ else if ((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null) { Program.Config.Integration.UrlOverride = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetUrlOverride]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null) { Program.Config.Integration.UrlOverride = string.Empty; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null) { try { string strFileOut = UrlUtil.EnsureTerminatingSeparator( Path.GetTempPath(), false) + "KeePass_UrlOverride.tmp"; string strContent = ("[KeePass]\r\nKeeURLOverride=" + Program.Config.Integration.UrlOverride + "\r\n"); File.WriteAllText(strFileOut, strContent); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null) { Program.Config.Application.LanguageFile = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetLanguageFile]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null) { PlgxPlugin.CreateFromCommandLine(); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null) { PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName); MainCleanUp(); return; } #if (DEBUG && !KeePassLibSD) else if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null) { PopularPasswords.MakeList(); MainCleanUp(); return; } #endif try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch (Exception) { Debug.Assert(false); } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Exit); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoType); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null) { string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid]; if (!string.IsNullOrEmpty(strEntryUuid)) { IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl, strEntryUuid, null, null, null, null); IpcUtilEx.SendGlobalMessage(ipUrl); } MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Lock); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Unlock); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if ((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); AutoType.InitStatic(); UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter(); Application.AddMessageFilter(nfActivity); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch (Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Application.RemoveMessageFilter(nfActivity); Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if (mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if (mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { m_bDesignMode = false; // Again, for the ones not calling Main int nRandomSeed = (int)DateTime.UtcNow.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); InitEnvSecurity(); // try { NativeMethods.SetProcessDPIAware(); } // catch(Exception) { } try { SelfTest.TestFipsComplianceProblems(); } catch(Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return false; } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; KdbxFile.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); m_appConfig.Apply(AceApplyFlags.All); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; // InitEnvWorkarounds(); LoadTranslation(); CustomResourceManager.Override(typeof(KeePass.Properties.Resources)); return true; }
public static bool Save(AppConfigEx tConfig) { Debug.Assert(tConfig != null); if(tConfig == null) throw new ArgumentNullException("tConfig"); AppConfigSerializer.GetConfigPaths(); bool bPreferUser = false; XmlDocument xdEnforced = LoadEnforcedConfigFile(); AppConfigEx cfgGlobal = LoadConfigFileEx(m_strGlobalConfigFile, xdEnforced); if((cfgGlobal != null) && cfgGlobal.Meta.PreferUserConfiguration) bPreferUser = true; if(bPreferUser) { EnsureAppDataDirAvailable(); if(SaveConfigFileEx(tConfig, m_strUserConfigFile, true)) return true; if(SaveConfigFileEx(tConfig, m_strGlobalConfigFile, false)) return true; } else // Don't prefer user -- use global first { if(SaveConfigFileEx(tConfig, m_strGlobalConfigFile, false)) return true; EnsureAppDataDirAvailable(); if(SaveConfigFileEx(tConfig, m_strUserConfigFile, true)) return true; } #if !KeePassLibSD if(Program.MainForm != null) Program.MainForm.SetStatusEx(KPRes.ConfigSaveFailed); #endif return false; }
private void OnFormLoad(object sender, EventArgs e) { // Can be invoked by tray command; don't use CenterParent Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen); // When multiline is enabled, tabs added by plugins can result // in multiple tab rows, cropping the tab content at the bottom; // https://sourceforge.net/p/keepass/discussion/329220/thread/a17a2734/ Debug.Assert(!m_tabMain.Multiline); GlobalWindowManager.AddWindow(this); this.Icon = AppIcons.Default; Debug.Assert(m_ilIcons != null); if (m_ilIcons != null) { m_tabMain.ImageList = m_ilIcons; m_tabSecurity.ImageIndex = (int)PwIcon.TerminalEncrypted; m_tabPolicy.ImageIndex = (int)PwIcon.List; m_tabGui.ImageIndex = (int)PwIcon.Screen; m_tabIntegration.ImageIndex = (int)PwIcon.Console; m_tabAdvanced.ImageIndex = (int)PwIcon.ClipboardReady; } uint uTab = Program.Config.Defaults.OptionsTabIndex; if (uTab < (uint)m_tabMain.TabPages.Count) { m_tabMain.SelectedTab = m_tabMain.TabPages[(int)uTab]; } m_aceUrlSchemeOverrides = Program.Config.Integration.UrlSchemeOverrides.CloneDeep(); m_strUrlOverrideAll = Program.Config.Integration.UrlOverride; Debug.Assert(!m_cmbMenuStyle.Sorted); m_cmbMenuStyle.Items.Add(KPRes.Auto + " (" + KPRes.Recommended + ")"); m_cmbMenuStyle.Items.Add(new string('-', 24)); int nTsrs = 2, iTsrSel = 0, nSuffixes = 0; foreach (TsrFactory fTsr in TsrPool.Factories) { string strSuffix = string.Empty; if (!fTsr.IsSupported()) { strSuffix = " (" + KPRes.IncompatibleEnv + ")"; ++nSuffixes; } string strUuid = Convert.ToBase64String(fTsr.Uuid.UuidBytes); if (Program.Config.UI.ToolStripRenderer == strUuid) { iTsrSel = nTsrs; } m_cmbMenuStyle.Items.Add((fTsr.Name ?? string.Empty) + strSuffix); m_dTsrUuids[nTsrs] = strUuid; ++nTsrs; } Debug.Assert(m_cmbMenuStyle.Items.Count == nTsrs); m_cmbMenuStyle.SelectedIndex = iTsrSel; if (nSuffixes > 0) { m_cmbMenuStyle.DropDownWidth = m_cmbMenuStyle.Width * 2; } if (AppConfigEx.IsOptionEnforced(Program.Config.UI, "ToolStripRenderer")) { m_lblMenuStyle.Enabled = false; m_cmbMenuStyle.Enabled = false; } Debug.Assert(!m_cmbBannerStyle.Sorted); m_cmbBannerStyle.Items.Add("(" + KPRes.CurrentStyle + ")"); m_cmbBannerStyle.Items.Add("Windows XP Login"); m_cmbBannerStyle.Items.Add("Windows Vista Black"); m_cmbBannerStyle.Items.Add("KeePass Win32"); m_cmbBannerStyle.Items.Add("Blue Carbon"); CreateDialogBanner(BannerStyle.Default); // Default forces generation m_cmbBannerStyle.SelectedIndex = (int)BannerStyle.Default; if ((BannerFactory.CustomGenerator != null) || AppConfigEx.IsOptionEnforced(Program.Config.UI, "BannerStyle")) { m_lblBannerStyle.Enabled = false; m_cmbBannerStyle.Enabled = false; } int nWidth = m_lvPolicy.ClientSize.Width - UIUtil.GetVScrollBarWidth(); m_lvPolicy.Columns.Add(KPRes.Feature, (nWidth * 10) / 29); m_lvPolicy.Columns.Add(KPRes.Description, (nWidth * 19) / 29); m_hkGlobalAutoType = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbGlobalAutoType, false); m_hkSelectedAutoType = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbSelAutoTypeHotKey, false); m_hkShowWindow = HotKeyControlEx.ReplaceTextBox(m_grpHotKeys, m_tbShowWindowHotKey, false); if (!NativeLib.IsUnix()) { UIUtil.SetShield(m_btnFileExtCreate, true); UIUtil.SetShield(m_btnFileExtRemove, true); m_linkHotKeyHelp.Visible = false; } else // Unix { m_hkGlobalAutoType.TextNone = KPRes.External; m_hkSelectedAutoType.TextNone = KPRes.External; m_hkShowWindow.TextNone = KPRes.External; m_hkGlobalAutoType.Enabled = m_hkSelectedAutoType.Enabled = m_hkShowWindow.Enabled = false; m_btnFileExtCreate.Enabled = m_btnFileExtRemove.Enabled = false; m_cbAutoRun.Enabled = false; } UIUtil.SetExplorerTheme(m_lvSecurityOptions, false); UIUtil.SetExplorerTheme(m_lvPolicy, false); UIUtil.SetExplorerTheme(m_lvGuiOptions, false); UIUtil.SetExplorerTheme(m_lvAdvanced, false); AppConfigEx.ClearXmlPathCache(); LoadOptions(); // if(Program.Config.Meta.IsEnforcedConfiguration) // m_lvPolicy.Enabled = false; UpdateUIState(); }
private static bool SaveConfigFileEx(AppConfigEx tConfig, string strFilePath, bool bRemoveConfigPref) { tConfig.PrepareSave(); XmlSerializer xmlSerial = new XmlSerializer(typeof(AppConfigEx)); FileStream fs = null; bool bResult = true; // Temporarily remove user file preference (restore after saving) bool bConfigPref = tConfig.Meta.PreferUserConfiguration; if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = false; XmlWriterSettings xws = new XmlWriterSettings(); xws.Encoding = Encoding.UTF8; xws.Indent = true; xws.IndentChars = "\t"; try { fs = new FileStream(strFilePath, FileMode.Create, FileAccess.Write, FileShare.None); XmlWriter xw = XmlWriter.Create(fs, xws); xmlSerial.Serialize(xw, tConfig); xw.Close(); } catch(Exception) { bResult = false; } // Do not assert if(fs != null) { fs.Close(); fs = null; } if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = bConfigPref; return bResult; }
/// <summary> /// Common program initialization function that can also be /// used by applications that use KeePass as a library /// (like e.g. KPScript). /// </summary> public static bool CommonInit() { m_bDesignMode = false; // Again, for the ones not calling Main m_rndGlobal = CryptoRandom.NewWeakRandom(); InitEnvSecurity(); MonoWorkarounds.Initialize(); // Do not run as AppX, because of compatibility problems if (WinUtil.IsAppX) { return(false); } try { SelfTest.TestFipsComplianceProblems(); } catch (Exception exFips) { MessageService.ShowWarning(KPRes.SelfTestFailed, exFips); return(false); } // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; KdbxFile.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if (m_appConfig.Logging.Enabled) { AppLogEx.Open(PwDefs.ShortProductName); } AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); AppPolicy.ApplyToConfig(); if (m_appConfig.Security.ProtectProcessWithDacl) { KeePassLib.Native.NativeMethods.ProtectProcessWithDacl(); } m_appConfig.Apply(AceApplyFlags.All); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); // InitEnvWorkarounds(); LoadTranslation(); CustomResourceManager.Override(typeof(KeePass.Properties.Resources)); #if KP_DEVSNAP if (!m_bAsmResReg) { AppDomain.CurrentDomain.AssemblyResolve += Program.AssemblyResolve; m_bAsmResReg = true; } else { Debug.Assert(false); } #endif return(true); }