private void Dispose(bool bDisposing) { if (object.ReferenceEquals(this, g_sdbPrimary)) { try { if (!NativeMethods.ShutdownBlockReasonDestroy(m_hWnd)) { Debug.Assert(false); } } catch (Exception) { Debug.Assert(false); } g_sdbPrimary = null; } }
public ShutdownBlocker(IntPtr hWnd, string strReason) { Debug.Assert(hWnd != IntPtr.Zero); m_hWnd = hWnd; if(g_sdbPrimary != null) return; // We're not the first if(!WinUtil.IsAtLeastWindowsVista) return; if(NativeLib.IsUnix()) return; string str = strReason; if(string.IsNullOrEmpty(str)) { Debug.Assert(false); str = "..."; } try { if(NativeMethods.ShutdownBlockReasonCreate(hWnd, str)) g_sdbPrimary = this; else { Debug.Assert(false); } } catch(Exception) { Debug.Assert(false); } }
public ShutdownBlocker(IntPtr hWnd, string strReason) { Debug.Assert(hWnd != IntPtr.Zero); m_hWnd = hWnd; if (g_sdbPrimary != null) { return; // We're not the first } if (!WinUtil.IsAtLeastWindowsVista) { return; } if (NativeLib.IsUnix()) { return; } string str = strReason; if (string.IsNullOrEmpty(str)) { Debug.Assert(false); str = "..."; } try { if (NativeMethods.ShutdownBlockReasonCreate(hWnd, str)) { g_sdbPrimary = this; } else { Debug.Assert(false); } } catch (Exception) { Debug.Assert(false); } }
// 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); } }
private void SaveDatabase(PwDatabase pdToSave, object sender) { PwDatabase pd = (pdToSave ?? m_docMgr.ActiveDatabase); if(!pd.IsOpen) return; if(!AppPolicy.Try(AppPolicyId.SaveFile)) return; if((pd.IOConnectionInfo == null) || (pd.IOConnectionInfo.Path.Length == 0)) { SaveDatabaseAs(pd, false, sender, false); return; } UIBlockInteraction(true); if(!PreSaveValidate(pd)) { 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); ShutdownBlocker sdb = new ShutdownBlocker(this.Handle, KPRes.SavingDatabase); 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; } 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, pd.IOConnectionInfo.Path); }
private void Dispose(bool bDisposing) { if(object.ReferenceEquals(this, g_sdbPrimary)) { try { if(!NativeMethods.ShutdownBlockReasonDestroy(m_hWnd)) { Debug.Assert(false); } } catch(Exception) { Debug.Assert(false); } g_sdbPrimary = null; } }