Event arguments structure for file-closing events.
Inheritance: KeePass.Util.CancellableOperationEventArgs
示例#1
0
        private void MainWindowOnFileClosingPre(object sender, FileClosingEventArgs fileClosingEventArgs)
        {
            if (!fileClosingEventArgs.Database.IOConnectionInfo.IsLocalFile())
            {
                return;
            }

            this.RemoveMonitor(fileClosingEventArgs.Database.IOConnectionInfo.Path);
        }
        private void MainWindow_FileClosingPre(object sender, KeePass.Forms.FileClosingEventArgs e)
        {
            lock (lockObject)
            {
                if (((e.Flags & FileEventFlags.Exiting) == FileEventFlags.Exiting) && !exiting)
                {
                    exiting = true;
                    string xml = string.Empty;
                    try
                    {
                        var       ser     = new XmlSerializerEx(typeof(IOConnectionInfo[]));
                        var       builder = new StringBuilder();
                        XmlWriter writer  = XmlWriter.Create(builder);

                        var connections = new List <IOConnectionInfo>();
                        foreach (var document in pluginHost.MainWindow.DocumentManager.Documents)
                        {
                            if (document.LockedIoc != null && document.LockedIoc.Path.Length > 0)
                            {
                                connections.Add(document.LockedIoc);
                            }
                            else if (document.Database.IOConnectionInfo != null && document.Database.IOConnectionInfo.Path.Length > 0)
                            {
                                connections.Add(document.Database.IOConnectionInfo);
                            }
                        }
                        var connectionArray = connections.ToArray();
                        ser.Serialize(writer, connectionArray);
                        writer.Flush();
                        xml = builder.ToString();
                        pluginHost.CustomConfig.SetString(configKey, xml);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to save list of open password database files to config file:\n\n" + ex.ToString());
                    }
                }
            }
        }
示例#3
0
    private void OnFileClosing(object sender, FileClosingEventArgs e) {
        if(ShouldAutoSync(KeePassQiniuConfig.Default.SyncOnFileClosed))
            AutoSync();

        m_databaseModified = false;
        m_uploadToolItem.Enabled = false;
        m_downToolItem.Enabled = true;
    }
示例#4
0
		internal void CloseDocument(PwDocument dsToClose, bool bLocking,
			bool bExiting, bool bUpdateUI)
		{
			PwDocument ds = (dsToClose ?? m_docMgr.ActiveDocument);
			PwDatabase pd = ds.Database;
			bool bIsActive = (ds == m_docMgr.ActiveDocument);

			Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePre,
				EcasProperty.Database, pd);
			if(this.FileClosingPre != null)
			{
				FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
				this.FileClosingPre(null, fcea);
				if(fcea.Cancel) return;
			}

			if(pd.Modified) // Implies pd.IsOpen
			{
				bool bInvokeSave = false;

				// https://sourceforge.net/p/keepass/discussion/329220/thread/c3c823c6/
				bool bCanAutoSave = AppPolicy.Current.SaveFile;

				if(Program.Config.Application.FileClosing.AutoSave && bCanAutoSave)
					bInvokeSave = true;
				else
				{
					FileSaveOrigin fso = FileSaveOrigin.Closing;
					if(bLocking) fso = FileSaveOrigin.Locking;
					if(bExiting) fso = FileSaveOrigin.Exiting;

					DialogResult dr = FileDialogsEx.ShowFileSaveQuestion(
						pd.IOConnectionInfo.GetDisplayName(), fso);

					if(dr == DialogResult.Cancel) return;
					else if(dr == DialogResult.Yes) bInvokeSave = true;
					else if(dr == DialogResult.No) { } // Changes are lost
				}

				if(bInvokeSave)
				{
					SaveDatabase(pd, null);
					if(pd.Modified) return;
				}
			}

			Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePost,
				EcasProperty.Database, pd);
			if(this.FileClosingPost != null)
			{
				FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
				this.FileClosingPost(null, fcea);
				if(fcea.Cancel) return;
			}

			IOConnectionInfo ioClosing = pd.IOConnectionInfo.CloneDeep();

			pd.Close();
			if(!bLocking) m_docMgr.CloseDatabase(pd);

			if(bIsActive)
			{
				m_tbQuickFind.Items.Clear();
				m_tbQuickFind.Text = string.Empty;

				if(!bLocking)
				{
					m_docMgr.ActiveDatabase.UINeedsIconUpdate = true;
					ResetDefaultFocus(null);
				}
			}
			if(bUpdateUI)
				UpdateUI(true, null, true, null, true, null, false);

			// NativeMethods.ClearIconicBitmaps(this.Handle);

			if(this.FileClosed != null)
			{
				FileClosedEventArgs fcea = new FileClosedEventArgs(ioClosing);
				this.FileClosed(null, fcea);
			}
		}
