Ejemplo n.º 1
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            m_bFormLoading = true;
            GlobalWindowManager.CustomizeControl(this);
            GlobalWindowManager.CustomizeControl(m_ctxTray);

            m_strNeverExpiresText = KPRes.NeverExpires;

            this.Text = PwDefs.ProductName;
            this.Icon = Properties.Resources.KeePass;
            m_imgFileSaveEnabled = Properties.Resources.B16x16_FileSave;
            m_imgFileSaveDisabled = Properties.Resources.B16x16_FileSave_Disabled;
            // m_imgFileSaveAllEnabled = Properties.Resources.B16x16_File_SaveAll;
            // m_imgFileSaveAllDisabled = Properties.Resources.B16x16_File_SaveAll_Disabled;
            m_ilCurrentIcons = m_ilClientIcons;

            m_ctxEntryOpenUrl.Text = KPRes.OpenCmd;

            m_ntfTray = new NotifyIconEx(this.components);
            m_ntfTray.ContextMenuStrip = m_ctxTray;
            m_ntfTray.Visible = true;
            m_ntfTray.SetHandlers(OnSystemTrayClick, OnSystemTrayDoubleClick,
                OnSystemTrayMouseDown);

            m_ctxTrayTray.Font = FontUtil.CreateFont(m_ctxTrayTray.Font, FontStyle.Bold);

            m_nLockTimerMax = (int)Program.Config.Security.WorkspaceLocking.LockAfterTime;
            m_nClipClearMax = Program.Config.Security.ClipboardClearAfterSeconds;

            NativeLib.AllowNative = Program.Config.Native.NativeKeyTransformations;

            m_ctxEntryPreviewContextMenu.Attach(m_richEntryView, this);

            m_dynCustomStrings = new DynamicMenu(m_ctxEntryCopyCustomString.DropDownItems);
            m_dynCustomStrings.MenuClick += this.OnCopyCustomString;

            m_dynCustomBinaries = new DynamicMenu(m_ctxEntryAttachments.DropDownItems);
            m_dynCustomBinaries.MenuClick += this.OnEntryBinaryView;

            m_dynShowEntriesByTagsEditMenu = new DynamicMenu(m_menuEditShowByTag.DropDownItems);
            m_dynShowEntriesByTagsEditMenu.MenuClick += this.OnShowEntriesByTag;

            m_dynShowEntriesByTagsToolBar = new DynamicMenu(m_tbEntryViewsDropDown.DropDownItems);
            m_dynShowEntriesByTagsToolBar.MenuClick += this.OnShowEntriesByTag;

            m_dynAddTag = new DynamicMenu(m_ctxEntrySelectedAddTag.DropDownItems);
            m_dynAddTag.MenuClick += this.OnAddEntryTag;

            m_dynRemoveTag = new DynamicMenu(m_ctxEntrySelectedRemoveTag.DropDownItems);
            m_dynRemoveTag.MenuClick += this.OnRemoveEntryTag;

            m_dynOpenUrl = new OpenWithMenu(m_ctxEntryUrl);

            EntryTemplates.Init(m_tbAddEntry);

            m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
            InsertToolStripItem(m_menuEdit, m_ctxEntrySelectAll, new EventHandler(OnEntrySelectAll), true);
            m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
            InsertToolStripItem(m_menuEdit, m_ctxEntryDelete, new EventHandler(OnEntryDelete), true);
            InsertToolStripItem(m_menuEdit, m_ctxEntryDuplicate, new EventHandler(OnEntryDuplicate), true);
            InsertToolStripItem(m_menuEdit, m_ctxEntryEdit, new EventHandler(OnEntryEdit), true);
            InsertToolStripItem(m_menuEdit, m_ctxEntryAdd, new EventHandler(OnEntryAdd), true);
            m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
            InsertToolStripItem(m_menuEdit, m_ctxGroupDelete, new EventHandler(OnGroupsDelete), true);
            InsertToolStripItem(m_menuEdit, m_ctxGroupEdit, new EventHandler(OnGroupsEdit), true);
            InsertToolStripItem(m_menuEdit, m_ctxGroupAdd, new EventHandler(OnGroupsAdd), true);

            UIUtil.ConfigureTbButton(m_tbNewDatabase, KPRes.ToolBarNew, null);
            UIUtil.ConfigureTbButton(m_tbOpenDatabase, KPRes.ToolBarOpen, null);
            UIUtil.ConfigureTbButton(m_tbSaveDatabase, KPRes.Save, null);
            UIUtil.ConfigureTbButton(m_tbSaveAll, KPRes.ToolBarSaveAll, null);
            UIUtil.ConfigureTbButton(m_tbAddEntry, KPRes.AddEntry, null);
            UIUtil.ConfigureTbButton(m_tbAddEntryDefault, KPRes.AddEntryBtn, null);
            UIUtil.ConfigureTbButton(m_tbCopyUserName, KPRes.CopyUserFull, null);
            UIUtil.ConfigureTbButton(m_tbCopyPassword, KPRes.CopyPasswordFull, null);
            UIUtil.ConfigureTbButton(m_tbFind, KPRes.Find + "...", null);
            UIUtil.ConfigureTbButton(m_tbEntryViewsDropDown, null, KPRes.ShowEntries);
            UIUtil.ConfigureTbButton(m_tbViewsShowAll, KPRes.ShowAllEntries, null);
            UIUtil.ConfigureTbButton(m_tbViewsShowExpired, KPRes.ShowExpiredEntries, null);
            UIUtil.ConfigureTbButton(m_tbLockWorkspace, KPRes.LockMenuLock, null);
            UIUtil.ConfigureTbButton(m_tbQuickFind, null, KPRes.SearchQuickPrompt +
                " (" + KPRes.KeyboardKeyCtrl + "+E)");
            UIUtil.ConfigureTbButton(m_tbCloseTab, StrUtil.RemoveAccelerator(
                KPRes.CloseButton), null);

            UIUtil.EnableAutoCompletion(m_tbQuickFind, false);

            bool bVisible = Program.Config.MainWindow.ToolBar.Show;
            m_toolMain.Visible = bVisible;
            m_menuViewShowToolBar.Checked = bVisible;

            // Make a copy of the maximized setting (the configuration item might
            // get changed when the window's position/size is restored)
            bool bMaximizedSetting = Program.Config.MainWindow.Maximized;

            int wndX = Program.Config.MainWindow.X;
            int wndY = Program.Config.MainWindow.Y;
            int sizeX = Program.Config.MainWindow.Width;
            int sizeY = Program.Config.MainWindow.Height;
            bool bWndValid = ((wndX != -32000) && (wndY != -32000) &&
                (wndX != -64000) && (wndY != -64000));

            if((sizeX != AppDefs.InvalidWindowValue) &&
                (sizeY != AppDefs.InvalidWindowValue) && bWndValid)
                this.Size = new Size(sizeX, sizeY);

            Rectangle rectRestWindow = new Rectangle(wndX, wndY,
                this.Size.Width, this.Size.Height);
            bool bWndPartVisible = UIUtil.IsScreenAreaVisible(rectRestWindow);
            if((wndX != AppDefs.InvalidWindowValue) &&
                (wndY != AppDefs.InvalidWindowValue) && bWndValid && bWndPartVisible)
            {
                this.Location = new Point(wndX, wndY);
            }
            else
            {
                Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
                this.Location = new Point((rectScreen.Width - this.Size.Width) / 2,
                    (rectScreen.Height - this.Size.Height) / 2);
            }

            SetMainWindowLayout(Program.Config.MainWindow.Layout == AceMainWindowLayout.SideBySide);
            ShowEntryView(Program.Config.MainWindow.EntryView.Show);
            UpdateColumnsEx(false);

            AceMainWindow mw = Program.Config.MainWindow;

            m_menuViewTanSimpleList.Checked = m_bSimpleTanView =
                mw.TanView.UseSimpleView;
            m_menuViewTanIndices.Checked = m_bShowTanIndices =
                mw.TanView.ShowIndices;

            m_menuViewShowEntriesOfSubGroups.Checked =
                Program.Config.MainWindow.ShowEntriesOfSubGroups;

            m_pListSorter = Program.Config.MainWindow.ListSorting;
            if((m_pListSorter.Column >= 0) && (m_pListSorter.Order != SortOrder.None))
                m_lvEntries.ListViewItemSorter = m_pListSorter;
            else m_pListSorter = new ListSorter();

            m_lvsmMenu = new ListViewSortMenu(m_menuViewSortBy, m_lvEntries,
                new SortCommandHandler(this.SortPasswordList));

            m_menuViewAlwaysOnTop.Checked = mw.AlwaysOnTop;
            OnViewAlwaysOnTop(null, null);

            m_mruList.Initialize(this, m_menuFileRecent, m_menuFileSyncRecent);
            SerializeMruList(false);

            SetListFont(Program.Config.UI.StandardFont);

            m_ctxEntryColorLightRed.Image = UIUtil.CreateColorBitmap24(16, 16,
                AppDefs.NamedEntryColor.LightRed);
            m_ctxEntryColorLightGreen.Image = UIUtil.CreateColorBitmap24(16, 16,
                AppDefs.NamedEntryColor.LightGreen);
            m_ctxEntryColorLightBlue.Image = UIUtil.CreateColorBitmap24(16, 16,
                AppDefs.NamedEntryColor.LightBlue);
            m_ctxEntryColorLightYellow.Image = UIUtil.CreateColorBitmap24(16, 16,
                AppDefs.NamedEntryColor.LightYellow);

            // m_lvEntries.GridLines = mw.ShowGridLines;
            if(UIUtil.VistaStyleListsSupported)
            {
                // m_tvGroups.ItemHeight += 1;

                m_tvGroups.ShowRootLines = false;
                m_tvGroups.ShowLines = false;

                UIUtil.SetExplorerTheme(m_tvGroups.Handle);
                UIUtil.SetExplorerTheme(m_lvEntries.Handle);
            }

            m_clrAlternateItemBgColor = UIUtil.GetAlternateColor(m_lvEntries.BackColor);

            m_statusPartProgress.Visible = false;

            if(bMaximizedSetting)
            {
                if((this.WindowState == FormWindowState.Normal) && !IsTrayed())
                    UIUtil.SetWindowState(this, FormWindowState.Maximized);
            }

            try
            {
                float fSplitPos = mw.SplitterHorizontalFrac;
                if(fSplitPos == float.Epsilon) fSplitPos = 0.8333f;
                m_splitHorizontal.SplitterDistance = (int)Math.Round(fSplitPos *
                    (double)m_splitHorizontal.Height);

                fSplitPos = mw.SplitterVerticalFrac;
                if(fSplitPos == float.Epsilon) fSplitPos = 0.25f;
                m_splitVertical.SplitterDistance = (int)Math.Round(fSplitPos *
                    (double)m_splitVertical.Width);
            }
            catch(Exception) { Debug.Assert(false); }

            string strSearchTr = ((WinUtil.IsAtLeastWindowsVista ?
                string.Empty : " ") + KPRes.Search);
            UIUtil.SetCueBanner(m_tbQuickFind, strSearchTr);

            #if DEBUG
            Program.Config.CustomConfig.SetBool("TestItem", true);

            Program.KeyProviderPool.Add(new KeePassLib.Keys.SampleKeyProvider());
            #endif

            m_sessionLockNotifier.Install(this.OnSessionLock);
            IpcBroadcast.StartServer();

            int nInitColProvCount = Program.ColumnProviderPool.Count;

            m_pluginDefaultHost.Initialize(this, Program.CommandLineArgs,
                CipherPool.GlobalPool);
            m_pluginManager.Initialize(m_pluginDefaultHost);

            m_pluginManager.UnloadAllPlugins();
            if(AppPolicy.Current.Plugins)
                m_pluginManager.LoadAllPlugins(UrlUtil.GetFileDirectory(
                    WinUtil.GetExecutable(), false, true));

            // Delete old files *after* loading plugins (when timestamps
            // of loaded plugins have been updated already)
            if(Program.Config.Application.Start.PluginCacheDeleteOld)
                PlgxCache.DeleteOldFilesAsync();

            if(Program.ColumnProviderPool.Count != nInitColProvCount)
                UpdateColumnsEx(false);

            HotKeyManager.Initialize(this);

            Keys kAutoTypeKey = (Keys)Program.Config.Integration.HotKeyGlobalAutoType;
            HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.AutoType, kAutoTypeKey);
            Keys kAutoTypeSelKey = (Keys)Program.Config.Integration.HotKeySelectedAutoType;
            HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.AutoTypeSelected, kAutoTypeSelKey);
            Keys kShowWindowKey = (Keys)Program.Config.Integration.HotKeyShowWindow;
            HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.ShowWindow, kShowWindowKey);
            Keys kEntryMenuKey = (Keys)Program.Config.Integration.HotKeyEntryMenu;
            HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.EntryMenu, kEntryMenuKey);

            m_statusClipboard.Visible = false;
            UpdateClipboardStatus();

            UpdateTrayIcon();
            UpdateTagsMenu(m_dynShowEntriesByTagsEditMenu, false, false,
                false, false); // Ensure popup arrow
            UpdateTagsMenu(m_dynRemoveTag, false, false, false, false);
            UpdateUIState(false);
            ApplyUICustomizations();

            ThreadPool.QueueUserWorkItem(new WaitCallback(OnFormLoadParallelAsync));

            Program.TriggerSystem.RaiseEvent(EcasEventIDs.AppInitPost);

            if(Program.CommandLineArgs.FileName != null)
                OpenDatabase(IocFromCommandLine(), KeyUtil.KeyFromCommandLine(
                    Program.CommandLineArgs), false);
            else if(Program.Config.Application.Start.OpenLastFile)
            {
                IOConnectionInfo ioLastFile = Program.Config.Application.LastUsedFile;
                if(ioLastFile.Path.Length > 0)
                    OpenDatabase(ioLastFile, null, false);
            }

            if(Program.Config.Application.Start.CheckForUpdate)
                CheckForUpdate.StartAsync(PwDefs.VersionUrl, m_statusPartInfo);

            ResetDefaultFocus(null);

            MinimizeToTrayAtStartIfEnabled(true);

            m_bFormLoading = false;
            NotifyUserActivity(); // Initialize locking timeout
            Program.TriggerSystem.RaiseEvent(EcasEventIDs.AppLoadPost);
        }
