diff --git a/ModernKeePassLib.Test/Keys/KcpKeyFileTests.cs b/ModernKeePassLib.Test/Keys/KcpKeyFileTests.cs
index c729420..665671c 100644
--- a/ModernKeePassLib.Test/Keys/KcpKeyFileTests.cs
+++ b/ModernKeePassLib.Test/Keys/KcpKeyFileTests.cs
@@ -1,9 +1,11 @@
using System;
using System.IO;
+using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Utility;
using Windows.Storage;
+using Windows.Storage.Streams;
using NUnit.Framework;
namespace ModernKeePassLib.Test.Keys
@@ -58,15 +60,19 @@ namespace ModernKeePassLib.Test.Keys
sw.Write(ExpectedFileEnd);
}
- var keyFile = new KcpKeyFile(_file);
+ var fileBytes = (await FileIO.ReadBufferAsync(_file)).ToArray();
+
+ var keyFile = new KcpKeyFile(fileBytes);
var keyData = keyFile.KeyData.ReadData();
+
Assert.That(MemUtil.ArraysEqual(keyData, expectedKeyData), Is.True);
}
[Test]
public async Task TestCreate()
{
- KcpKeyFile.Create(_file, null);
+ var fileBytes = KcpKeyFile.Create(null);
+ await FileIO.WriteBytesAsync(_file, fileBytes);
var fileContents = await FileIO.ReadTextAsync(_file);
Assert.That(fileContents.Length, Is.EqualTo(185));
diff --git a/ModernKeePassLib.Test/Utility/GfxUtilTests.cs b/ModernKeePassLib.Test/Utility/GfxUtilTests.cs
index 25d0f35..a340ab3 100644
--- a/ModernKeePassLib.Test/Utility/GfxUtilTests.cs
+++ b/ModernKeePassLib.Test/Utility/GfxUtilTests.cs
@@ -1,4 +1,6 @@
-using NUnit.Framework;
+using System;
+using ModernKeePassLib.Utility;
+using NUnit.Framework;
namespace ModernKeePassLib.Test.Utility
{
@@ -6,20 +8,20 @@ namespace ModernKeePassLib.Test.Utility
public class GfxUtilTests
{
// 16x16 all white PNG file, base64 encoded
- const string testImageData =
+ private const string TestImageData =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAAsTAAA" +
"LEwEAmpwYAAAAB3RJTUUH3wMOFgIgmTCUMQAAABl0RVh0Q29tbWVudABDcmVhdG" +
"VkIHdpdGggR0lNUFeBDhcAAAAaSURBVCjPY/z//z8DKYCJgUQwqmFUw9DRAABVb" +
"QMdny4VogAAAABJRU5ErkJggg==";
- //[Test]
- //public void TestLoadImage ()
- //{
- // var testData = Convert.FromBase64String (testImageData);
- // var image = GfxUtil.ScaleImage(testData, 16, 16, ScaleTransformFlags.UIIcon);
- // //var image = GfxUtil.LoadImage(testData);
- // Assert.Equal(image.Width, 16);
- // Assert.Equal(image.Height, 16);
- //}
+ [Test]
+ public void TestLoadImage()
+ {
+ var testData = Convert.FromBase64String(TestImageData);
+ //var image = GfxUtil.ScaleImage(testData, 16, 16, ScaleTransformFlags.UIIcon);
+ var image = GfxUtil.LoadImage(testData);
+ Assert.That(image.Width, Is.EqualTo(16));
+ Assert.That(image.Height, Is.EqualTo(16));
+ }
}
}
diff --git a/ModernKeePassLib/Keys/KcpKeyFile.cs b/ModernKeePassLib/Keys/KcpKeyFile.cs
index 9ec1d5c..dc85ad8 100644
--- a/ModernKeePassLib/Keys/KcpKeyFile.cs
+++ b/ModernKeePassLib/Keys/KcpKeyFile.cs
@@ -27,9 +27,6 @@ using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
-using Windows.Security.Cryptography;
-using Windows.Security.Cryptography.Core;
-using Windows.Storage;
#else
using System.Security.Cryptography;
#endif
@@ -68,9 +65,9 @@ namespace ModernKeePassLib.Keys
get { return m_pbKeyData; }
}
#if ModernKeePassLib
- public KcpKeyFile(StorageFile keyFile)
+ public KcpKeyFile(byte[] keyFile)
{
- Construct(IOConnectionInfo.FromStorageFile(keyFile), false);
+ Construct(IOConnectionInfo.FromByteArray(keyFile), false);
}
#else
public KcpKeyFile(string strKeyFile)
@@ -192,7 +189,7 @@ namespace ModernKeePassLib.Keys
/// random number generator is used).
/// Returns a FileSaveResult error code.
#if ModernKeePassLib
- public static void Create(StorageFile file, byte[] pbAdditionalEntropy)
+ public static byte[] Create(byte[] pbAdditionalEntropy)
#else
public static void Create(string strFilePath, byte[] pbAdditionalEntropy)
#endif
@@ -215,7 +212,7 @@ namespace ModernKeePassLib.Keys
}
#if ModernKeePassLib
- CreateXmlKeyFile(file, pbFinalKey32);
+ return CreateXmlKeyFile(pbFinalKey32);
#else
CreateXmlKeyFile(strFilePath, pbFinalKey32);
#endif
@@ -281,10 +278,8 @@ namespace ModernKeePassLib.Keys
}
#if ModernKeePassLib
- private static void CreateXmlKeyFile(StorageFile file, byte[] pbKeyData)
+ private static byte[] CreateXmlKeyFile(byte[] pbKeyData)
{
- Debug.Assert(file != null);
- if (file == null) throw new ArgumentNullException(nameof(file));
#else
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
{
@@ -295,7 +290,8 @@ namespace ModernKeePassLib.Keys
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
#if ModernKeePassLib
- var ioc = IOConnectionInfo.FromStorageFile(file);
+ var fileContents = new byte[0];
+ var ioc = IOConnectionInfo.FromByteArray(fileContents);
#else
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
#endif
@@ -323,7 +319,10 @@ namespace ModernKeePassLib.Keys
xw.WriteEndElement(); //
xw.WriteEndDocument();
}
+#if ModernKeePassLib
+ return ((MemoryStream) s).ToArray();
+#endif
}
- }
- }
+ }
+ }
}
diff --git a/ModernKeePassLib/Keys/KcpUserAccount.cs b/ModernKeePassLib/Keys/KcpUserAccount.cs
index 452ba39..d6d53fc 100644
--- a/ModernKeePassLib/Keys/KcpUserAccount.cs
+++ b/ModernKeePassLib/Keys/KcpUserAccount.cs
@@ -23,12 +23,10 @@ using System.IO;
using System.Security;
#if ModernKeePassLib
-using Windows.Storage;
using System.Security.Cryptography;
#endif
using ModernKeePassLib.Cryptography;
-using ModernKeePassLib.Native;
using ModernKeePassLib.Resources;
using ModernKeePassLib.Security;
using ModernKeePassLib.Utility;
@@ -87,8 +85,8 @@ namespace ModernKeePassLib.Keys
private static string GetUserKeyFilePath(bool bCreate)
{
-#if ModernKeePassLib
- string strUserDir = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
+#if KeePassUAP
+ string strUserDir = EnvironmentExt.AppDataRoamingFolderPath;
#else
string strUserDir = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
@@ -97,11 +95,8 @@ namespace ModernKeePassLib.Keys
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
strUserDir += PwDefs.ShortProductName;
-#if !ModernKeePassLib
-
if(bCreate && !Directory.Exists(strUserDir))
Directory.CreateDirectory(strUserDir);
-#endif
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
return (strUserDir + UserKeyFileName);
@@ -115,15 +110,7 @@ namespace ModernKeePassLib.Keys
try
{
string strFilePath = GetUserKeyFilePath(false);
-
-#if ModernKeePassLib
- var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForReadAsync().GetAwaiter().GetResult();
- var pbProtectedKey = new byte[(int)fileStream.Length];
- fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
- fileStream.Dispose();
-#else
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
-#endif
pbKey = CryptoUtil.UnprotectData(pbProtectedKey, m_pbEntropy,
DataProtectionScope.CurrentUser);
@@ -148,13 +135,8 @@ namespace ModernKeePassLib.Keys
byte[] pbRandomKey = CryptoRandom.Instance.GetRandomBytes(64);
byte[] pbProtectedKey = CryptoUtil.ProtectData(pbRandomKey,
m_pbEntropy, DataProtectionScope.CurrentUser);
-#if ModernKeePassLib
- var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForWriteAsync().GetAwaiter().GetResult();
- fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
- fileStream.Dispose();
-#else
+
File.WriteAllBytes(strFilePath, pbProtectedKey);
-#endif
byte[] pbKey = LoadUserKey(true);
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));
diff --git a/ModernKeePassLib/ModernKeePassLib.csproj b/ModernKeePassLib/ModernKeePassLib.csproj
index 83ad1df..0a86d60 100644
--- a/ModernKeePassLib/ModernKeePassLib.csproj
+++ b/ModernKeePassLib/ModernKeePassLib.csproj
@@ -3,14 +3,14 @@
netstandard2.0
true
- 2.42.1
+ 2.42.1.1
Geoffroy Bonneville
- https://www.gnu.org/licenses/gpl-3.0.en.html
- https://github.com/wismna/ModernKeePass
- Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases.
+ https://www.gnu.org/licenses/gpl-3.0.en.html
+ https://github.com/wismna/ModernKeePassLib
+ Portable KeePass Password Management Library that targets .Net Standard. Allows reading, editing and writing to KeePass 2.x databases.
wismna
ModernKeePassLib
- Update to version 2.42.1
+ Removed dependency to UWP SDK, use ImageSharp for image processing
KeePass KeePassLib Portable PCL NetStandard ModernKeePass
Copyright © 2019 Geoffroy Bonneville
@@ -54,15 +54,9 @@
+
-
-
- ..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd
- true
-
-
-
diff --git a/ModernKeePassLib/PwCustomIcon.cs b/ModernKeePassLib/PwCustomIcon.cs
index 00343df..670a2fc 100644
--- a/ModernKeePassLib/PwCustomIcon.cs
+++ b/ModernKeePassLib/PwCustomIcon.cs
@@ -20,13 +20,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-#if !ModernKeePassLib
-using System.Drawing;
+#if ModernKeePassLib
+using SixLabors.ImageSharp;
#else
-using Windows.UI.Xaml.Controls;
+using System.Drawing;
#endif
using ModernKeePassLib.Utility;
+using SixLabors.ImageSharp.PixelFormats;
namespace ModernKeePassLib
{
@@ -38,8 +39,8 @@ namespace ModernKeePassLib
private readonly PwUuid m_pwUuid;
private readonly byte[] m_pbImageDataPng;
- private readonly Image m_imgOrg;
- private Dictionary m_dImageCache = new Dictionary();
+ private readonly Image m_imgOrg;
+ private Dictionary> m_dImageCache = new Dictionary>();
// Recommended maximum sizes, not obligatory
internal const int MaxWidth = 128;
@@ -56,7 +57,7 @@ namespace ModernKeePassLib
}
[Obsolete("Use GetImage instead.")]
- public Image Image
+ public Image Image
{
#if (!KeePassLibSD && !KeePassUAP)
get { return GetImage(16, 16); } // Backward compatibility
@@ -96,7 +97,7 @@ namespace ModernKeePassLib
///
/// Get the icon as an Image (original size).
///
- public Image GetImage()
+ public Image GetImage()
{
return m_imgOrg;
}
@@ -107,7 +108,7 @@ namespace ModernKeePassLib
///
/// Width of the returned image.
/// Height of the returned image.
- public Image GetImage(int w, int h)
+ public Image GetImage(int w, int h)
{
if(w < 0) { Debug.Assert(false); return m_imgOrg; }
if(h < 0) { Debug.Assert(false); return m_imgOrg; }
@@ -115,7 +116,7 @@ namespace ModernKeePassLib
long lID = GetID(w, h);
- Image img;
+ Image img;
if(m_dImageCache.TryGetValue(lID, out img)) return img;
img = GfxUtil.ScaleImage(m_imgOrg, w, h, ScaleTransformFlags.UIIcon);
diff --git a/ModernKeePassLib/Serialization/FileLock.cs b/ModernKeePassLib/Serialization/FileLock.cs
index 2f400ac..eb5af4a 100644
--- a/ModernKeePassLib/Serialization/FileLock.cs
+++ b/ModernKeePassLib/Serialization/FileLock.cs
@@ -24,9 +24,7 @@ using System.IO;
using System.Text;
using System.Threading;
#if ModernKeePassLib
-using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
-using Windows.Storage.Streams;
#endif
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Resources;
diff --git a/ModernKeePassLib/Serialization/FileTransactionEx.cs b/ModernKeePassLib/Serialization/FileTransactionEx.cs
index 0f57384..4180e55 100644
--- a/ModernKeePassLib/Serialization/FileTransactionEx.cs
+++ b/ModernKeePassLib/Serialization/FileTransactionEx.cs
@@ -23,13 +23,9 @@ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
-using Windows.Storage.AccessCache;
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
using System.Security.AccessControl;
#endif
-#if ModernKeePassLib
-using Windows.Storage;
-#endif
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Delegates;
@@ -237,7 +233,7 @@ namespace ModernKeePassLib.Serialization
FileSecurity sec = File.GetAccessControl(m_iocBase.Path, acs);
if(sec != null) pbSec = sec.GetSecurityDescriptorBinaryForm();
#endif
- }
+ }
catch(Exception) { Debug.Assert(NativeLib.IsUnix()); }
// if((long)(faBase & FileAttributes.ReadOnly) != 0)
@@ -351,13 +347,7 @@ namespace ModernKeePassLib.Serialization
if((chT != chB) && !TxfIsSupported(chT)) return;
m_iocTxfMidFallback = m_iocTemp;
-#if ModernKeePassLib
- var tempFile = ApplicationData.Current.TemporaryFolder.CreateFileAsync(m_iocTemp.Path).GetAwaiter()
- .GetResult();
- m_iocTemp = IOConnectionInfo.FromStorageFile(tempFile);
-#else
m_iocTemp = IOConnectionInfo.FromPath(strTemp);
-#endif
m_lToDelete.Add(m_iocTemp);
}
@@ -370,9 +360,9 @@ namespace ModernKeePassLib.Serialization
if(TxfMoveWithTx()) return true;
- // Move the temporary file onto the base file's drive first,
- // such that it cannot happen that both the base file and
- // the temporary file are deleted/corrupted
+ // Move the temporary file onto the base file's drive first,
+ // such that it cannot happen that both the base file and
+ // the temporary file are deleted/corrupted
#if !ModernKeePassLib
const uint f = (NativeMethods.MOVEFILE_COPY_ALLOWED |
NativeMethods.MOVEFILE_REPLACE_EXISTING);
@@ -441,10 +431,6 @@ namespace ModernKeePassLib.Serialization
{
try
{
-#if ModernKeePassLib
- ApplicationData.Current.TemporaryFolder.GetFileAsync(UrlUtil.GetTempPath()).GetAwaiter()
- .GetResult().DeleteAsync().GetAwaiter().GetResult();
-#else
// See also TxfPrepare method
DirectoryInfo di = new DirectoryInfo(UrlUtil.GetTempPath());
List l = UrlUtil.GetFileInfos(di, StrTxfTempPrefix +
@@ -460,7 +446,6 @@ namespace ModernKeePassLib.Serialization
if((DateTime.UtcNow - fi.LastWriteTimeUtc).TotalDays > 1.0)
fi.Delete();
}
-#endif
}
catch(Exception) { Debug.Assert(false); }
}
diff --git a/ModernKeePassLib/Serialization/IOConnection.cs b/ModernKeePassLib/Serialization/IOConnection.cs
index 35b64cc..a540c73 100644
--- a/ModernKeePassLib/Serialization/IOConnection.cs
+++ b/ModernKeePassLib/Serialization/IOConnection.cs
@@ -33,10 +33,6 @@ using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
#endif
-#if ModernKeePassLib
-using Windows.Storage;
-using Windows.Storage.Streams;
-#endif
using ModernKeePassLib.Native;
using ModernKeePassLib.Utility;
@@ -600,7 +596,7 @@ namespace ModernKeePassLib.Serialization
private static Stream OpenReadLocal(IOConnectionInfo ioc)
{
#if ModernKeePassLib
- return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetAwaiter().GetResult().AsStream();
+ return new MemoryStream(ioc.Bytes);
#else
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
FileShare.Read);
@@ -639,12 +635,12 @@ namespace ModernKeePassLib.Serialization
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
{
#if ModernKeePassLib
- return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetAwaiter().GetResult().AsStream();
+ return new MemoryStream();
#else
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
FileShare.None);
#endif
- }
+ }
public static bool FileExists(IOConnectionInfo ioc)
{
@@ -658,7 +654,7 @@ namespace ModernKeePassLib.Serialization
RaiseIOAccessPreEvent(ioc, IOAccessType.Exists);
#if ModernKeePassLib
- return ioc.StorageFile != null;
+ return ioc.Bytes != null;
#else
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
@@ -700,7 +696,7 @@ namespace ModernKeePassLib.Serialization
#if ModernKeePassLib
if (!ioc.IsLocalFile()) return;
- ioc.StorageFile?.DeleteAsync().GetAwaiter().GetResult();
+ MemUtil.ZeroByteArray(ioc.Bytes);
#else
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
@@ -737,10 +733,7 @@ namespace ModernKeePassLib.Serialization
{
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
-#if ModernKeePassLib
- if (!iocFrom.IsLocalFile()) return;
- iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetAwaiter().GetResult();
-#else
+#if !ModernKeePassLib
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
#if !KeePassLibSD
diff --git a/ModernKeePassLib/Serialization/IOConnectionInfo.cs b/ModernKeePassLib/Serialization/IOConnectionInfo.cs
index b4be643..fb267a3 100644
--- a/ModernKeePassLib/Serialization/IOConnectionInfo.cs
+++ b/ModernKeePassLib/Serialization/IOConnectionInfo.cs
@@ -24,9 +24,6 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml.Serialization;
-#if ModernKeePassLib
-using Windows.Storage;
-#endif
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Utility;
@@ -67,9 +64,9 @@ namespace ModernKeePassLib.Serialization
{
// private IOFileFormatHint m_ioHint = IOFileFormatHint.None;
- public StorageFile StorageFile { get; set; }
+ public byte[] Bytes { get; private set; }
- private string m_strUrl = string.Empty;
+ private string m_strUrl = string.Empty;
public string Path
{
get { return m_strUrl; }
@@ -118,7 +115,8 @@ namespace ModernKeePassLib.Serialization
}
private IOCredSaveMode m_ioCredSaveMode = IOCredSaveMode.NoSave;
- public IOCredSaveMode CredSaveMode
+
+ public IOCredSaveMode CredSaveMode
{
get { return m_ioCredSaveMode; }
set { m_ioCredSaveMode = value; }
@@ -315,16 +313,16 @@ namespace ModernKeePassLib.Serialization
}
#if ModernKeePassLib
- public static IOConnectionInfo FromStorageFile(StorageFile file)
- {
- IOConnectionInfo ioc = new IOConnectionInfo();
+ public static IOConnectionInfo FromByteArray(byte[] bytes)
+ {
+ IOConnectionInfo ioc = new IOConnectionInfo();
- ioc.StorageFile = file;
- ioc.CredSaveMode = IOCredSaveMode.NoSave;
+ ioc.Bytes = bytes;
+ ioc.CredSaveMode = IOCredSaveMode.NoSave;
- return ioc;
- }
-#else
+ return ioc;
+ }
+#endif
public static IOConnectionInfo FromPath(string strPath)
{
IOConnectionInfo ioc = new IOConnectionInfo();
@@ -334,16 +332,11 @@ namespace ModernKeePassLib.Serialization
return ioc;
}
-#endif
- public bool CanProbablyAccess()
+
+ public bool CanProbablyAccess()
{
#if ModernKeePassLib
- if (IsLocalFile())
- {
- //return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
- var file = StorageFile.GetFileFromPathAsync(m_strUrl).GetAwaiter().GetResult();
- return file != null;
- }
+ if (IsLocalFile()) return Bytes != null;
#else
if(IsLocalFile()) return File.Exists(m_strUrl);
#endif
diff --git a/ModernKeePassLib/Serialization/KdbxFile.Read.cs b/ModernKeePassLib/Serialization/KdbxFile.Read.cs
index 2f3921f..b924d5a 100644
--- a/ModernKeePassLib/Serialization/KdbxFile.Read.cs
+++ b/ModernKeePassLib/Serialization/KdbxFile.Read.cs
@@ -28,8 +28,6 @@ using System.Text;
using System.Xml;
#if !ModernKeePassLib && !KeePassUAP
using System.Security.Cryptography;
-#else
-using Windows.Storage;
#endif
#if !KeePassLibSD
@@ -62,9 +60,9 @@ namespace ModernKeePassLib.Serialization
/// Format.
/// Status logger (optional).
#if ModernKeePassLib
- public void Load(StorageFile file, KdbxFormat fmt, IStatusLogger slLogger)
+ public void Load(byte[] fileContents, KdbxFormat fmt, IStatusLogger slLogger)
{
- IOConnectionInfo ioc = IOConnectionInfo.FromStorageFile(file);
+ IOConnectionInfo ioc = IOConnectionInfo.FromByteArray(fileContents);
#else
public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger)
{
diff --git a/ModernKeePassLib/Serialization/KdbxFile.cs b/ModernKeePassLib/Serialization/KdbxFile.cs
index 55a01c7..3fb6faf 100644
--- a/ModernKeePassLib/Serialization/KdbxFile.cs
+++ b/ModernKeePassLib/Serialization/KdbxFile.cs
@@ -30,10 +30,6 @@ using System.Xml;
using System.Security.Cryptography;
#endif
-#if ModernKeePassLib
-using Windows.Storage;
-#endif
-
using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Cipher;
@@ -512,33 +508,11 @@ namespace ModernKeePassLib.Serialization
++iTry;
}
-#if ModernKeePassLib
- while (StorageFile.GetFileFromPathAsync(strPath).GetResults() != null);
-#else
while(File.Exists(strPath));
-#endif
-#if ModernKeePassLib
- byte[] pbData = pb.ReadData();
- /*var file = FileSystem.Current.GetFileFromPathAsync(strPath).Result;
- using (var stream = file.OpenAsync(FileAccess.ReadAndWrite).Result) {*/
- var file = StorageFile.GetFileFromPathAsync(strPath).GetAwaiter().GetResult();
- using (var stream = file.OpenAsync(FileAccessMode.ReadWrite).GetAwaiter().GetResult().AsStream())
- {
- stream.Write (pbData, 0, pbData.Length);
- }
- MemUtil.ZeroByteArray(pbData);
-#elif !KeePassLibSD
- byte[] pbData = pb.ReadData();
- File.WriteAllBytes(strPath, pbData);
- MemUtil.ZeroByteArray(pbData);
-#else
- FileStream fs = new FileStream(strPath, FileMode.Create,
- FileAccess.Write, FileShare.None);
byte[] pbData = pb.ReadData();
try { File.WriteAllBytes(strPath, pbData); }
finally { if(pb.IsProtected) MemUtil.ZeroByteArray(pbData); }
-#endif
}
}
}
diff --git a/ModernKeePassLib/Utility/GfxUtil.PCL.cs b/ModernKeePassLib/Utility/GfxUtil.PCL.cs
index b06a388..4eceb50 100644
--- a/ModernKeePassLib/Utility/GfxUtil.PCL.cs
+++ b/ModernKeePassLib/Utility/GfxUtil.PCL.cs
@@ -1,17 +1,21 @@
-using Windows.UI.Xaml.Controls;
+
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
namespace ModernKeePassLib.Utility
{
public class GfxUtil
{
- public static Image LoadImage(byte[] pb)
+ public static Image LoadImage(byte[] pb)
{
- return null;
+ return Image.Load(pb);
}
- public static Image ScaleImage(Image m_imgOrg, int? w, int? h, ScaleTransformFlags flags)
+ public static Image ScaleImage(Image m_imgOrg, int? w, int? h, ScaleTransformFlags flags)
{
- return null;
+ m_imgOrg.Mutate(i => i.Resize(w.GetValueOrDefault(), h.GetValueOrDefault()));
+ return m_imgOrg;
}
}
}
diff --git a/ModernKeePassLib/Utility/StreamExtensions.cs b/ModernKeePassLib/Utility/StreamExtensions.cs
deleted file mode 100644
index 499a4c2..0000000
--- a/ModernKeePassLib/Utility/StreamExtensions.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-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);
- }
- }
-}
diff --git a/ModernKeePassLib/Utility/UrlUtil.cs b/ModernKeePassLib/Utility/UrlUtil.cs
index e3b4f25..daa9ecd 100644
--- a/ModernKeePassLib/Utility/UrlUtil.cs
+++ b/ModernKeePassLib/Utility/UrlUtil.cs
@@ -25,10 +25,6 @@ using System.IO;
using System.Text;
using System.Text.RegularExpressions;
-#if ModernKeePassLib
-using Windows.Storage;
-#endif
-
using ModernKeePassLib.Native;
namespace ModernKeePassLib.Utility
@@ -44,14 +40,7 @@ namespace ModernKeePassLib.Utility
public static char LocalDirSepChar
{
-#if KeePassRT
- get { return '\\'; }
-#elif ModernKeePassLib
- //get { return PortablePath.DirectorySeparatorChar; }
- get { return '\\'; }
-#else
get { return Path.DirectorySeparatorChar; }
-#endif
}
private static char[] g_vDirSepChars = null;
@@ -486,16 +475,7 @@ namespace ModernKeePassLib.Utility
}
string str;
- try
- {
-#if ModernKeePassLib
- var dirT = StorageFolder.GetFolderFromPathAsync(
- strPath).GetResults();
- str = dirT.Path;
-#else
- str = Path.GetFullPath(strPath);
-#endif
- }
+ try { str = Path.GetFullPath(strPath); }
catch(Exception) { Debug.Assert(false); return strPath; }
Debug.Assert((str.IndexOf("\\..\\") < 0) || NativeLib.IsUnix());
@@ -703,10 +683,11 @@ namespace ModernKeePassLib.Utility
string strDir;
if(NativeLib.IsUnix())
strDir = NativeMethods.GetUserRuntimeDir();
-#if KeePassUAP || ModernKeePassLib
+#if KeePassUAP
else strDir = Windows.Storage.ApplicationData.Current.TemporaryFolder.Path;
#else
else strDir = Path.GetTempPath();
+#endif
try
{
@@ -714,11 +695,10 @@ namespace ModernKeePassLib.Utility
}
catch(Exception) { Debug.Assert(false); }
-#endif
return strDir;
}
-#if !ModernKeePassLib && !KeePassLibSD
+#if !KeePassLibSD
// Structurally mostly equivalent to UrlUtil.GetFileInfos
public static List GetFilePaths(string strDir, string strPattern,
SearchOption opt)