private void CommitWriteTransaction() { bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path); #if (!KeePass2PCL && !KeePassLibSD && !KeePassRT) FileSecurity bkSecurity = null; bool bEfsEncrypted = false; #endif if (IOConnection.FileExists(m_iocBase)) { #if (!KeePass2PCL && !KeePassLibSD && !KeePassRT) if (m_iocBase.IsLocalFile()) { try { FileAttributes faBase = File.GetAttributes(m_iocBase.Path); bEfsEncrypted = ((long)(faBase & FileAttributes.Encrypted) != 0); DateTime tCreation = File.GetCreationTime(m_iocBase.Path); bkSecurity = File.GetAccessControl(m_iocBase.Path); File.SetCreationTime(m_iocTemp.Path, tCreation); } catch (Exception) { Debug.Assert(false); } } #endif IOConnection.DeleteFile(m_iocBase); } IOConnection.RenameFile(m_iocTemp, m_iocBase); #if (!KeePass2PCL && !KeePassLibSD && !KeePassRT) if (m_iocBase.IsLocalFile()) { try { if (bEfsEncrypted) { try { File.Encrypt(m_iocBase.Path); } catch (Exception) { Debug.Assert(false); } } if (bkSecurity != null) { File.SetAccessControl(m_iocBase.Path, bkSecurity); } } catch (Exception) { Debug.Assert(false); } } #endif if (bMadeUnhidden) { UrlUtil.HideFile(m_iocBase.Path, true); // Hide again } }
public Stream OpenWrite() { if (!m_bTransacted) { m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path); } else // m_bTransacted { try { IOConnection.DeleteFile(m_iocTemp); } catch (Exception) { } } return(IOConnection.OpenWrite(m_iocTemp)); }
private void Dispose(bool bDisposing) { if (m_iocLockFile == null) { return; } bool bFileDeleted = false; for (int r = 0; r < 5; ++r) { // if(!OwnLockFile()) { bFileDeleted = true; break; } try { IOConnection.DeleteFile(m_iocLockFile); bFileDeleted = true; } catch (Exception) { Debug.Assert(false); } if (bFileDeleted) { break; } #if KeePass2PCL if (bDisposing) { Task.Delay(50).Wait(); } #else if (bDisposing) { Thread.Sleep(50); } #endif } if (bDisposing && !bFileDeleted) { IOConnection.DeleteFile(m_iocLockFile); // Possibly with exception } m_iocLockFile = null; }