Ejemplo n.º 2
0
		private void OnFormLoad(object sender, EventArgs e)
		{
			if(m_bFormLoadCalled && MonoWorkarounds.IsRequired(3574233558U)) return;
			m_bFormLoadCalled = true;

			m_bFormLoaded = false;
			GlobalWindowManager.CustomizeControl(this);
			GlobalWindowManager.CustomizeControl(m_ctxTray);

			m_strNeverExpiresText = KPRes.NeverExpires;

			this.Text = PwDefs.ShortProductName;
			this.Icon = Properties.Resources.KeePass;
			m_imgFileSaveEnabled = Properties.Resources.B16x16_FileSave;
			m_imgFileSaveDisabled = Properties.Resources.B16x16_FileSave_Disabled;
			// m_imgFileSaveAllEnabled = Properties.Resources.B16x16_File_SaveAll;
			// m_imgFileSaveAllDisabled = Properties.Resources.B16x16_File_SaveAll_Disabled;

			// m_ilCurrentIcons = m_ilClientIcons;
			UpdateImageLists(true);

			m_ctxEntryOpenUrl.Text = KPRes.OpenCmd;

			m_ntfTray = new NotifyIconEx(this.components);
			m_ntfTray.ContextMenuStrip = m_ctxTray;
			m_ntfTray.Visible = true;
			m_ntfTray.SetHandlers(this.OnSystemTrayClick, this.OnSystemTrayDoubleClick,
				this.OnSystemTrayMouseDown);

			m_ctxTrayTray.Font = FontUtil.CreateFont(m_ctxTrayTray.Font, FontStyle.Bold);

			m_nLockTimerMax = (int)Program.Config.Security.WorkspaceLocking.LockAfterTime;
			m_nClipClearMax = Program.Config.Security.ClipboardClearAfterSeconds;

			NativeLib.AllowNative = Program.Config.Native.NativeKeyTransformations;

			m_ctxEntryPreviewContextMenu.Attach(m_richEntryView, this);

			m_dynCustomStrings = new DynamicMenu(m_ctxEntryCopyString.DropDownItems);
			m_dynCustomStrings.MenuClick += this.OnCopyCustomString;

			m_dynCustomBinaries = new DynamicMenu(m_ctxEntryAttachments.DropDownItems);
			m_dynCustomBinaries.MenuClick += this.OnEntryBinaryOpen;

			m_dynShowEntriesByTagsEditMenu = new DynamicMenu(m_menuEditShowByTag.DropDownItems);
			m_dynShowEntriesByTagsEditMenu.MenuClick += this.OnShowEntriesByTag;

			m_dynShowEntriesByTagsToolBar = new DynamicMenu(m_tbEntryViewsDropDown.DropDownItems);
			m_dynShowEntriesByTagsToolBar.MenuClick += this.OnShowEntriesByTag;

			m_dynAddTag = new DynamicMenu(m_ctxEntrySelectedAddTag.DropDownItems);
			m_dynAddTag.MenuClick += this.OnAddEntryTag;

			m_dynRemoveTag = new DynamicMenu(m_ctxEntrySelectedRemoveTag.DropDownItems);
			m_dynRemoveTag.MenuClick += this.OnRemoveEntryTag;

			m_dynMoveToGroup = new DynamicMenu(m_ctxEntryMoveToGroup.DropDownItems);
			m_dynMoveToGroup.MenuClick += this.OnEntryMoveToGroup;

			m_dynAutoTypeAdv = new DynamicMenu(m_ctxEntryAutoTypeAdv.DropDownItems);
			m_dynAutoTypeAdv.MenuClick += this.OnEntryPerformAutoTypeAdv;

			string[] vAdvSeq = new string[] {
				@"{USERNAME}", @"{USERNAME}{ENTER}",
				@"{PASSWORD}", @"{PASSWORD}{ENTER}",
				@"{USERNAME}{TAB}{PASSWORD}",
				@"{USERNAME}{TAB}{PASSWORD}{ENTER}",
				@"{USERNAME}{TAB}{TAB}{PASSWORD}",
				@"{USERNAME}{TAB}{TAB}{PASSWORD}{ENTER}"
			};
			Bitmap bmpAutoType = Properties.Resources.B16x16_KTouch;
			foreach(string strAdvSeq in vAdvSeq)
			{
				m_dynAutoTypeAdv.AddItem(strAdvSeq, bmpAutoType);
			}

			m_dynOpenUrl = new OpenWithMenu(m_ctxEntryUrl);
			m_dynOpenUrlToolBar = new OpenWithMenu(m_tbOpenUrl);

			EntryTemplates.Init(m_tbAddEntry);

			m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
			InsertToolStripItem(m_menuEdit, m_ctxEntrySelectAll, new EventHandler(OnEntrySelectAll), true);
			m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
			InsertToolStripItem(m_menuEdit, m_ctxEntryDelete, new EventHandler(OnEntryDelete), true);
			InsertToolStripItem(m_menuEdit, m_ctxEntryDuplicate, new EventHandler(OnEntryDuplicate), true);
			InsertToolStripItem(m_menuEdit, m_ctxEntryEdit, new EventHandler(OnEntryEdit), true);
			ToolStripMenuItem tsmiAddEntry = InsertToolStripItem(m_menuEdit,
				m_ctxEntryAdd, new EventHandler(OnEntryAdd), true);
			m_menuEdit.DropDownItems.Insert(0, new ToolStripSeparator());
			InsertToolStripItem(m_menuEdit, m_ctxGroupDelete, new EventHandler(OnGroupsDelete), true);
			InsertToolStripItem(m_menuEdit, m_ctxGroupEdit, new EventHandler(OnGroupsEdit), true);
			InsertToolStripItem(m_menuEdit, m_ctxGroupAdd, new EventHandler(OnGroupsAdd), true);

			// Under .NET, we assign the shortcut keys directly (to avoid a
			// beep when pressing them); under Mono, this doesn't work, thus
			// we handle it in HandleMainWindowKeyMessage instead
			if(!MonoWorkarounds.IsRequired(2139))
				UIUtil.AssignShortcut(tsmiAddEntry, Keys.Control | Keys.I);

			UIUtil.ConfigureTbButton(m_tbNewDatabase, KPRes.ToolBarNew, null, m_menuFileNew);
			UIUtil.ConfigureTbButton(m_tbOpenDatabase, KPRes.ToolBarOpen, null, m_menuFileOpenLocal);
			UIUtil.ConfigureTbButton(m_tbSaveDatabase, KPRes.Save, null, m_menuFileSave);
			UIUtil.ConfigureTbButton(m_tbSaveAll, KPRes.ToolBarSaveAll, null, null);
			UIUtil.ConfigureTbButton(m_tbAddEntry, KPRes.AddEntry, null, null);
			UIUtil.ConfigureTbButton(m_tbCopyUserName, KPRes.CopyUserFull, null, m_ctxEntryCopyUserName);
			UIUtil.ConfigureTbButton(m_tbCopyPassword, KPRes.CopyPasswordFull, null, m_ctxEntryCopyPassword);
			UIUtil.ConfigureTbButton(m_tbOpenUrl, KPRes.OpenUrl, null, m_ctxEntryOpenUrl);
			UIUtil.ConfigureTbButton(m_tbCopyUrl, KPRes.CopyUrlToClipboard, null, m_ctxEntryCopyUrl);
			UIUtil.ConfigureTbButton(m_tbAutoType, KPRes.PerformAutoType, null, m_ctxEntryPerformAutoType);
			UIUtil.ConfigureTbButton(m_tbFind, KPRes.Find + "...", null, m_menuEditFind);
			UIUtil.ConfigureTbButton(m_tbEntryViewsDropDown, null, KPRes.ShowEntries, null);
			UIUtil.ConfigureTbButton(m_tbLockWorkspace, KPRes.LockMenuLock, null, m_menuFileLock);
			UIUtil.ConfigureTbButton(m_tbQuickFind, null, KPRes.SearchQuickPrompt +
				" (" + KPRes.KeyboardKeyCtrl + "+E)", null);
			UIUtil.ConfigureTbButton(m_tbCloseTab, StrUtil.RemoveAccelerator(
				KPRes.CloseButton), null, m_menuFileClose);

			CopyMenuItemText(m_tbAddEntryDefault, m_ctxEntryAdd, null);
			CopyMenuItemText(m_tbOpenUrlDefault, m_ctxEntryOpenUrl, KPRes.OpenUrl);
			CopyMenuItemText(m_tbViewsShowAll, m_menuEditShowAll, null);
			CopyMenuItemText(m_tbViewsShowExpired, m_menuEditShowExp, null);

			UIUtil.EnableAutoCompletion(m_tbQuickFind, false);

			bool bVisible = Program.Config.MainWindow.ToolBar.Show;
			m_toolMain.Visible = bVisible;
			UIUtil.SetChecked(m_menuViewShowToolBar, bVisible);

			// Make a copy of the maximized setting (the configuration item might
			// get changed when the window's position/size is restored)
			bool bMaximizedSetting = Program.Config.MainWindow.Maximized;

			int wndX = Program.Config.MainWindow.X;
			int wndY = Program.Config.MainWindow.Y;
			int sizeX = Program.Config.MainWindow.Width;
			int sizeY = Program.Config.MainWindow.Height;
			bool bWndValid = ((wndX != -32000) && (wndY != -32000) &&
				(wndX != -64000) && (wndY != -64000));

			if((sizeX != AppDefs.InvalidWindowValue) &&
				(sizeY != AppDefs.InvalidWindowValue) && bWndValid)
			{
				if(MonoWorkarounds.IsRequired(686017))
				{
					sizeX = Math.Max(250, sizeX);
					sizeY = Math.Max(250, sizeY);
				}

				this.Size = new Size(sizeX, sizeY);
			}
			if(MonoWorkarounds.IsRequired(686017))
				this.MinimumSize = new Size(250, 250);

			Rectangle rectRestWindow = new Rectangle(wndX, wndY,
				this.Size.Width, this.Size.Height);
			bool bWndPartVisible = UIUtil.IsScreenAreaVisible(rectRestWindow);
			if((wndX != AppDefs.InvalidWindowValue) &&
				(wndY != AppDefs.InvalidWindowValue) && bWndValid && bWndPartVisible)
			{
				this.Location = new Point(wndX, wndY);
			}
			else
			{
				Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
				this.Location = new Point((rectScreen.Width - this.Size.Width) / 2,
					(rectScreen.Height - this.Size.Height) / 2);
			}

			SetMainWindowLayout(Program.Config.MainWindow.Layout == AceMainWindowLayout.SideBySide);
			ShowEntryView(Program.Config.MainWindow.EntryView.Show);
			UpdateColumnsEx(false);

			AceMainWindow mw = Program.Config.MainWindow;

			m_bSimpleTanView = mw.TanView.UseSimpleView;
			UIUtil.SetChecked(m_menuViewTanSimpleList, m_bSimpleTanView);
			m_bShowTanIndices = mw.TanView.ShowIndices;
			UIUtil.SetChecked(m_menuViewTanIndices, m_bShowTanIndices);

			UIUtil.SetChecked(m_menuViewShowEntriesOfSubGroups,
				Program.Config.MainWindow.ShowEntriesOfSubGroups);

			m_pListSorter = Program.Config.MainWindow.ListSorting;
			if((m_pListSorter.Column >= 0) && (m_pListSorter.Order != SortOrder.None))
				m_lvEntries.ListViewItemSorter = m_pListSorter;
			else m_pListSorter = new ListSorter();

			m_lvsmMenu = new ListViewSortMenu(m_menuViewSortBy, m_lvEntries,
				new SortCommandHandler(this.SortPasswordList));
			m_lvgmMenu = new ListViewGroupingMenu(m_menuViewEntryListGrouping, this);

			UIUtil.SetChecked(m_menuViewAlwaysOnTop, mw.AlwaysOnTop);
			EnsureAlwaysOnTopOpt();

			m_mruList.Initialize(this, m_menuFileRecent, m_menuFileSyncRecent);
			m_mruList.MarkOpened = true;
			SerializeMruList(false);

			SetListFont(Program.Config.UI.StandardFont);

			m_ctxEntryColorLightRed.Image = UIUtil.CreateColorBitmap24(16, 16,
				AppDefs.NamedEntryColor.LightRed);
			m_ctxEntryColorLightGreen.Image = UIUtil.CreateColorBitmap24(16, 16,
				AppDefs.NamedEntryColor.LightGreen);
			m_ctxEntryColorLightBlue.Image = UIUtil.CreateColorBitmap24(16, 16,
				AppDefs.NamedEntryColor.LightBlue);
			m_ctxEntryColorLightYellow.Image = UIUtil.CreateColorBitmap24(16, 16,
				AppDefs.NamedEntryColor.LightYellow);

			// m_lvEntries.GridLines = mw.ShowGridLines;
			if(UIUtil.VistaStyleListsSupported)
			{
				// m_tvGroups.ItemHeight += 1;

				m_tvGroups.ShowRootLines = false;
				m_tvGroups.ShowLines = false;

				UIUtil.SetExplorerTheme(m_tvGroups.Handle);
				UIUtil.SetExplorerTheme(m_lvEntries.Handle);
			}

			// m_tvGroups.QueryToolTip = UIUtil.GetPwGroupToolTipTN;

			UpdateAlternatingBgColor();

			m_statusPartProgress.Visible = false;

			if(bMaximizedSetting)
			{
				if((this.WindowState == FormWindowState.Normal) && !IsTrayed())
				{
					// bool bVis = this.Visible;
					// if(bVis) this.Visible = false;

					UIUtil.SetWindowState(this, FormWindowState.Maximized);

					// if(bVis) this.Visible = true;
				}
			}

			try
			{
				double dSplitPos = mw.SplitterHorizontalFrac;
				if(dSplitPos == double.Epsilon) dSplitPos = 0.8333;
				if(MonoWorkarounds.IsRequired(686017))
					m_splitHorizontal.Panel1MinSize = 35;
				m_splitHorizontal.SplitterDistanceFrac = dSplitPos;

				dSplitPos = mw.SplitterVerticalFrac;
				if(dSplitPos == double.Epsilon) dSplitPos = 0.25;
				m_splitVertical.SplitterDistanceFrac = dSplitPos;
			}
			catch(Exception) { Debug.Assert(false); }

			string strSearchTr = ((WinUtil.IsAtLeastWindowsVista ?
				string.Empty : " ") + KPRes.Search);
			UIUtil.SetCueBanner(m_tbQuickFind, strSearchTr);

#if DEBUG
			Program.Config.CustomConfig.SetBool("TestItem1", true);
			Program.Config.CustomConfig.SetULong("TestItem2", 13);
			Program.Config.CustomConfig.SetString("TestItem3", "TestValue");

			Program.KeyProviderPool.Add(new KeePassLib.Keys.SampleKeyProvider());
#endif

			m_sessionLockNotifier.Install(this.OnSessionLock);
			IpcBroadcast.StartServer();

			int nInitColProvCount = Program.ColumnProviderPool.Count;

			m_pluginDefaultHost.Initialize(this, Program.CommandLineArgs,
				CipherPool.GlobalPool);
			m_pluginManager.Initialize(m_pluginDefaultHost);

			m_pluginManager.UnloadAllPlugins();
			if(AppPolicy.Current.Plugins)
			{
				string[] vExclNames = new string[] {
					AppDefs.FileNames.Program, AppDefs.FileNames.XmlSerializers,
					AppDefs.FileNames.NativeLib32, AppDefs.FileNames.NativeLib64,
					AppDefs.FileNames.ShInstUtil
				};

				string strPlgRoot = UrlUtil.GetFileDirectory(
					WinUtil.GetExecutable(), false, true);
				m_pluginManager.LoadAllPlugins(strPlgRoot, SearchOption.TopDirectoryOnly,
					vExclNames);

				if(!NativeLib.IsUnix())
				{
					string strPlgSub = UrlUtil.EnsureTerminatingSeparator(strPlgRoot,
						false) + AppDefs.PluginsDir;
					m_pluginManager.LoadAllPlugins(strPlgSub, SearchOption.AllDirectories,
						vExclNames);
				}
				else // Unix
				{
					try
					{
						DirectoryInfo diPlgRoot = new DirectoryInfo(strPlgRoot);
						foreach(DirectoryInfo diSub in diPlgRoot.GetDirectories())
						{
							if(diSub == null) { Debug.Assert(false); continue; }

							if(string.Equals(diSub.Name, AppDefs.PluginsDir,
								StrUtil.CaseIgnoreCmp))
								m_pluginManager.LoadAllPlugins(diSub.FullName,
									SearchOption.AllDirectories, vExclNames);
						}
					}
					catch(Exception) { Debug.Assert(false); }
				}
			}

			// Delete old files *after* loading plugins (when timestamps
			// of loaded plugins have been updated already)
			if(Program.Config.Application.Start.PluginCacheDeleteOld)
				PlgxCache.DeleteOldFilesAsync();

			if(Program.ColumnProviderPool.Count != nInitColProvCount)
				UpdateColumnsEx(false);

			HotKeyManager.Initialize(this);

			Keys kAutoTypeKey = (Keys)Program.Config.Integration.HotKeyGlobalAutoType;
			HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.AutoType, kAutoTypeKey);
			Keys kAutoTypeSelKey = (Keys)Program.Config.Integration.HotKeySelectedAutoType;
			HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.AutoTypeSelected, kAutoTypeSelKey);
			Keys kShowWindowKey = (Keys)Program.Config.Integration.HotKeyShowWindow;
			HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.ShowWindow, kShowWindowKey);
			Keys kEntryMenuKey = (Keys)Program.Config.Integration.HotKeyEntryMenu;
			HotKeyManager.RegisterHotKey(AppDefs.GlobalHotKeyId.EntryMenu, kEntryMenuKey);

			m_statusClipboard.Visible = false;
			UpdateClipboardStatus();

			ToolStripItem[] vSbItems = new ToolStripItem[] {
				m_statusPartSelected, m_statusPartProgress, m_statusClipboard };
			int[] vStdSbWidths = new int[] { 140, 150, 100 };
			DpiUtil.ScaleToolStripItems(vSbItems, vStdSbWidths);

			// Workaround for .NET ToolStrip height bug;
			// https://sourceforge.net/p/keepass/discussion/329220/thread/19e7c256/
			Debug.Assert((m_toolMain.Height == 25) || DpiUtil.ScalingRequired);
			m_toolMain.LockHeight(true);

			UpdateTrayIcon();
			UpdateTagsMenu(m_dynShowEntriesByTagsEditMenu, false, false,
				TagsMenuMode.EnsurePopupOnly);
			UpdateTagsMenu(m_dynRemoveTag, false, false, TagsMenuMode.EnsurePopupOnly);
			UpdateEntryMoveMenu(true);
			UpdateUIState(false);
			ApplyUICustomizations();
			MonoWorkarounds.ApplyTo(this);

			ThreadPool.QueueUserWorkItem(new WaitCallback(OnFormLoadParallelAsync));

			HotKeyManager.CheckCtrlAltA(this);

			Program.TriggerSystem.RaiseEvent(EcasEventIDs.AppInitPost);

			if(Program.CommandLineArgs.FileName != null)
				OpenDatabase(IocFromCommandLine(), KeyUtil.KeyFromCommandLine(
					Program.CommandLineArgs), false);
			else if(Program.Config.Application.Start.OpenLastFile)
			{
				IOConnectionInfo ioLastFile = Program.Config.Application.LastUsedFile;
				if(ioLastFile.Path.Length > 0)
					OpenDatabase(ioLastFile, null, false);
			}

			UpdateCheckEx.EnsureConfigured(this);
			if(Program.Config.Application.Start.CheckForUpdate)
				UpdateCheckEx.Run(false, null);
			// UpdateCheck.StartAsync(PwDefs.VersionUrl, m_statusPartInfo);

			ResetDefaultFocus(null);

			MinimizeToTrayAtStartIfEnabled(true);

			m_bFormLoaded = true;
			NotifyUserActivity(); // Initialize locking timeout

			if(this.FormLoadPost != null)
				this.FormLoadPost(this, EventArgs.Empty);
			Program.TriggerSystem.RaiseEvent(EcasEventIDs.AppLoadPost);
		}