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

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