OpenWrite() public static method

public static OpenWrite ( IOConnectionInfo ioc ) : Stream
ioc IOConnectionInfo
return Stream
コード例 #1
0
            // Throws on error
            public static LockFileInfo Create(IOConnectionInfo iocLockFile)
            {
                LockFileInfo lfi;
                Stream       s = null;

                try
                {
                    byte[] pbID    = CryptoRandom.Instance.GetRandomBytes(16);
                    string strTime = TimeUtil.SerializeUtc(DateTime.UtcNow);

                    lfi = new LockFileInfo(Convert.ToBase64String(pbID), strTime,
#if KeePassUAP
                                           EnvironmentExt.UserName, EnvironmentExt.MachineName,
                                           EnvironmentExt.UserDomainName);
#elif KeePassLibSD
                                           string.Empty, string.Empty, string.Empty);
#else
                                           Environment.UserName, Environment.MachineName,
                                           Environment.UserDomainName);
#endif

                    StringBuilder sb = new StringBuilder();
#if !KeePassLibSD
                    sb.AppendLine(LockFileHeader);
                    sb.AppendLine(lfi.ID);
                    sb.AppendLine(strTime);
                    sb.AppendLine(lfi.UserName);
                    sb.AppendLine(lfi.Machine);
                    sb.AppendLine(lfi.Domain);
#else
                    sb.Append(LockFileHeader + MessageService.NewLine);
                    sb.Append(lfi.ID + MessageService.NewLine);
                    sb.Append(strTime + MessageService.NewLine);
                    sb.Append(lfi.UserName + MessageService.NewLine);
                    sb.Append(lfi.Machine + MessageService.NewLine);
                    sb.Append(lfi.Domain + MessageService.NewLine);
#endif

                    byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());

                    s = IOConnection.OpenWrite(iocLockFile);
                    if (s == null)
                    {
                        throw new IOException(iocLockFile.GetDisplayName());
                    }
                    s.Write(pbFile, 0, pbFile.Length);
                }
                finally { if (s != null)
                          {
                              s.Close();
                          }
                }

                return(lfi);
            }
コード例 #2
0
ファイル: FileTransactionEx.cs プロジェクト: yesde/keepass
		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);
		}
コード例 #3
0
        public Stream OpenWrite()
        {
            if (m_iocBase == null)
            {
                Debug.Assert(false); throw new ObjectDisposedException(null);
            }

            if (!m_bTransacted)
            {
                m_bMadeUnhidden |= UrlUtil.UnhideFile(m_iocTemp.Path);
            }

            return(IOConnection.OpenWrite(m_iocTemp));
        }
コード例 #4
0
        public void Save(string strFile, PwGroup pgDataSource, Kdb4Format format,
                         IStatusLogger slLogger)
        {
            bool bMadeUnhidden = UrlUtil.UnhideFile(strFile);

            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);

            this.Save(IOConnection.OpenWrite(ioc), pgDataSource, format, slLogger);

            if (bMadeUnhidden)
            {
                UrlUtil.HideFile(strFile, true);                           // Hide again
            }
        }