mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 15:40:20 -04:00
Downgrade to net standard 1.2
This commit is contained in:
@@ -180,7 +180,7 @@ namespace ModernKeePassLib.Utility
|
||||
internal static DialogResult SafeShowMessageBox(string strText, string strTitle,
|
||||
MessageBoxButtons mb, MessageBoxIcon mi, MessageBoxDefaultButton mdb)
|
||||
{
|
||||
#if (KeePassLibSD || KeePassRT)
|
||||
#if KeePassLibSD
|
||||
return MessageBox.Show(strText, strTitle, mb, mi, mdb);
|
||||
#else
|
||||
IWin32Window wnd = null;
|
||||
@@ -215,7 +215,7 @@ namespace ModernKeePassLib.Utility
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
#if !KeePassLibSD
|
||||
internal delegate DialogResult SafeShowMessageBoxInternalDelegate(IWin32Window iParent,
|
||||
string strText, string strTitle, MessageBoxButtons mb, MessageBoxIcon mi,
|
||||
MessageBoxDefaultButton mdb);
|
||||
|
@@ -340,7 +340,7 @@ namespace ModernKeePassLib.Utility
|
||||
if(!MonoWorkarounds.IsRequired()) return;
|
||||
if(f == null) { Debug.Assert(false); return; }
|
||||
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
#if !KeePassLibSD
|
||||
f.HandleCreated += MonoWorkarounds.OnFormHandleCreated;
|
||||
SetWmClass(f);
|
||||
|
||||
@@ -353,14 +353,14 @@ namespace ModernKeePassLib.Utility
|
||||
if(!MonoWorkarounds.IsRequired()) return;
|
||||
if(f == null) { Debug.Assert(false); return; }
|
||||
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
#if !KeePassLibSD
|
||||
f.HandleCreated -= MonoWorkarounds.OnFormHandleCreated;
|
||||
|
||||
ApplyToControlsRec(f.Controls, f, MonoWorkarounds.ReleaseControl);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
#if !KeePassLibSD
|
||||
private delegate void MwaControlHandler(Control c, Form fContext);
|
||||
|
||||
private static void ApplyToControlsRec(Control.ControlCollection cc,
|
||||
|
@@ -25,13 +25,14 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Drawing;
|
||||
#if ModernKeePassLib
|
||||
using ModernKeePassLib.Cryptography;
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Collections;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.PasswordGenerator;
|
||||
using ModernKeePassLib.Native;
|
||||
using ModernKeePassLib.Security;
|
||||
@@ -224,7 +225,7 @@ namespace ModernKeePassLib.Utility
|
||||
Encoding.Default,
|
||||
(uint)Encoding.Default.GetBytes("a").Length, null));
|
||||
#endif
|
||||
#if !ModernKeePassLib && !KeePassRT
|
||||
#if !ModernKeePassLib
|
||||
l.Add(new StrEncodingInfo(StrEncodingType.Ascii,
|
||||
"ASCII", Encoding.ASCII, 1, null));
|
||||
l.Add(new StrEncodingInfo(StrEncodingType.Utf7,
|
||||
@@ -238,7 +239,7 @@ namespace ModernKeePassLib.Utility
|
||||
l.Add(new StrEncodingInfo(StrEncodingType.Utf16BE,
|
||||
"Unicode (UTF-16 BE)", new UnicodeEncoding(true, false),
|
||||
2, new byte[] { 0xFE, 0xFF }));
|
||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||
#if !ModernKeePassLib && !KeePassLibSD
|
||||
l.Add(new StrEncodingInfo(StrEncodingType.Utf32LE,
|
||||
"Unicode (UTF-32 LE)", new UTF32Encoding(false, false),
|
||||
4, new byte[] { 0xFF, 0xFE, 0x0, 0x0 }));
|
||||
@@ -849,10 +850,8 @@ namespace ModernKeePassLib.Utility
|
||||
Debug.Assert(strY != null);
|
||||
if(strY == null) throw new ArgumentNullException("strY");
|
||||
|
||||
#if !ModernKeePassLib
|
||||
if(NativeMethods.SupportsStrCmpNaturally)
|
||||
return NativeMethods.StrCmpNaturally(strX, strY);
|
||||
#endif
|
||||
|
||||
int cX = strX.Length;
|
||||
int cY = strY.Length;
|
||||
@@ -1376,7 +1375,7 @@ namespace ModernKeePassLib.Utility
|
||||
byte[] pbEnc = CryptoUtil.ProtectData(pbPlain, m_pbOptEnt,
|
||||
DataProtectionScope.CurrentUser);
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
#if !ModernKeePassLib && !KeePassLibSD
|
||||
return Convert.ToBase64String(pbEnc, Base64FormattingOptions.None);
|
||||
#else
|
||||
return Convert.ToBase64String(pbEnc);
|
||||
@@ -1489,7 +1488,7 @@ namespace ModernKeePassLib.Utility
|
||||
Array.Reverse(pb);
|
||||
for(int i = 0; i < pb.Length; ++i) pb[i] = (byte)(pb[i] ^ 0x65);
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
#if !ModernKeePassLib && !KeePassLibSD
|
||||
return Convert.ToBase64String(pb, Base64FormattingOptions.None);
|
||||
#else
|
||||
return Convert.ToBase64String(pb);
|
||||
@@ -1649,7 +1648,7 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
if(strMediaType == null) strMediaType = "application/octet-stream";
|
||||
|
||||
#if (!ModernKeePassLib && !KeePassLibSD)
|
||||
#if !ModernKeePassLib && !KeePassLibSD
|
||||
return ("data:" + strMediaType + ";base64," + Convert.ToBase64String(
|
||||
pbData, Base64FormattingOptions.None));
|
||||
#else
|
||||
@@ -1680,7 +1679,7 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
#if ModernKeePassLib || KeePassRT
|
||||
#if ModernKeePassLib
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
#else
|
||||
Encoding enc = Encoding.ASCII;
|
||||
|
17
ModernKeePassLib/Utility/StreamExtensions.cs
Normal file
17
ModernKeePassLib/Utility/StreamExtensions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.IO;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace ModernKeePassLibPCL.Utility
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
||||
public static Stream AsStream(this IRandomAccessStream inputStream)
|
||||
{
|
||||
var reader = new DataReader(inputStream.GetInputStreamAt(0));
|
||||
var bytes = new byte[inputStream.Size];
|
||||
reader.LoadAsync((uint)inputStream.Size).GetResults();
|
||||
reader.ReadBytes(bytes);
|
||||
return new MemoryStream(bytes);
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,6 +25,10 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
#if ModernKeePassLib
|
||||
using Windows.Storage;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Native;
|
||||
|
||||
namespace ModernKeePassLib.Utility
|
||||
@@ -40,7 +44,11 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
public static char LocalDirSepChar
|
||||
{
|
||||
#if ModernKeePassLib
|
||||
get { return '\\'; }
|
||||
#else
|
||||
get { return Path.DirectorySeparatorChar; }
|
||||
#endif
|
||||
}
|
||||
|
||||
private static char[] g_vDirSepChars = null;
|
||||
@@ -58,7 +66,7 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
if(!l.Contains(UrlUtil.LocalDirSepChar))
|
||||
{
|
||||
//Debug.Assert(false);
|
||||
Debug.Assert(false);
|
||||
l.Add(UrlUtil.LocalDirSepChar);
|
||||
}
|
||||
|
||||
@@ -278,13 +286,14 @@ namespace ModernKeePassLib.Utility
|
||||
if(strUrl == null) { Debug.Assert(false); throw new ArgumentNullException("strUrl"); }
|
||||
if(strUrl.Length == 0) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
if(!strUrl.StartsWith(Uri.UriSchemeFile + ":", StrUtil.CaseIgnoreCmp))
|
||||
#if !ModernKeePassLib
|
||||
if(!strUrl.StartsWith(Uri.UriSchemeFile + ":", StrUtil.CaseIgnoreCmp))
|
||||
{
|
||||
Debug.Assert(false);
|
||||
return strUrl;
|
||||
}
|
||||
|
||||
try
|
||||
#endif
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(strUrl);
|
||||
string str = uri.LocalPath;
|
||||
@@ -298,7 +307,7 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
public static bool UnhideFile(string strFile)
|
||||
{
|
||||
#if (ModernKeePassLib || KeePassLibSD)
|
||||
#if ModernKeePassLib || KeePassLibSD
|
||||
return false;
|
||||
#else
|
||||
if(strFile == null) throw new ArgumentNullException("strFile");
|
||||
@@ -318,7 +327,7 @@ namespace ModernKeePassLib.Utility
|
||||
|
||||
public static bool HideFile(string strFile, bool bHide)
|
||||
{
|
||||
#if (ModernKeePassLib || KeePassLibSD)
|
||||
#if ModernKeePassLib || KeePassLibSD
|
||||
return false;
|
||||
#else
|
||||
if(strFile == null) throw new ArgumentNullException("strFile");
|
||||
@@ -484,7 +493,16 @@ namespace ModernKeePassLib.Utility
|
||||
}
|
||||
|
||||
string str;
|
||||
try
|
||||
{
|
||||
#if ModernKeePassLib
|
||||
var dirT = StorageFolder.GetFolderFromPathAsync(
|
||||
strPath).GetResults();
|
||||
str = dirT.Path;
|
||||
#else
|
||||
try { str = Path.GetFullPath(strPath); }
|
||||
#endif
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); return strPath; }
|
||||
|
||||
Debug.Assert((str.IndexOf("\\..\\") < 0) || NativeLib.IsUnix());
|
||||
@@ -692,11 +710,10 @@ namespace ModernKeePassLib.Utility
|
||||
string strDir;
|
||||
if(NativeLib.IsUnix())
|
||||
strDir = NativeMethods.GetUserRuntimeDir();
|
||||
#if KeePassUAP
|
||||
#if KeePassUAP || ModernKeePassLib
|
||||
else strDir = Windows.Storage.ApplicationData.Current.TemporaryFolder.Path;
|
||||
#else
|
||||
else strDir = Path.GetTempPath();
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
@@ -704,10 +721,11 @@ namespace ModernKeePassLib.Utility
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
|
||||
#endif
|
||||
return strDir;
|
||||
}
|
||||
|
||||
#if !KeePassLibSD
|
||||
#if !ModernKeePassLib && !KeePassLibSD
|
||||
// Structurally mostly equivalent to UrlUtil.GetFileInfos
|
||||
public static List<string> GetFilePaths(string strDir, string strPattern,
|
||||
SearchOption opt)
|
||||
|
@@ -24,6 +24,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Windows.Data.Xml.Dom;
|
||||
|
||||
namespace ModernKeePassLib.Utility
|
||||
{
|
||||
@@ -33,10 +34,12 @@ namespace ModernKeePassLib.Utility
|
||||
{
|
||||
XmlDocument d = new XmlDocument();
|
||||
|
||||
// .NET 4.5.2 and newer do not resolve external XML resources
|
||||
// by default; for older .NET versions, we explicitly
|
||||
// prevent resolving
|
||||
d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object
|
||||
// .NET 4.5.2 and newer do not resolve external XML resources
|
||||
// by default; for older .NET versions, we explicitly
|
||||
// prevent resolving
|
||||
#if !ModernKeePassLib
|
||||
d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object
|
||||
#endif
|
||||
|
||||
return d;
|
||||
}
|
||||
@@ -56,11 +59,11 @@ namespace ModernKeePassLib.Utility
|
||||
// Also see PrepMonoDev.sh script
|
||||
xrs.ProhibitDtd = true; // Obsolete in .NET 4, but still there
|
||||
// xrs.DtdProcessing = DtdProcessing.Prohibit; // .NET 4 only
|
||||
#endif
|
||||
|
||||
xrs.ValidationType = ValidationType.None;
|
||||
xrs.XmlResolver = null;
|
||||
|
||||
#endif
|
||||
return xrs;
|
||||
}
|
||||
|
||||
@@ -71,24 +74,28 @@ namespace ModernKeePassLib.Utility
|
||||
return XmlReader.Create(s, CreateXmlReaderSettings());
|
||||
}
|
||||
|
||||
public static XmlWriterSettings CreateXmlWriterSettings()
|
||||
public static XmlWriterSettings CreateXmlWriterSettings(bool isVersionGreaterThan4 = false)
|
||||
{
|
||||
XmlWriterSettings xws = new XmlWriterSettings();
|
||||
|
||||
xws.CloseOutput = false;
|
||||
xws.CloseOutput = isVersionGreaterThan4;
|
||||
xws.Encoding = StrUtil.Utf8;
|
||||
xws.Indent = true;
|
||||
xws.IndentChars = "\t";
|
||||
xws.NewLineOnAttributes = false;
|
||||
#if ModernKeePassLib
|
||||
// This is needed for Argon2Kdf write
|
||||
xws.Async = true;
|
||||
#endif
|
||||
|
||||
return xws;
|
||||
}
|
||||
|
||||
public static XmlWriter CreateXmlWriter(Stream s)
|
||||
public static XmlWriter CreateXmlWriter(Stream s, bool isVersionGreaterThan4 = false)
|
||||
{
|
||||
if(s == null) { Debug.Assert(false); throw new ArgumentNullException("s"); }
|
||||
|
||||
return XmlWriter.Create(s, CreateXmlWriterSettings());
|
||||
return XmlWriter.Create(s, CreateXmlWriterSettings(isVersionGreaterThan4));
|
||||
}
|
||||
|
||||
public static void Serialize<T>(Stream s, T t)
|
||||
|
Reference in New Issue
Block a user