Exemple #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.Now);

#if (!KeePass2PCL && !KeePassLibSD && !KeePassRT)
                    lfi = new LockFileInfo(Convert.ToBase64String(pbID), strTime,
                                           Environment.UserName, Environment.MachineName,
                                           Environment.UserDomainName);
#else
                    lfi = new LockFileInfo(Convert.ToBase64String(pbID), strTime,
                                           string.Empty, string.Empty, string.Empty);
#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.Dispose();
                          }
                }

                return(lfi);
            }
Exemple #2
0
        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));
        }