complete merging of Keepass 2.35, fix auto-merge errors
This commit is contained in:
@@ -96,13 +96,6 @@ namespace KeePassLib.Cryptography
|
||||
m_hash = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_sBaseStream.Flush();
|
||||
}
|
||||
|
||||
#if KeePassRT
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2016 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,14 +19,12 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
using KeePassLib.Security;
|
||||
using KeePassLib.Utility;
|
||||
|
||||
namespace KeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
@@ -50,12 +48,8 @@ namespace KeePassLib.Cryptography.PasswordGenerator
|
||||
Debug.Assert(pwProfile != null);
|
||||
if (pwProfile == null) throw new ArgumentNullException("pwProfile");
|
||||
|
||||
CryptoRandomStream crs = CreateCryptoStream(pbUserEntropy);
|
||||
PwgError e = PwgError.Unknown;
|
||||
CryptoRandomStream crs = null;
|
||||
byte[] pbKey = null;
|
||||
try
|
||||
{
|
||||
crs = CreateRandomStream(pbUserEntropy, out pbKey);
|
||||
|
||||
if (pwProfile.GeneratorType == PasswordGeneratorType.CharSet)
|
||||
e = CharSetBasedGenerator.Generate(out psOut, pwProfile, crs);
|
||||
@@ -64,29 +58,26 @@ namespace KeePassLib.Cryptography.PasswordGenerator
|
||||
else if (pwProfile.GeneratorType == PasswordGeneratorType.Custom)
|
||||
e = GenerateCustom(out psOut, pwProfile, crs, pwAlgorithmPool);
|
||||
else { Debug.Assert(false); psOut = ProtectedString.Empty; }
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(crs != null) crs.Dispose();
|
||||
if(pbKey != null) MemUtil.ZeroByteArray(pbKey);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
private static CryptoRandomStream CreateRandomStream(byte[] pbAdditionalEntropy,
|
||||
out byte[] pbKey)
|
||||
private static CryptoRandomStream CreateCryptoStream(byte[] pbAdditionalEntropy)
|
||||
{
|
||||
pbKey = CryptoRandom.Instance.GetRandomBytes(256);
|
||||
byte[] pbKey = CryptoRandom.Instance.GetRandomBytes(128);
|
||||
|
||||
// Mix in additional entropy
|
||||
Debug.Assert(pbKey.Length >= 64);
|
||||
if ((pbAdditionalEntropy != null) && (pbAdditionalEntropy.Length > 0))
|
||||
{
|
||||
for(int nKeyPos = 0; nKeyPos < pbKey.Length; ++nKeyPos)
|
||||
pbKey[nKeyPos] ^= pbAdditionalEntropy[nKeyPos % pbAdditionalEntropy.Length];
|
||||
using (SHA512Managed h = new SHA512Managed())
|
||||
{
|
||||
byte[] pbHash = h.ComputeHash(pbAdditionalEntropy);
|
||||
MemUtil.XorArray(pbHash, 0, pbKey, 0, pbHash.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return new CryptoRandomStream(CrsAlgorithm.Salsa20, pbKey);
|
||||
return new CryptoRandomStream(CrsAlgorithm.ChaCha20, pbKey);
|
||||
}
|
||||
|
||||
internal static char GenerateCharacter(PwProfile pwProfile,
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Collections\ProtectedBinarySet.cs" />
|
||||
<Compile Include="Collections\VariantDictionary.cs" />
|
||||
<Compile Include="Cryptography\Cipher\ChaCha20Cipher.cs" />
|
||||
<Compile Include="Cryptography\Cipher\ChaCha20Engine.cs" />
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2016 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
Modified to be used with Mono for Android. Changes Copyright (C) 2013 Philipp Crocoll
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -63,22 +65,7 @@ namespace KeePassLib.Keys
|
||||
/// </summary>
|
||||
public KcpUserAccount()
|
||||
{
|
||||
// Test if ProtectedData is supported -- throws an exception
|
||||
// when running on an old system (Windows 98 / ME).
|
||||
byte[] pbDummyData = new byte[128];
|
||||
ProtectedData.Protect(pbDummyData, m_pbEntropy,
|
||||
DataProtectionScope.CurrentUser);
|
||||
|
||||
byte[] pbKey = LoadUserKey(false);
|
||||
if(pbKey == null) pbKey = CreateUserKey();
|
||||
if(pbKey == null) // Should never happen
|
||||
{
|
||||
Debug.Assert(false);
|
||||
throw new SecurityException(KLRes.UserAccountKeyError);
|
||||
}
|
||||
|
||||
m_pbKeyData = new ProtectedBinary(true, pbKey);
|
||||
MemUtil.ZeroByteArray(pbKey);
|
||||
throw new NotSupportedException("DataProtection not supported on MonoForAndroid!");
|
||||
}
|
||||
|
||||
// public void Clear()
|
||||
@@ -88,8 +75,8 @@ namespace KeePassLib.Keys
|
||||
|
||||
private static string GetUserKeyFilePath(bool bCreate)
|
||||
{
|
||||
#if KeePassUAP
|
||||
string strUserDir = EnvironmentExt.AppDataRoamingFolderPath;
|
||||
#if KeePassRT
|
||||
string strUserDir = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
|
||||
#else
|
||||
string strUserDir = Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData);
|
||||
@@ -102,25 +89,22 @@ namespace KeePassLib.Keys
|
||||
Directory.CreateDirectory(strUserDir);
|
||||
|
||||
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
||||
return (strUserDir + UserKeyFileName);
|
||||
return strUserDir + UserKeyFileName;
|
||||
}
|
||||
|
||||
private static byte[] LoadUserKey(bool bThrow)
|
||||
private static byte[] LoadUserKey(bool bShowWarning)
|
||||
{
|
||||
byte[] pbKey = null;
|
||||
|
||||
#if !KeePassLibSD
|
||||
try
|
||||
{
|
||||
string strFilePath = GetUserKeyFilePath(false);
|
||||
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
|
||||
|
||||
pbKey = ProtectedData.Unprotect(pbProtectedKey, m_pbEntropy,
|
||||
DataProtectionScope.CurrentUser);
|
||||
throw new NotSupportedException("DataProtection not supported on MonoForAndroid!");
|
||||
}
|
||||
catch(Exception)
|
||||
catch (Exception exLoad)
|
||||
{
|
||||
if(bThrow) throw;
|
||||
if (bShowWarning) MessageService.ShowWarning(exLoad);
|
||||
|
||||
pbKey = null;
|
||||
}
|
||||
#endif
|
||||
@@ -130,23 +114,17 @@ namespace KeePassLib.Keys
|
||||
|
||||
private static byte[] CreateUserKey()
|
||||
{
|
||||
#if KeePassLibSD
|
||||
return null;
|
||||
#else
|
||||
string strFilePath = GetUserKeyFilePath(true);
|
||||
byte[] pbKey = null;
|
||||
|
||||
byte[] pbRandomKey = CryptoRandom.Instance.GetRandomBytes(64);
|
||||
byte[] pbProtectedKey = ProtectedData.Protect(pbRandomKey,
|
||||
m_pbEntropy, DataProtectionScope.CurrentUser);
|
||||
|
||||
File.WriteAllBytes(strFilePath, pbProtectedKey);
|
||||
|
||||
byte[] pbKey = LoadUserKey(true);
|
||||
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));
|
||||
|
||||
MemUtil.ZeroByteArray(pbRandomKey);
|
||||
return pbKey;
|
||||
#if !KeePassLibSD
|
||||
try
|
||||
{
|
||||
throw new NotSupportedException("DataProtection not supported on MonoForAndroid!");
|
||||
}
|
||||
catch (Exception) { pbKey = null; }
|
||||
#endif
|
||||
|
||||
return pbKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace KeePassLib
|
||||
private PwUuid m_uuid = PwUuid.Zero;
|
||||
private PwGroup m_pParentGroup = null;
|
||||
private DateTime m_tParentGroupLastMod = PwDefs.DtDefaultNow;
|
||||
private string m_tParentGroupLastModLazy;
|
||||
|
||||
private ProtectedStringDictionary m_listStrings = new ProtectedStringDictionary();
|
||||
private ProtectedBinaryDictionary m_listBinaries = new ProtectedBinaryDictionary();
|
||||
@@ -59,12 +58,6 @@ namespace KeePassLib
|
||||
private DateTime m_tLastMod = PwDefs.DtDefaultNow;
|
||||
private DateTime m_tLastAccess = PwDefs.DtDefaultNow;
|
||||
private DateTime m_tExpire = PwDefs.DtDefaultNow;
|
||||
|
||||
private string m_tCreationLazy;
|
||||
private string m_tLastModLazy;
|
||||
private string m_tLastAccessLazy;
|
||||
private string m_tExpireLazy;
|
||||
|
||||
private bool m_bExpires = false;
|
||||
private ulong m_uUsageCount = 0;
|
||||
|
||||
@@ -103,14 +96,10 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime LocationChanged
|
||||
{
|
||||
get { return GetLazyTime(ref m_tParentGroupLastModLazy, ref m_tParentGroupLastMod); }
|
||||
set { m_tParentGroupLastMod = value; m_tParentGroupLastModLazy = null; }
|
||||
get { return m_tParentGroupLastMod; }
|
||||
set { m_tParentGroupLastMod = value; }
|
||||
}
|
||||
|
||||
public void SetLazyLocationChanged(string xmlDateTime)
|
||||
{
|
||||
m_tParentGroupLastModLazy = xmlDateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set all entry strings.
|
||||
@@ -211,27 +200,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime CreationTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tCreationLazy, ref m_tCreation); }
|
||||
set { m_tCreation = value; m_tCreationLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyCreationTime(string xmlDateTime)
|
||||
{
|
||||
m_tCreationLazy = xmlDateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date/time when this entry was last accessed (read).
|
||||
/// </summary>
|
||||
public DateTime LastAccessTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tLastAccessLazy, ref m_tLastAccess); }
|
||||
set { m_tLastAccess = value; m_tLastAccessLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyLastAccessTime(string xmlDateTime)
|
||||
{
|
||||
m_tLastAccessLazy = xmlDateTime;
|
||||
get { return m_tCreation; }
|
||||
set { m_tCreation = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,13 +209,17 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime LastModificationTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tLastModLazy, ref m_tLastMod); }
|
||||
set { m_tLastMod = value; m_tLastModLazy = null; }
|
||||
get { return m_tLastMod; }
|
||||
set { m_tLastMod = value; }
|
||||
}
|
||||
|
||||
public void SetLazyLastModificationTime(string xmlDateTime)
|
||||
/// <summary>
|
||||
/// The date/time when this entry was last accessed (read).
|
||||
/// </summary>
|
||||
public DateTime LastAccessTime
|
||||
{
|
||||
m_tLastModLazy = xmlDateTime;
|
||||
get { return m_tLastAccess; }
|
||||
set { m_tLastAccess = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -254,13 +228,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime ExpiryTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tExpireLazy, ref m_tExpire); }
|
||||
set { m_tExpire = value; m_tExpireLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyExpiryTime(string xmlDateTime)
|
||||
{
|
||||
m_tExpireLazy = xmlDateTime;
|
||||
get { return m_tExpire; }
|
||||
set { m_tExpire = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -400,7 +369,6 @@ namespace KeePassLib
|
||||
peNew.m_uuid = m_uuid; // PwUuid is immutable
|
||||
peNew.m_pParentGroup = m_pParentGroup;
|
||||
peNew.m_tParentGroupLastMod = m_tParentGroupLastMod;
|
||||
peNew.m_tParentGroupLastModLazy = m_tParentGroupLastModLazy;
|
||||
|
||||
peNew.m_listStrings = m_listStrings.CloneDeep();
|
||||
peNew.m_listBinaries = m_listBinaries.CloneDeep();
|
||||
@@ -420,11 +388,6 @@ namespace KeePassLib
|
||||
peNew.m_bExpires = m_bExpires;
|
||||
peNew.m_uUsageCount = m_uUsageCount;
|
||||
|
||||
peNew.m_tCreationLazy = m_tCreationLazy;
|
||||
peNew.m_tLastModLazy = m_tLastModLazy;
|
||||
peNew.m_tLastAccessLazy = m_tLastAccessLazy;
|
||||
peNew.m_tExpireLazy = m_tExpireLazy;
|
||||
|
||||
peNew.m_strOverrideUrl = m_strOverrideUrl;
|
||||
|
||||
peNew.m_vTags = new List<string>(m_vTags);
|
||||
@@ -440,7 +403,6 @@ namespace KeePassLib
|
||||
|
||||
peNew.m_uuid = m_uuid; // PwUuid is immutable
|
||||
peNew.m_tParentGroupLastMod = m_tParentGroupLastMod;
|
||||
peNew.m_tParentGroupLastModLazy = m_tParentGroupLastModLazy;
|
||||
// Do not assign m_pParentGroup
|
||||
|
||||
return peNew;
|
||||
@@ -493,7 +455,7 @@ namespace KeePassLib
|
||||
if ((pwOpt & PwCompareOptions.IgnoreParentGroup) == PwCompareOptions.None)
|
||||
{
|
||||
if (m_pParentGroup != pe.m_pParentGroup) return false;
|
||||
if(!bIgnoreLastMod && (LocationChanged != pe.LocationChanged))
|
||||
if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -537,10 +499,10 @@ namespace KeePassLib
|
||||
if (m_clrForeground != pe.m_clrForeground) return false;
|
||||
if (m_clrBackground != pe.m_clrBackground) return false;
|
||||
|
||||
if(CreationTime != pe.CreationTime) return false;
|
||||
if(!bIgnoreLastMod && (LastModificationTime != pe.LastModificationTime)) return false;
|
||||
if(!bIgnoreLastAccess && (LastAccessTime != pe.LastAccessTime)) return false;
|
||||
if(ExpiryTime != pe.ExpiryTime) return false;
|
||||
if (m_tCreation != pe.m_tCreation) return false;
|
||||
if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod)) return false;
|
||||
if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess)) return false;
|
||||
if (m_tExpire != pe.m_tExpire) return false;
|
||||
if (m_bExpires != pe.m_bExpires) return false;
|
||||
if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount)) return false;
|
||||
|
||||
@@ -572,14 +534,16 @@ namespace KeePassLib
|
||||
{
|
||||
if (peTemplate == null) { Debug.Assert(false); throw new ArgumentNullException("peTemplate"); }
|
||||
|
||||
if(bOnlyIfNewer && (TimeUtil.Compare(peTemplate.LastModificationTime,LastModificationTime,true) < 0)) return;
|
||||
if (bOnlyIfNewer && (TimeUtil.Compare(peTemplate.m_tLastMod,
|
||||
m_tLastMod, true) < 0))
|
||||
return;
|
||||
|
||||
// Template UUID should be the same as the current one
|
||||
Debug.Assert(m_uuid.Equals(peTemplate.m_uuid));
|
||||
m_uuid = peTemplate.m_uuid;
|
||||
|
||||
if (bAssignLocationChanged)
|
||||
m_tParentGroupLastMod = peTemplate.LocationChanged;
|
||||
m_tParentGroupLastMod = peTemplate.m_tParentGroupLastMod;
|
||||
|
||||
m_listStrings = peTemplate.m_listStrings.CloneDeep();
|
||||
m_listBinaries = peTemplate.m_listBinaries.CloneDeep();
|
||||
@@ -593,10 +557,10 @@ namespace KeePassLib
|
||||
m_clrForeground = peTemplate.m_clrForeground;
|
||||
m_clrBackground = peTemplate.m_clrBackground;
|
||||
|
||||
m_tCreation = peTemplate.CreationTime;
|
||||
m_tLastMod = peTemplate.LastModificationTime;
|
||||
m_tLastAccess = peTemplate.LastAccessTime;
|
||||
m_tExpire = peTemplate.ExpiryTime;
|
||||
m_tCreation = peTemplate.m_tCreation;
|
||||
m_tLastMod = peTemplate.m_tLastMod;
|
||||
m_tLastAccess = peTemplate.m_tLastAccess;
|
||||
m_tExpire = peTemplate.m_tExpire;
|
||||
m_bExpires = peTemplate.m_bExpires;
|
||||
m_uUsageCount = peTemplate.m_uUsageCount;
|
||||
|
||||
@@ -929,17 +893,6 @@ namespace KeePassLib
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime GetLazyTime(ref string lazyTime, ref DateTime dateTime)
|
||||
{
|
||||
if (lazyTime != null)
|
||||
{
|
||||
dateTime = TimeUtil.DeserializeUtcOrDefault(lazyTime, dateTime);
|
||||
lazyTime = null;
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
|
||||
public void SetCreatedNow()
|
||||
{
|
||||
DateTime dt = DateTime.UtcNow;
|
||||
|
||||
@@ -47,7 +47,6 @@ namespace KeePassLib
|
||||
private PwObjectList<PwEntry> m_listEntries = new PwObjectList<PwEntry>();
|
||||
private PwGroup m_pParentGroup = null;
|
||||
private DateTime m_tParentGroupLastMod = PwDefs.DtDefaultNow;
|
||||
private string m_tParentGroupLastModLazy;
|
||||
|
||||
private PwUuid m_uuid = PwUuid.Zero;
|
||||
private string m_strName = string.Empty;
|
||||
@@ -63,12 +62,6 @@ namespace KeePassLib
|
||||
private bool m_bExpires = false;
|
||||
private ulong m_uUsageCount = 0;
|
||||
|
||||
|
||||
private string m_tCreationLazy;
|
||||
private string m_tLastModLazy;
|
||||
private string m_tLastAccessLazy;
|
||||
private string m_tExpireLazy;
|
||||
|
||||
private bool m_bIsExpanded = true;
|
||||
private bool m_bVirtual = false;
|
||||
|
||||
@@ -160,12 +153,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime LocationChanged
|
||||
{
|
||||
get { return GetLazyTime(ref m_tParentGroupLastModLazy, ref m_tParentGroupLastMod); }
|
||||
set { m_tParentGroupLastMod = value; m_tParentGroupLastModLazy = null; }
|
||||
}
|
||||
public void SetLazyLocationChanged(string xmlDateTime)
|
||||
{
|
||||
m_tParentGroupLastModLazy = xmlDateTime;
|
||||
get { return m_tParentGroupLastMod; }
|
||||
set { m_tParentGroupLastMod = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,13 +172,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime CreationTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tCreationLazy, ref m_tCreation); }
|
||||
set { m_tCreation = value; m_tCreationLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyCreationTime(string xmlDateTime)
|
||||
{
|
||||
m_tCreationLazy = xmlDateTime;
|
||||
get { return m_tCreation; }
|
||||
set { m_tCreation = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -197,13 +181,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime LastModificationTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tLastModLazy, ref m_tLastMod); }
|
||||
set { m_tLastMod = value; m_tLastModLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyLastModificationTime(string xmlDateTime)
|
||||
{
|
||||
m_tLastModLazy = xmlDateTime;
|
||||
get { return m_tLastMod; }
|
||||
set { m_tLastMod = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,13 +190,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime LastAccessTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tLastAccessLazy, ref m_tLastAccess); }
|
||||
set { m_tLastAccess = value; m_tLastAccessLazy = null; }
|
||||
}
|
||||
|
||||
public void SetLazyLastAccessTime(string xmlDateTime)
|
||||
{
|
||||
m_tLastAccessLazy = xmlDateTime;
|
||||
get { return m_tLastAccess; }
|
||||
set { m_tLastAccess = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -225,12 +199,8 @@ namespace KeePassLib
|
||||
/// </summary>
|
||||
public DateTime ExpiryTime
|
||||
{
|
||||
get { return GetLazyTime(ref m_tExpireLazy, ref m_tExpire); }
|
||||
set { m_tExpire = value; m_tExpireLazy = null; }
|
||||
}
|
||||
public void SetLazyExpiryTime(string xmlDateTime)
|
||||
{
|
||||
m_tExpireLazy = xmlDateTime;
|
||||
get { return m_tExpire; }
|
||||
set { m_tExpire = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -406,7 +376,6 @@ namespace KeePassLib
|
||||
pg.m_listEntries = m_listEntries.CloneDeep();
|
||||
pg.m_pParentGroup = m_pParentGroup;
|
||||
pg.m_tParentGroupLastMod = m_tParentGroupLastMod;
|
||||
pg.m_tParentGroupLastModLazy = m_tParentGroupLastModLazy;
|
||||
|
||||
pg.m_strName = m_strName;
|
||||
pg.m_strNotes = m_strNotes;
|
||||
@@ -421,11 +390,6 @@ namespace KeePassLib
|
||||
pg.m_bExpires = m_bExpires;
|
||||
pg.m_uUsageCount = m_uUsageCount;
|
||||
|
||||
pg.m_tCreationLazy = m_tCreationLazy;
|
||||
pg.m_tLastModLazy = m_tLastModLazy;
|
||||
pg.m_tLastAccessLazy = m_tLastAccessLazy;
|
||||
pg.m_tExpireLazy = m_tExpireLazy;
|
||||
|
||||
pg.m_bIsExpanded = m_bIsExpanded;
|
||||
pg.m_bVirtual = m_bVirtual;
|
||||
|
||||
@@ -483,7 +447,7 @@ namespace KeePassLib
|
||||
if (!m_pwCustomIconID.Equals(pg.m_pwCustomIconID)) return false;
|
||||
|
||||
if (m_tCreation != pg.m_tCreation) return false;
|
||||
if (!bIgnoreLastMod && (LastModificationTime != pg.LastModificationTime)) return false;
|
||||
if(!bIgnoreLastMod && (m_tLastMod != pg.m_tLastMod)) return false;
|
||||
if (!bIgnoreLastAccess && (m_tLastAccess != pg.m_tLastAccess)) return false;
|
||||
if (m_tExpire != pg.m_tExpire) return false;
|
||||
if (m_bExpires != pg.m_bExpires) return false;
|
||||
@@ -543,7 +507,7 @@ namespace KeePassLib
|
||||
{
|
||||
Debug.Assert(pgTemplate != null); if(pgTemplate == null) throw new ArgumentNullException("pgTemplate");
|
||||
|
||||
if (bOnlyIfNewer && (TimeUtil.Compare(pgTemplate.LastModificationTime, LastModificationTime,
|
||||
if(bOnlyIfNewer && (TimeUtil.Compare(pgTemplate.m_tLastMod, m_tLastMod,
|
||||
true) < 0))
|
||||
return;
|
||||
|
||||
@@ -560,11 +524,10 @@ namespace KeePassLib
|
||||
m_pwIcon = pgTemplate.m_pwIcon;
|
||||
m_pwCustomIconID = pgTemplate.m_pwCustomIconID;
|
||||
|
||||
m_tCreation = pgTemplate.CreationTime;
|
||||
m_tLastMod = pgTemplate.LastModificationTime;
|
||||
m_tLastAccess = pgTemplate.LastAccessTime;
|
||||
m_tExpire = pgTemplate.ExpiryTime;
|
||||
|
||||
m_tCreation = pgTemplate.m_tCreation;
|
||||
m_tLastMod = pgTemplate.m_tLastMod;
|
||||
m_tLastAccess = pgTemplate.m_tLastAccess;
|
||||
m_tExpire = pgTemplate.m_tExpire;
|
||||
m_bExpires = pgTemplate.m_bExpires;
|
||||
m_uUsageCount = pgTemplate.m_uUsageCount;
|
||||
|
||||
@@ -1723,15 +1686,6 @@ namespace KeePassLib
|
||||
|
||||
return pg;
|
||||
}
|
||||
private DateTime GetLazyTime(ref string lazyTime, ref DateTime dateTime)
|
||||
{
|
||||
if (lazyTime != null)
|
||||
{
|
||||
dateTime = TimeUtil.DeserializeUtcOrDefault(lazyTime, m_tLastMod);
|
||||
lazyTime = null;
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PwGroupComparer : IComparer<PwGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2013 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
Modified to be used with Mono for Android. Changes Copyright (C) 2013 Philipp Crocoll
|
||||
|
||||
@@ -53,185 +53,6 @@ namespace KeePassLib.Serialization
|
||||
}
|
||||
#endif
|
||||
|
||||
internal abstract class WrapperStream : Stream
|
||||
{
|
||||
private readonly Stream m_s;
|
||||
protected Stream BaseStream
|
||||
{
|
||||
get { return m_s; }
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return m_s.CanRead; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return m_s.CanSeek; }
|
||||
}
|
||||
|
||||
public override bool CanTimeout
|
||||
{
|
||||
get { return m_s.CanTimeout; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_s.CanWrite; }
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { return m_s.Length; }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { return m_s.Position; }
|
||||
set { m_s.Position = value; }
|
||||
}
|
||||
|
||||
public override int ReadTimeout
|
||||
{
|
||||
get { return m_s.ReadTimeout; }
|
||||
set { m_s.ReadTimeout = value; }
|
||||
}
|
||||
|
||||
public override int WriteTimeout
|
||||
{
|
||||
get { return m_s.WriteTimeout; }
|
||||
set { m_s.WriteTimeout = value; }
|
||||
}
|
||||
|
||||
public WrapperStream(Stream sBase) : base()
|
||||
{
|
||||
if(sBase == null) throw new ArgumentNullException("sBase");
|
||||
|
||||
m_s = sBase;
|
||||
}
|
||||
|
||||
#if !KeePassUAP
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset,
|
||||
int count, AsyncCallback callback, object state)
|
||||
{
|
||||
return m_s.BeginRead(buffer, offset, count, callback, state);
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset,
|
||||
int count, AsyncCallback callback, object state)
|
||||
{
|
||||
return BeginWrite(buffer, offset, count, callback, state);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing) m_s.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#if !KeePassUAP
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
return m_s.EndRead(asyncResult);
|
||||
}
|
||||
|
||||
public override void EndWrite(IAsyncResult asyncResult)
|
||||
{
|
||||
m_s.EndWrite(asyncResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_s.Flush();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
return m_s.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
return m_s.ReadByte();
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return m_s.Seek(offset, origin);
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
m_s.SetLength(value);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
m_s.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_s.WriteByte(value);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class IocStream : WrapperStream
|
||||
{
|
||||
private readonly bool m_bWrite; // Initially opened for writing
|
||||
private bool m_bDisposed = false;
|
||||
|
||||
public IocStream(Stream sBase) : base(sBase)
|
||||
{
|
||||
m_bWrite = sBase.CanWrite;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if(disposing && MonoWorkarounds.IsRequired(10163) && m_bWrite &&
|
||||
!m_bDisposed)
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream s = this.BaseStream;
|
||||
Type t = s.GetType();
|
||||
if(t.Name == "WebConnectionStream")
|
||||
{
|
||||
PropertyInfo pi = t.GetProperty("Request",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if(pi != null)
|
||||
{
|
||||
WebRequest wr = (pi.GetValue(s, null) as WebRequest);
|
||||
if(wr != null)
|
||||
IOConnection.DisposeResponse(wr.GetResponse(), false);
|
||||
else { Debug.Assert(false); }
|
||||
}
|
||||
else { Debug.Assert(false); }
|
||||
}
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
m_bDisposed = true;
|
||||
}
|
||||
|
||||
public static Stream WrapIfRequired(Stream s)
|
||||
{
|
||||
if(s == null) { Debug.Assert(false); return null; }
|
||||
|
||||
if(MonoWorkarounds.IsRequired(10163) && s.CanWrite)
|
||||
return new IocStream(s);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IOConnection
|
||||
{
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
|
||||
@@ -499,22 +499,21 @@ namespace KeePassLib.Serialization
|
||||
Debug.Assert(tl != null);
|
||||
|
||||
if(xr.Name == ElemCreationTime)
|
||||
tl.SetLazyCreationTime(ReadString(xr));
|
||||
tl.CreationTime = ReadTime(xr);
|
||||
else if(xr.Name == ElemLastModTime)
|
||||
tl.SetLazyLastModificationTime(ReadString(xr));
|
||||
tl.LastModificationTime = ReadTime(xr);
|
||||
else if(xr.Name == ElemLastAccessTime)
|
||||
tl.SetLazyLastAccessTime(ReadString(xr));
|
||||
tl.LastAccessTime = ReadTime(xr);
|
||||
else if(xr.Name == ElemExpiryTime)
|
||||
tl.SetLazyExpiryTime(ReadString(xr));
|
||||
tl.ExpiryTime = ReadTime(xr);
|
||||
else if(xr.Name == ElemExpires)
|
||||
tl.Expires = ReadBool(xr, false);
|
||||
else if(xr.Name == ElemUsageCount)
|
||||
tl.UsageCount = ReadULong(xr, 0);
|
||||
else if(xr.Name == ElemLocationChanged)
|
||||
tl.SetLazyLocationChanged(ReadString(xr));
|
||||
tl.LocationChanged = ReadTime(xr);
|
||||
else ReadUnknown(xr);
|
||||
break;
|
||||
|
||||
case KdbContext.EntryString:
|
||||
if(xr.Name == ElemKey)
|
||||
m_ctxStringName = ReadString(xr);
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace KeePassLib.Serialization
|
||||
|
||||
if (fmt == KdbxFormat.ProtocolBuffers)
|
||||
{
|
||||
KdbpFile.ReadDocument(m_pwDatabase, sXml, m_pbProtectedStreamKey, m_pbHashOfHeader);
|
||||
KdbpFile.ReadDocument(m_pwDatabase, sXml, m_pbInnerRandomStreamKey, m_pbHashOfHeader);
|
||||
|
||||
Kp2aLog.Log(String.Format("KdbpFile.ReadDocument: {0}ms", stopWatch.ElapsedMilliseconds));
|
||||
|
||||
@@ -577,8 +577,6 @@ namespace KeePassLib.Serialization
|
||||
else { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
return vEntries; */
|
||||
|
||||
|
||||
return vEntries; */
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace KeePassLib.Serialization
|
||||
|
||||
if (m_format == KdbxFormat.ProtocolBuffers)
|
||||
{
|
||||
KdbpFile.WriteDocument(m_pwDatabase, sXml, m_pbProtectedStreamKey, m_pbHashOfHeader);
|
||||
KdbpFile.WriteDocument(m_pwDatabase, sXml, m_pbInnerRandomStreamKey, m_pbHashOfHeader);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1017,14 +1017,9 @@ namespace KeePassLib.Serialization
|
||||
PwEntry[] vEntries)
|
||||
{
|
||||
if (msOutput == null) { Debug.Assert(false); return false; }
|
||||
/// <summary>
|
||||
// pdContext may be null
|
||||
if (vEntries == null) { Debug.Assert(false); return false; }
|
||||
/// Write entries to a stream.
|
||||
/// </summary>
|
||||
/// <param name="msOutput">Output stream to which the entries will be written.</param>
|
||||
/// <param name="vEntries">Entries to serialize.</param>
|
||||
/// <returns>Returns <c>true</c>, if the entries were written successfully
|
||||
/// to the stream.</returns>
|
||||
|
||||
/* KdbxFile f = new KdbxFile(pwDatabase);
|
||||
f.m_format = KdbxFormat.PlainXml;
|
||||
|
||||
@@ -1047,12 +1042,17 @@ namespace KeePassLib.Serialization
|
||||
|
||||
xtw.WriteEndElement();
|
||||
xtw.WriteEndDocument();
|
||||
|
||||
xtw.Flush();
|
||||
xtw.Close();
|
||||
return true; */
|
||||
|
||||
PwDatabase pd = new PwDatabase();
|
||||
pd.New(new IOConnectionInfo(), new CompositeKey());
|
||||
|
||||
PwGroup pg = pd.RootGroup;
|
||||
if (pg == null) { Debug.Assert(false); return false; }
|
||||
xtw.Flush();
|
||||
|
||||
foreach (PwEntry pe in vEntries)
|
||||
{
|
||||
PwUuid pu = pe.CustomIconUuid;
|
||||
@@ -1067,11 +1067,11 @@ namespace KeePassLib.Serialization
|
||||
}
|
||||
else { Debug.Assert(pdContext == null); }
|
||||
}
|
||||
xtw.Close();
|
||||
|
||||
PwEntry peCopy = pe.CloneDeep();
|
||||
pg.AddEntry(peCopy, true);
|
||||
}
|
||||
return true; */
|
||||
|
||||
KdbxFile f = new KdbxFile(pd);
|
||||
f.Save(msOutput, null, KdbxFormat.PlainXml, null);
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2013 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
Modified to be used with Mono for Android. Changes Copyright (C) 2013 Philipp Crocoll
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -20,29 +22,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Windows.Forms;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
|
||||
using KeePassLib.Resources;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace KeePassLib.Utility
|
||||
{
|
||||
public enum MessageBoxButtons
|
||||
{
|
||||
OK, OKCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel
|
||||
}
|
||||
public enum MessageBoxIcon
|
||||
{
|
||||
Information, Warning, Error, Question
|
||||
}
|
||||
public enum MessageBoxDefaultButton
|
||||
{
|
||||
Button1, Button2, Button3
|
||||
}
|
||||
|
||||
public enum DialogResult
|
||||
{
|
||||
Yes, No, Cancel, Retry, Abort
|
||||
}
|
||||
|
||||
|
||||
public sealed class MessageServiceEventArgs : EventArgs
|
||||
{
|
||||
private string m_strTitle = string.Empty;
|
||||
private string m_strText = string.Empty;
|
||||
private MessageBoxButtons m_msgButtons = MessageBoxButtons.OK;
|
||||
private MessageBoxIcon m_msgIcon = MessageBoxIcon.None;
|
||||
//private MessageBoxButtons m_msgButtons = MessageBoxButtons.OK;
|
||||
//private MessageBoxIcon m_msgIcon = MessageBoxIcon.None;
|
||||
|
||||
public string Title { get { return m_strTitle; } }
|
||||
public string Text { get { return m_strText; } }
|
||||
public MessageBoxButtons Buttons { get { return m_msgButtons; } }
|
||||
public MessageBoxIcon Icon { get { return m_msgIcon; } }
|
||||
//public MessageBoxButtons Buttons { get { return m_msgButtons; } }
|
||||
//public MessageBoxIcon Icon { get { return m_msgIcon; } }
|
||||
|
||||
public MessageServiceEventArgs() { }
|
||||
|
||||
@@ -51,8 +69,7 @@ namespace KeePassLib.Utility
|
||||
{
|
||||
m_strTitle = (strTitle ?? string.Empty);
|
||||
m_strText = (strText ?? string.Empty);
|
||||
m_msgButtons = msgButtons;
|
||||
m_msgIcon = msgIcon;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,14 +82,12 @@ namespace KeePassLib.Utility
|
||||
private const MessageBoxIcon m_mbiWarning = MessageBoxIcon.Warning;
|
||||
private const MessageBoxIcon m_mbiFatal = MessageBoxIcon.Error;
|
||||
|
||||
private const MessageBoxOptions m_mboRtl = (MessageBoxOptions.RtlReading |
|
||||
MessageBoxOptions.RightAlign);
|
||||
#else
|
||||
private const MessageBoxIcon m_mbiInfo = MessageBoxIcon.Asterisk;
|
||||
private const MessageBoxIcon m_mbiWarning = MessageBoxIcon.Exclamation;
|
||||
private const MessageBoxIcon m_mbiFatal = MessageBoxIcon.Hand;
|
||||
#endif
|
||||
private const MessageBoxIcon m_mbiQuestion = MessageBoxIcon.Question;
|
||||
//private const MessageBoxIcon m_mbiQuestion = MessageBoxIcon.Question;
|
||||
|
||||
public static string NewLine
|
||||
{
|
||||
@@ -97,9 +112,7 @@ namespace KeePassLib.Utility
|
||||
get { return m_uCurrentMessageCount; }
|
||||
}
|
||||
|
||||
#if !KeePassUAP
|
||||
public static event EventHandler<MessageServiceEventArgs> MessageShowing;
|
||||
#endif
|
||||
|
||||
private static string ObjectsToMessage(object[] vLines)
|
||||
{
|
||||
@@ -123,7 +136,7 @@ namespace KeePassLib.Utility
|
||||
|
||||
Exception exObj = (obj as Exception);
|
||||
string strObj = (obj as string);
|
||||
#if !KeePassLibSD
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
StringCollection scObj = (obj as StringCollection);
|
||||
#endif
|
||||
|
||||
@@ -134,7 +147,7 @@ namespace KeePassLib.Utility
|
||||
else if ((exObj.Message != null) && (exObj.Message.Length > 0))
|
||||
strAppend = exObj.Message;
|
||||
}
|
||||
#if !KeePassLibSD
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
else if (scObj != null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -163,24 +176,30 @@ namespace KeePassLib.Utility
|
||||
return sbText.ToString();
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
internal static Form GetTopForm()
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
/*internal static Form GetTopForm()
|
||||
{
|
||||
FormCollection fc = Application.OpenForms;
|
||||
if((fc == null) || (fc.Count == 0)) return null;
|
||||
|
||||
return fc[fc.Count - 1];
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
#if !KeePassUAP
|
||||
internal static DialogResult SafeShowMessageBox(string strText, string strTitle,
|
||||
private static DialogResult SafeShowMessageBox(string strText, string strTitle,
|
||||
MessageBoxButtons mb, MessageBoxIcon mi, MessageBoxDefaultButton mdb)
|
||||
{
|
||||
#if KeePassLibSD
|
||||
#if (KeePassLibSD || KeePassRT)
|
||||
return MessageBox.Show(strText, strTitle, mb, mi, mdb);
|
||||
#else
|
||||
IWin32Window wnd = null;
|
||||
|
||||
if (mb == MessageBoxButtons.OK)
|
||||
{
|
||||
//Android.Widget.Toast toast = ..
|
||||
}
|
||||
//this might help: http://www.gregshackles.com/2011/04/using-background-threads-in-mono-for-android-applications/
|
||||
throw new NotImplementedException();
|
||||
/*IWin32Window wnd = null;
|
||||
try
|
||||
{
|
||||
Form f = GetTopForm();
|
||||
@@ -209,11 +228,12 @@ namespace KeePassLib.Utility
|
||||
if(StrUtil.RightToLeft)
|
||||
return MessageBox.Show(strText, strTitle, mb, mi, mdb, m_mboRtl);
|
||||
return MessageBox.Show(strText, strTitle, mb, mi, mdb);
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !KeePassLibSD
|
||||
internal delegate DialogResult SafeShowMessageBoxInternalDelegate(IWin32Window iParent,
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
/* internal delegate DialogResult SafeShowMessageBoxInternalDelegate(IWin32Window iParent,
|
||||
string strText, string strTitle, MessageBoxButtons mb, MessageBoxIcon mi,
|
||||
MessageBoxDefaultButton mdb);
|
||||
|
||||
@@ -224,7 +244,7 @@ namespace KeePassLib.Utility
|
||||
if(StrUtil.RightToLeft)
|
||||
return MessageBox.Show(iParent, strText, strTitle, mb, mi, mdb, m_mboRtl);
|
||||
return MessageBox.Show(iParent, strText, strTitle, mb, mi, mdb);
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
public static void ShowInfo(params object[] vLines)
|
||||
@@ -289,13 +309,12 @@ namespace KeePassLib.Utility
|
||||
|
||||
try
|
||||
{
|
||||
string strDetails = ObjectsToMessage(vLines, true);
|
||||
|
||||
#if KeePassLibSD
|
||||
Clipboard.SetDataObject(strDetails);
|
||||
#else
|
||||
#if !KeePassLibSD
|
||||
/* nicht benoetigt - hoffentlich :-)
|
||||
Clipboard.Clear();
|
||||
Clipboard.SetText(strDetails);
|
||||
Clipboard.SetText(ObjectsToMessage(vLines, true));*/
|
||||
#else
|
||||
Clipboard.SetDataObject(ObjectsToMessage(vLines, true));
|
||||
#endif
|
||||
}
|
||||
catch (Exception) { Debug.Assert(false); }
|
||||
@@ -320,10 +339,10 @@ namespace KeePassLib.Utility
|
||||
|
||||
if (MessageService.MessageShowing != null)
|
||||
MessageService.MessageShowing(null, new MessageServiceEventArgs(
|
||||
strTitleEx, strTextEx, mbb, m_mbiQuestion));
|
||||
strTitleEx, strTextEx, mbb, MessageBoxIcon.Question));
|
||||
|
||||
DialogResult dr = SafeShowMessageBox(strTextEx, strTitleEx, mbb,
|
||||
m_mbiQuestion, MessageBoxDefaultButton.Button1);
|
||||
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
|
||||
|
||||
--m_uCurrentMessageCount;
|
||||
return dr;
|
||||
@@ -339,10 +358,10 @@ namespace KeePassLib.Utility
|
||||
|
||||
if (MessageService.MessageShowing != null)
|
||||
MessageService.MessageShowing(null, new MessageServiceEventArgs(
|
||||
strTitleEx, strTextEx, MessageBoxButtons.YesNo, mbi));
|
||||
strTitleEx, strTextEx, MessageBoxButtons.YesNo, MessageBoxIcon.Question));
|
||||
|
||||
DialogResult dr = SafeShowMessageBox(strTextEx, strTitleEx,
|
||||
MessageBoxButtons.YesNo, mbi, bDefaultToYes ?
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question, bDefaultToYes ?
|
||||
MessageBoxDefaultButton.Button1 : MessageBoxDefaultButton.Button2);
|
||||
|
||||
--m_uCurrentMessageCount;
|
||||
@@ -351,17 +370,17 @@ namespace KeePassLib.Utility
|
||||
|
||||
public static bool AskYesNo(string strText, string strTitle, bool bDefaultToYes)
|
||||
{
|
||||
return AskYesNo(strText, strTitle, bDefaultToYes, m_mbiQuestion);
|
||||
return AskYesNo(strText, strTitle, bDefaultToYes, MessageBoxIcon.Question);
|
||||
}
|
||||
|
||||
public static bool AskYesNo(string strText, string strTitle)
|
||||
{
|
||||
return AskYesNo(strText, strTitle, true, m_mbiQuestion);
|
||||
return AskYesNo(strText, strTitle, true, MessageBoxIcon.Question);
|
||||
}
|
||||
|
||||
public static bool AskYesNo(string strText)
|
||||
{
|
||||
return AskYesNo(strText, null, true, m_mbiQuestion);
|
||||
return AskYesNo(strText, null, true, MessageBoxIcon.Question);
|
||||
}
|
||||
|
||||
public static void ShowLoadWarning(string strFilePath, Exception ex)
|
||||
@@ -372,7 +391,21 @@ namespace KeePassLib.Utility
|
||||
public static void ShowLoadWarning(string strFilePath, Exception ex,
|
||||
bool bFullException)
|
||||
{
|
||||
ShowWarning(GetLoadWarningMessage(strFilePath, ex, bFullException));
|
||||
string str = string.Empty;
|
||||
|
||||
if ((strFilePath != null) && (strFilePath.Length > 0))
|
||||
str += strFilePath + MessageService.NewParagraph;
|
||||
|
||||
str += KLRes.FileLoadFailed;
|
||||
|
||||
if ((ex != null) && (ex.Message != null) && (ex.Message.Length > 0))
|
||||
{
|
||||
str += MessageService.NewParagraph;
|
||||
if (!bFullException) str += ex.Message;
|
||||
else str += ObjectsToMessage(new object[] { ex }, true);
|
||||
}
|
||||
|
||||
ShowWarning(str);
|
||||
}
|
||||
|
||||
public static void ShowLoadWarning(IOConnectionInfo ioConnection, Exception ex)
|
||||
@@ -392,7 +425,18 @@ namespace KeePassLib.Utility
|
||||
return;
|
||||
}
|
||||
|
||||
string str = GetSaveWarningMessage(strFilePath, ex, bCorruptionWarning);
|
||||
string str = string.Empty;
|
||||
if ((strFilePath != null) && (strFilePath.Length > 0))
|
||||
str += strFilePath + MessageService.NewParagraph;
|
||||
|
||||
str += KLRes.FileSaveFailed;
|
||||
|
||||
if ((ex != null) && (ex.Message != null) && (ex.Message.Length > 0))
|
||||
str += MessageService.NewParagraph + ex.Message;
|
||||
|
||||
if (bCorruptionWarning)
|
||||
str += MessageService.NewParagraph + KLRes.FileSaveCorruptionWarning;
|
||||
|
||||
ShowWarning(str);
|
||||
}
|
||||
|
||||
@@ -403,45 +447,6 @@ namespace KeePassLib.Utility
|
||||
ShowSaveWarning(ioConnection.GetDisplayName(), ex, bCorruptionWarning);
|
||||
else ShowWarning(ex);
|
||||
}
|
||||
#endif // !KeePassUAP
|
||||
|
||||
internal static string GetLoadWarningMessage(string strFilePath,
|
||||
Exception ex, bool bFullException)
|
||||
{
|
||||
string str = string.Empty;
|
||||
|
||||
if(!string.IsNullOrEmpty(strFilePath))
|
||||
str += strFilePath + MessageService.NewParagraph;
|
||||
|
||||
str += KLRes.FileLoadFailed;
|
||||
|
||||
if((ex != null) && !string.IsNullOrEmpty(ex.Message))
|
||||
{
|
||||
str += MessageService.NewParagraph;
|
||||
if(!bFullException) str += ex.Message;
|
||||
else str += ObjectsToMessage(new object[] { ex }, true);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
internal static string GetSaveWarningMessage(string strFilePath,
|
||||
Exception ex, bool bCorruptionWarning)
|
||||
{
|
||||
string str = string.Empty;
|
||||
if(!string.IsNullOrEmpty(strFilePath))
|
||||
str += strFilePath + MessageService.NewParagraph;
|
||||
|
||||
str += KLRes.FileSaveFailed;
|
||||
|
||||
if((ex != null) && !string.IsNullOrEmpty(ex.Message))
|
||||
str += MessageService.NewParagraph + ex.Message;
|
||||
|
||||
if(bCorruptionWarning)
|
||||
str += MessageService.NewParagraph + KLRes.FileSaveCorruptionWarning;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public static void ExternalIncrementMessageCount()
|
||||
{
|
||||
|
||||
@@ -166,16 +166,7 @@ namespace KeePassLib.Utility
|
||||
|
||||
// m_fOwnWindow = fOwnWindow;
|
||||
|
||||
if(IsRequired(1530))
|
||||
{
|
||||
try
|
||||
{
|
||||
ThreadStart ts = new ThreadStart(MonoWorkarounds.FixClipThread);
|
||||
m_thFixClip = new Thread(ts);
|
||||
m_thFixClip.Start();
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static void Terminate()
|
||||
@@ -189,89 +180,6 @@ namespace KeePassLib.Utility
|
||||
}
|
||||
}
|
||||
|
||||
private static void FixClipThread()
|
||||
{
|
||||
try
|
||||
{
|
||||
#if !KeePassUAP
|
||||
const string strXSel = "xsel";
|
||||
const AppRunFlags rfW = AppRunFlags.WaitForExit;
|
||||
|
||||
string strLast = null;
|
||||
while(true)
|
||||
{
|
||||
string str = NativeLib.RunConsoleApp(strXSel,
|
||||
"--output --clipboard");
|
||||
if(str == null) return; // 'xsel' not installed
|
||||
|
||||
if(str != strLast)
|
||||
{
|
||||
if(NeedClipboardWorkaround())
|
||||
NativeLib.RunConsoleApp(strXSel,
|
||||
"--input --clipboard", str, rfW);
|
||||
|
||||
strLast = str;
|
||||
}
|
||||
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch(ThreadAbortException)
|
||||
{
|
||||
try { Thread.ResetAbort(); }
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
finally { m_thFixClip = null; }
|
||||
}
|
||||
|
||||
private static bool NeedClipboardWorkaround()
|
||||
{
|
||||
const bool bDef = true;
|
||||
|
||||
try
|
||||
{
|
||||
string strHandle = (NativeLib.RunConsoleApp("xdotool",
|
||||
"getactivewindow") ?? string.Empty).Trim();
|
||||
if(strHandle.Length == 0) return bDef;
|
||||
|
||||
// IntPtr h = new IntPtr(long.Parse(strHandle));
|
||||
long.Parse(strHandle); // Validate
|
||||
|
||||
// Detection of own windows based on Form.Handle
|
||||
// comparisons doesn't work reliably (Mono's handles
|
||||
// are usually off by 1)
|
||||
// Predicate<IntPtr> fOwnWindow = m_fOwnWindow;
|
||||
// if(fOwnWindow != null)
|
||||
// {
|
||||
// if(fOwnWindow(h)) return true;
|
||||
// }
|
||||
// else { Debug.Assert(false); }
|
||||
|
||||
string strWmClass = (NativeLib.RunConsoleApp("xprop",
|
||||
"-id " + strHandle + " WM_CLASS") ?? string.Empty);
|
||||
|
||||
if(strWmClass.IndexOf("\"" + PwDefs.ResClass + "\"",
|
||||
StrUtil.CaseIgnoreCmp) >= 0) return true;
|
||||
|
||||
// Workaround for Remmina
|
||||
if(strWmClass.IndexOf("\"Remmina\"",
|
||||
StrUtil.CaseIgnoreCmp) >= 0) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
catch(ThreadAbortException) { throw; }
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
|
||||
return bDef;
|
||||
}
|
||||
|
||||
#if !KeePassUAP
|
||||
public static void ApplyTo(Form f)
|
||||
{
|
||||
if(!MonoWorkarounds.IsRequired()) return;
|
||||
if(f == null) { Debug.Assert(false); return; }
|
||||
/// <summary>
|
||||
/// Ensure that the file ~/.recently-used is valid (in order to
|
||||
/// prevent Mono's FileDialog from crashing).
|
||||
|
||||
Reference in New Issue
Block a user