Event arguments structure for the file-saving event.
Наследование: KeePass.Util.CancellableOperationEventArgs
Пример #1
0
		// Public for plugins
		public void SaveDatabaseAs(PwDatabase pdToSave, IOConnectionInfo iocTo,
			bool bOnline, object sender, bool bCopy)
		{
			PwDatabase pd = (pdToSave ?? m_docMgr.ActiveDatabase);

			if(!pd.IsOpen) return;
			if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

			Guid eventGuid = Guid.NewGuid();
			if(this.FileSaving != null)
			{
				FileSavingEventArgs args = new FileSavingEventArgs(true, bCopy, pd, eventGuid);
				this.FileSaving(sender, args);
				if(args.Cancel) return;
			}

			DialogResult dr;
			IOConnectionInfo ioc = iocTo;

			if((ioc != null) && (ioc.Path.Length > 0))
			{
				dr = DialogResult.OK; // Caller (plugin) specified target file
			}
			else if(bOnline)
			{
				IOConnectionForm iocf = new IOConnectionForm();
				iocf.InitEx(true, pd.IOConnectionInfo.CloneDeep(), true, true);

				dr = iocf.ShowDialog();
				ioc = iocf.IOConnectionInfo;
				UIUtil.DestroyForm(iocf);
			}
			else
			{
				SaveFileDialogEx sfdDb = UIUtil.CreateSaveFileDialog(KPRes.SaveDatabase,
					UrlUtil.GetFileName(pd.IOConnectionInfo.Path),
					UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt,
					KPRes.KdbxFiles, true), 1, AppDefs.FileExtension.FileExt,
					AppDefs.FileDialogContext.Database);

				GlobalWindowManager.AddDialog(sfdDb.FileDialog);
				dr = sfdDb.ShowDialog();
				GlobalWindowManager.RemoveDialog(sfdDb.FileDialog);

				if(dr == DialogResult.OK)
					ioc = IOConnectionInfo.FromPath(sfdDb.FileName);
			}

			if(dr == DialogResult.OK)
			{
				EcasPropertyDictionary dProps = new EcasPropertyDictionary();
				dProps.Set(EcasProperty.IOConnectionInfo, ioc);
				dProps.Set(EcasProperty.Database, pd);
				Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavingDatabaseFile,
					dProps);

				UIBlockInteraction(true);

				ShowWarningsLogger swLogger = CreateShowWarningsLogger();
				swLogger.StartLogging(KPRes.SavingDatabase, true);
				ShutdownBlocker sdb = new ShutdownBlocker(this.Handle, KPRes.SavingDatabase);

				bool bSuccess = true;
				try
				{
					PreSavingEx(pd, ioc);
					pd.SaveAs(ioc, !bCopy, swLogger);
					PostSavingEx(!bCopy, pd, ioc, swLogger);
				}
				catch(Exception exSaveAs)
				{
					MessageService.ShowSaveWarning(ioc, exSaveAs, true);
					bSuccess = false;
				}

				sdb.Dispose();
				swLogger.EndLogging();

				// Immediately after the UIBlockInteraction call the form might
				// be closed and UpdateUIState might crash, if the order of the
				// two methods is swapped; so first update state, then unblock
				UpdateUIState(false);
				UIBlockInteraction(false); // Calls Application.DoEvents()

				if(this.FileSaved != null)
				{
					FileSavedEventArgs args = new FileSavedEventArgs(bSuccess, pd, eventGuid);
					this.FileSaved(sender, args);
				}
				if(bSuccess)
					Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavedDatabaseFile,
						dProps);
			}
		}
Пример #2
0
 private void OnFileSaving(object sender, FileSavingEventArgs e) {
     m_databaseModified = e.Database.Modified;
 }
