Removed dependencies to UWP SDK

Added ImageSharp for image processing
This commit is contained in:
Geoffroy BONNEVILLE
2019-07-31 11:48:42 +02:00
parent fdba7c182d
commit 84adf3785b
15 changed files with 92 additions and 200 deletions

View File

@@ -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));

View File

@@ -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));
}
}
}

View File

@@ -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).</param>
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
#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(); // </KeyFile>
xw.WriteEndDocument();
}
#if ModernKeePassLib
return ((MemoryStream) s).ToArray();
#endif
}
}
}
}
}
}

View File

@@ -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));

View File

@@ -3,14 +3,14 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.42.1</Version>
<Version>2.42.1.1</Version>
<Authors>Geoffroy Bonneville</Authors>
<PackageLicenseUrl>https://www.gnu.org/licenses/gpl-3.0.en.html</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/wismna/ModernKeePass</PackageProjectUrl>
<Description>Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases.</Description>
<PackageLicense>https://www.gnu.org/licenses/gpl-3.0.en.html</PackageLicense>
<PackageProjectUrl>https://github.com/wismna/ModernKeePassLib</PackageProjectUrl>
<Description>Portable KeePass Password Management Library that targets .Net Standard. Allows reading, editing and writing to KeePass 2.x databases.</Description>
<Company>wismna</Company>
<Product>ModernKeePassLib</Product>
<PackageReleaseNotes>Update to version 2.42.1</PackageReleaseNotes>
<PackageReleaseNotes>Removed dependency to UWP SDK, use ImageSharp for image processing</PackageReleaseNotes>
<PackageTags>KeePass KeePassLib Portable PCL NetStandard ModernKeePass</PackageTags>
<Copyright>Copyright © 2019 Geoffroy Bonneville</Copyright>
</PropertyGroup>
@@ -54,15 +54,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Windows">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
<IsWinMDFile>true</IsWinMDFile>
</Reference>
</ItemGroup>
</Project>

View File

@@ -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<long, Image> m_dImageCache = new Dictionary<long, Image>();
private readonly Image<Rgba32> m_imgOrg;
private Dictionary<long, Image<Rgba32>> m_dImageCache = new Dictionary<long, Image<Rgba32>>();
// 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<Rgba32> Image
{
#if (!KeePassLibSD && !KeePassUAP)
get { return GetImage(16, 16); } // Backward compatibility
@@ -96,7 +97,7 @@ namespace ModernKeePassLib
/// <summary>
/// Get the icon as an <c>Image</c> (original size).
/// </summary>
public Image GetImage()
public Image<Rgba32> GetImage()
{
return m_imgOrg;
}
@@ -107,7 +108,7 @@ namespace ModernKeePassLib
/// </summary>
/// <param name="w">Width of the returned image.</param>
/// <param name="h">Height of the returned image.</param>
public Image GetImage(int w, int h)
public Image<Rgba32> 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<Rgba32> img;
if(m_dImageCache.TryGetValue(lID, out img)) return img;
img = GfxUtil.ScaleImage(m_imgOrg, w, h, ScaleTransformFlags.UIIcon);

View File

@@ -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;

View File

@@ -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<FileInfo> 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); }
}

View File

@@ -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

View File

@@ -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

View File

@@ -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
/// <param name="fmt">Format.</param>
/// <param name="slLogger">Status logger (optional).</param>
#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)
{

View File

@@ -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
}
}
}

View File

@@ -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<Rgba32> LoadImage(byte[] pb)
{
return null;
return Image.Load<Rgba32>(pb);
}
public static Image ScaleImage(Image m_imgOrg, int? w, int? h, ScaleTransformFlags flags)
public static Image<Rgba32> ScaleImage(Image<Rgba32> m_imgOrg, int? w, int? h, ScaleTransformFlags flags)
{
return null;
m_imgOrg.Mutate(i => i.Resize(w.GetValueOrDefault(), h.GetValueOrDefault()));
return m_imgOrg;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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<string> GetFilePaths(string strDir, string strPattern,
SearchOption opt)