示例#5
0
        private void CloseDocument(bool bLocking, bool bExiting)
        {
            PwDocument ds = m_docMgr.ActiveDocument;
            PwDatabase pd = ds.Database;

            Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePre,
                pd.IOConnectionInfo.Path);
            if(this.FileClosingPre != null)
            {
                FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
                this.FileClosingPre(null, fcea);
                if(fcea.Cancel) return;
            }

            if(pd.Modified) // Implies pd.IsOpen
            {
                bool bInvokeSave = false;

                if(Program.Config.Application.FileClosing.AutoSave)
                    bInvokeSave = true;
                else
                {
                    FileSaveOrigin fso = FileSaveOrigin.Closing;
                    if(bLocking) fso = FileSaveOrigin.Locking;
                    if(bExiting) fso = FileSaveOrigin.Exiting;

                    DialogResult dr = FileDialogsEx.ShowFileSaveQuestion(
                        pd.IOConnectionInfo.GetDisplayName(), fso, this.Handle);

                    if(dr == DialogResult.Cancel) return;
                    else if(dr == DialogResult.Yes) bInvokeSave = true;
                    else if(dr == DialogResult.No) { } // Changes are lost
                }

                if(bInvokeSave)
                {
                    OnFileSave(null, EventArgs.Empty);
                    if(pd.Modified) return;
                }
            }

            Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePost,
                pd.IOConnectionInfo.Path);
            if(this.FileClosingPost != null)
            {
                FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
                this.FileClosingPost(null, fcea);
                if(fcea.Cancel) return;
            }

            IOConnectionInfo ioClosing = pd.IOConnectionInfo.CloneDeep();

            pd.Close();
            if(!bLocking) m_docMgr.CloseDatabase(pd);

            m_tbQuickFind.Items.Clear();
            m_tbQuickFind.Text = string.Empty;

            if(!bLocking)
            {
                m_docMgr.ActiveDatabase.UINeedsIconUpdate = true;
                UpdateUI(true, null, true, null, true, null, false);
                ResetDefaultFocus(null);
            }

            // NativeMethods.ClearIconicBitmaps(this.Handle);

            if(this.FileClosed != null)
            {
                FileClosedEventArgs fcea = new FileClosedEventArgs(ioClosing);
                this.FileClosed(null, fcea);
            }
        }
示例#6
0
 private void MainForm_FileClosing(object aSender,
     FileClosingEventArgs aEventArgs)
 {
     try {
     removeKeyList.Clear();
     var allKeys = agent.GetAllKeys();
     foreach (var entry in aEventArgs.Database.RootGroup.GetEntries(true)) {
       try {
     var settings = entry.GetKeeAgentSettings();
     if (settings.AllowUseOfSshKey && settings.RemoveAtDatabaseClose) {
       var matchKey = entry.GetSshKey();
       if (matchKey == null) {
         continue;
       }
       var removeKey = allKeys.Get(matchKey.Version, matchKey.GetPublicKeyBlob());
       if (removeKey == null) {
         continue;
       }
       removeKeyList.Add(removeKey);
     }
       } catch (Exception ex) {
     // keep trying the rest of the keys
     Debug.Fail(ex.ToString());
       }
     }
       } catch (Exception ex) {
     // can't be crashing KeePass
     Debug.Fail(ex.ToString());
       }
 }
        /// <summary>
        /// Handler for when the database file is being closed by KeePass.  If
        /// we are setup for automatic backup on this event, we go ahead and do
        /// so.  We also disable any menu actions that require a database to be
        /// open and clear the modified flag.
        /// </summary>
        /// <param name="sender">Information about the sending object.</param>
        /// <param name="e">Event information.</param>
        private void OnFileClosing(object sender, FileClosingEventArgs e)
        {
            if (ShouldAutoBackup(Properties.Settings.Default.BackupOnFileClosed))
                AutoBackup();

            m_databaseModified = false;
            m_backupNowToolItem.Enabled = false;
        }