Пример #3
0
        private void OnFileSave(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;

            if(!pd.IsOpen) return;
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            if((pd.IOConnectionInfo == null) || (pd.IOConnectionInfo.Path.Length == 0))
            {
                OnFileSaveAs(sender, e);
                return;
            }

            UIBlockInteraction(true);
            if(PreSaveValidate(pd) == false) { UIBlockInteraction(false); return; }

            Guid eventGuid = Guid.NewGuid();
            if(this.FileSaving != null)
            {
                FileSavingEventArgs args = new FileSavingEventArgs(false, false, pd, eventGuid);
                this.FileSaving(sender, args);
                if(args.Cancel) { UIBlockInteraction(false); return; }
            }
            Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavingDatabaseFile,
                pd.IOConnectionInfo.Path);

            ShowWarningsLogger swLogger = CreateShowWarningsLogger();
            swLogger.StartLogging(KPRes.SavingDatabase, true);

            bool bSuccess = true;
            try
            {
                PreSavingEx(pd);
                pd.Save(swLogger);
                PostSavingEx(true, pd, pd.IOConnectionInfo, swLogger);
            }
            catch(Exception exSave)
            {
                MessageService.ShowSaveWarning(pd.IOConnectionInfo, exSave, true);
                bSuccess = false;
            }

            swLogger.EndLogging();

            // Immediately after the UIBlockInteraction call the form might
            // be closed and UpdateUIState might crash, if the order of the
            // two methods is swapped; so first update state, then unblock
            UpdateUIState(false);
            UIBlockInteraction(false); // Calls Application.DoEvents()

            if(this.FileSaved != null)
            {
                FileSavedEventArgs args = new FileSavedEventArgs(bSuccess, pd, eventGuid);
                this.FileSaved(sender, args);
            }
            if(bSuccess)
                Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavedDatabaseFile,
                    pd.IOConnectionInfo.Path);
        }
Пример #4
0
 private void OnKPDBSaving(object sender, FileSavingEventArgs e)
 {
     SignalAllManagedRPCClients(KeePassRPC.DataExchangeModel.Signal.DATABASE_SAVING);
 }
Пример #5
0
        private void SaveDatabaseAs(bool bOnline, object sender, bool bCopy)
        {
            if(!m_docMgr.ActiveDatabase.IsOpen) return;
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            PwDatabase pd = m_docMgr.ActiveDatabase;

            Guid eventGuid = Guid.NewGuid();
            if(this.FileSaving != null)
            {
                FileSavingEventArgs args = new FileSavingEventArgs(true, bCopy, pd, eventGuid);
                this.FileSaving(sender, args);
                if(args.Cancel) return;
            }

            DialogResult dr;
            IOConnectionInfo ioc = new IOConnectionInfo();

            if(bOnline)
            {
                IOConnectionForm iocf = new IOConnectionForm();
                iocf.InitEx(true, pd.IOConnectionInfo.CloneDeep(), true, true);

                dr = iocf.ShowDialog();
                ioc = iocf.IOConnectionInfo;
            }
            else
            {
                SaveFileDialog sfdDb = UIUtil.CreateSaveFileDialog(KPRes.SaveDatabase,
                    UrlUtil.GetFileName(pd.IOConnectionInfo.Path),
                    UIUtil.CreateFileTypeFilter("kdbx", KPRes.KdbxFiles, true),
                    1, "kdbx", false);

                GlobalWindowManager.AddDialog(sfdDb);
                dr = sfdDb.ShowDialog();
                GlobalWindowManager.RemoveDialog(sfdDb);

                if(dr == DialogResult.OK)
                    ioc = IOConnectionInfo.FromPath(sfdDb.FileName);
            }

            if(dr == DialogResult.OK)
            {
                ShowWarningsLogger swLogger = CreateShowWarningsLogger();
                swLogger.StartLogging(KPRes.SavingDatabase, true);

                bool bSuccess = true;
                try
                {
                    pd.SaveAs(ioc, !bCopy, swLogger);

                    PostSavingEx(!bCopy, pd, ioc);
                }
                catch(Exception exSaveAs)
                {
                    MessageService.ShowSaveWarning(ioc, exSaveAs, true);
                    bSuccess = false;
                }

                swLogger.EndLogging();

                if(this.FileSaved != null)
                {
                    FileSavedEventArgs args = new FileSavedEventArgs(bSuccess, pd, eventGuid);
                    this.FileSaved(sender, args);
                }
            }

            UpdateUIState(false);
        }
Пример #6
0
		private void SaveDatabaseAs(bool bOnline, object sender, bool bCopy)
		{
			if(!m_docMgr.ActiveDatabase.IsOpen) return;
			if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

			PwDatabase pd = m_docMgr.ActiveDatabase;

			Guid eventGuid = Guid.NewGuid();
			if(this.FileSaving != null)
			{
				FileSavingEventArgs args = new FileSavingEventArgs(true, bCopy, pd, eventGuid);
				this.FileSaving(sender, args);
				if(args.Cancel) return;
			}

			DialogResult dr;
			IOConnectionInfo ioc = new IOConnectionInfo();

			if(bOnline)
			{
				IOConnectionForm iocf = new IOConnectionForm();
				iocf.InitEx(true, pd.IOConnectionInfo.CloneDeep(), true, true);

				dr = iocf.ShowDialog();
				ioc = iocf.IOConnectionInfo;
			}
			else
			{
				SaveFileDialog sfdDb = UIUtil.CreateSaveFileDialog(KPRes.SaveDatabase,
					UrlUtil.GetFileName(pd.IOConnectionInfo.Path),
					UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt,
					KPRes.KdbxFiles, true), 1, AppDefs.FileExtension.FileExt, false, true);

				GlobalWindowManager.AddDialog(sfdDb);
				dr = sfdDb.ShowDialog();
				GlobalWindowManager.RemoveDialog(sfdDb);

				if(dr == DialogResult.OK)
					ioc = IOConnectionInfo.FromPath(sfdDb.FileName);
			}

			if(dr == DialogResult.OK)
			{
				Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavingDatabaseFile,
					ioc.Path);

				UIBlockInteraction(true);

				ShowWarningsLogger swLogger = CreateShowWarningsLogger();
				swLogger.StartLogging(KPRes.SavingDatabase, true);

				bool bSuccess = true;
				try
				{
					PreSavingEx(pd);
					pd.SaveAs(ioc, !bCopy, swLogger);
					PostSavingEx(!bCopy, pd, ioc, swLogger);
				}
				catch(Exception exSaveAs)
				{
					MessageService.ShowSaveWarning(ioc, exSaveAs, true);
					bSuccess = false;
				}

				swLogger.EndLogging();

				// Immediately after the UIBlockInteraction call the form might
				// be closed and UpdateUIState might crash, if the order of the
				// two methods is swapped; so first update state, then unblock
				UpdateUIState(false);
				UIBlockInteraction(false); // Calls Application.DoEvents()

				if(this.FileSaved != null)
				{
					FileSavedEventArgs args = new FileSavedEventArgs(bSuccess, pd, eventGuid);
					this.FileSaved(sender, args);
				}
				if(bSuccess)
					Program.TriggerSystem.RaiseEvent(EcasEventIDs.SavedDatabaseFile,
						ioc.Path);
			}
		}
Пример #7
0
        private void OnFileSave(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;

            if(!pd.IsOpen) return;
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            if((pd.IOConnectionInfo == null) ||
                (pd.IOConnectionInfo.Path.Length == 0))
            {
                OnFileSaveAs(sender, e);
                return;
            }

            if(PreSaveValidate(pd) == false) return;

            Guid eventGuid = Guid.NewGuid();
            if(FileSaving != null)
            {
                FileSavingEventArgs args = new FileSavingEventArgs(false, false, pd, eventGuid);
                FileSaving(sender, args);
                if(args.Cancel) return;
            }

            ShowWarningsLogger swLogger = CreateShowWarningsLogger();
            swLogger.StartLogging(KPRes.SavingDatabase, true);

            bool bSuccess = true;
            try
            {
                pd.Save(swLogger);

                PostSavingEx(true, pd, pd.IOConnectionInfo);
            }
            catch(Exception exSave)
            {
                bSuccess = false;
                MessageService.ShowSaveWarning(pd.IOConnectionInfo, exSave, true);
            }

            swLogger.EndLogging();

            if(this.FileSaved != null)
            {
                FileSavedEventArgs args = new FileSavedEventArgs(bSuccess, pd, eventGuid);
                this.FileSaved(sender, args);
            }

            UpdateUIState(false);
        }