WIP saving

This commit is contained in:
2017-09-20 18:45:37 +02:00
parent 668ffcb107
commit c4ac244270
6 changed files with 64 additions and 67 deletions

View File

@@ -54,7 +54,7 @@
<HyperlinkButton Grid.Row="0" Grid.ColumnSpan="2" Content="Select password database" Click="Button_Click" /> <HyperlinkButton Grid.Row="0" Grid.ColumnSpan="2" Content="Select password database" Click="Button_Click" />
<TextBlock Grid.Column="0" Grid.Row="1" x:Name="PasswordTextBlock" HorizontalAlignment="Left" Visibility="{Binding Visibility}" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" /> <TextBlock Grid.Column="0" Grid.Row="1" x:Name="PasswordTextBlock" HorizontalAlignment="Left" Visibility="{Binding Visibility}" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
<PasswordBox Grid.Column="1" Grid.Row="1" x:Name="PasswordBox" VerticalAlignment="Top" HorizontalAlignment=" Right" Visibility="{Binding Visibility}" Width="130" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/> <PasswordBox Grid.Column="1" Grid.Row="1" x:Name="PasswordBox" VerticalAlignment="Top" HorizontalAlignment=" Right" Visibility="{Binding Visibility}" Width="130" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
<TextBlock Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Text="{Binding ErrorMessage}" Foreground="#FF9E1B1B" /> <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding ErrorMessage}" Foreground="#FF9E1B1B" />
<Button Grid.Column="1" Grid.Row="3" x:Name="OpenButton" Content="OK" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="{Binding Visibility}" Click="openBbutton_Click" Margin="0,0,7,0" Width="auto"/> <Button Grid.Column="1" Grid.Row="3" x:Name="OpenButton" Content="OK" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="{Binding Visibility}" Click="openBbutton_Click" Margin="0,0,7,0" Width="auto"/>
</Grid> </Grid>
<HyperlinkButton Grid.Column="2" Name="SaveButton" Content="Save file" Click="saveBbutton_Click" VerticalAlignment="Top" Margin="0,30,0,0" Visibility="Collapsed" /> <HyperlinkButton Grid.Column="2" Name="SaveButton" Content="Save file" Click="saveBbutton_Click" VerticalAlignment="Top" Margin="0,30,0,0" Visibility="Collapsed" />

View File

@@ -159,8 +159,8 @@
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ModernKeePassLib, Version=2.19.0.24806, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ModernKeePassLib, Version=2.19.0.33692, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLib.2.19.0.24806\lib\netstandard1.2\ModernKeePassLib.dll</HintPath> <HintPath>..\packages\ModernKeePassLib.2.19.0.33692\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

View File

@@ -2,7 +2,7 @@
<packages> <packages>
<package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="win81" /> <package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="win81" />
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" /> <package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" />
<package id="ModernKeePassLib" version="2.19.0.24806" targetFramework="win81" /> <package id="ModernKeePassLib" version="2.19.0.33692" targetFramework="win81" />
<package id="NETStandard.Library" version="2.0.0" targetFramework="win81" /> <package id="NETStandard.Library" version="2.0.0" targetFramework="win81" />
<package id="System.Net.Requests" version="4.3.0" targetFramework="win81" /> <package id="System.Net.Requests" version="4.3.0" targetFramework="win81" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" /> <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" />

View File

@@ -18,17 +18,16 @@ namespace ModernKeePassLib.Serialization
private IEnumerator<byte> m_enumerator = null; private IEnumerator<byte> m_enumerator = null;
public CryptoStream(Stream s, String strAlgName, bool bEncrypt, byte[] pbKey, byte[] pbIV) public CryptoStream(Stream s, String strAlgName, bool bEncrypt, byte[] pbKey, byte[] pbIV)
: base()
{ {
IBuffer iv = CryptographicBuffer.CreateFromByteArray(pbIV); IBuffer iv = CryptographicBuffer.CreateFromByteArray(pbIV);
SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName); SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);
CryptographicKey key = objAlg.CreateSymmetricKey( CryptographicBuffer.CreateFromByteArray(pbKey) ); CryptographicKey key = objAlg.CreateSymmetricKey( CryptographicBuffer.CreateFromByteArray(pbKey) );
if (bEncrypt) /*if (bEncrypt)
{ {
Debug.Assert(false, "Not implemented yet"); Debug.Assert(false, "Not implemented yet");
} }
else else
{ {*/
// For the time being, WinRT CryptographicEngine doesn't support stream decoding. Bummer. // For the time being, WinRT CryptographicEngine doesn't support stream decoding. Bummer.
// Copy the file to a memory buffer, then decode all at once. // Copy the file to a memory buffer, then decode all at once.
@@ -50,7 +49,7 @@ namespace ModernKeePassLib.Serialization
} }
CryptographicBuffer.CopyToByteArray(decoded, out m_decoded); CryptographicBuffer.CopyToByteArray(decoded, out m_decoded);
m_enumerator = m_decoded.AsEnumerable().GetEnumerator(); m_enumerator = m_decoded.AsEnumerable().GetEnumerator();
} //}
} }

View File

@@ -281,13 +281,13 @@ namespace ModernKeePassLib.Serialization
return CreateWebClient(ioc).OpenWrite(uri); return CreateWebClient(ioc).OpenWrite(uri);
} }
#else #else
public async static Task<Stream> OpenWrite(IOConnectionInfo ioc) public static async Task<Stream> OpenWrite(IOConnectionInfo ioc)
{ {
return await OpenWriteLocal(ioc); return await OpenWriteLocal(ioc);
} }
#endif #endif
private async static Task<Stream> OpenWriteLocal(IOConnectionInfo ioc) private static async Task<Stream> OpenWriteLocal(IOConnectionInfo ioc)
{ {
try try
{ {
@@ -303,18 +303,15 @@ namespace ModernKeePassLib.Serialization
public static bool FileExists(IOConnectionInfo ioc) public static bool FileExists(IOConnectionInfo ioc)
{ {
return FileExists(ioc, false); //return FileExists(ioc, false);
return true;
} }
public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors) /*public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors)
{ {
Debug.Assert(false, "Not implemented yet");
return false;
#if TODO
if(ioc == null) { Debug.Assert(false); return false; } if(ioc == null) { Debug.Assert(false); return false; }
if(ioc.IsLocalFile()) return File.Exists(ioc.Path); if(ioc.IsLocalFile()) return ioc.StorageFile.IsAvailable;
try try
{ {
@@ -334,15 +331,12 @@ namespace ModernKeePassLib.Serialization
} }
return true; return true;
#endif }*/
}
public static void DeleteFile(IOConnectionInfo ioc) public static async void DeleteFile(IOConnectionInfo ioc)
{ {
Debug.Assert(false, "Not implemented yet"); if(ioc.IsLocalFile()) { await ioc.StorageFile.DeleteAsync(StorageDeleteOption.Default);
return ; }
#if TODO
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
#if !KeePassLibSD && TODO #if !KeePassLibSD && TODO
WebRequest req = CreateWebRequest(ioc); WebRequest req = CreateWebRequest(ioc);
@@ -359,7 +353,6 @@ namespace ModernKeePassLib.Serialization
DisposeResponse(req.GetResponse(), true); DisposeResponse(req.GetResponse(), true);
} }
#endif
#endif #endif
} }
@@ -372,11 +365,9 @@ namespace ModernKeePassLib.Serialization
/// </summary> /// </summary>
/// <param name="iocFrom">Source file path.</param> /// <param name="iocFrom">Source file path.</param>
/// <param name="iocTo">Target file path.</param> /// <param name="iocTo">Target file path.</param>
public static void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo) public static async void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
{ {
return; if(iocFrom.IsLocalFile()) { await iocTo.StorageFile.RenameAsync(iocTo.Path, NameCollisionOption.GenerateUniqueName); }
#if TODO
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
#if !KeePassLibSD && TODO #if !KeePassLibSD && TODO
WebRequest req = CreateWebRequest(iocFrom); WebRequest req = CreateWebRequest(iocFrom);
@@ -419,7 +410,6 @@ namespace ModernKeePassLib.Serialization
// sIn.Close(); // sIn.Close();
// } // }
// DeleteFile(iocFrom); // DeleteFile(iocFrom);
#endif
} }
private static void DisposeResponse(WebResponse wr, bool bGetStream) private static void DisposeResponse(WebResponse wr, bool bGetStream)

View File

@@ -120,7 +120,11 @@ namespace ModernKeePassLib.Serialization
} }
else if (m_format == Kdb4Format.PlainXml) else if (m_format == Kdb4Format.PlainXml)
writerStream = hashedStream; writerStream = hashedStream;
else { Debug.Assert(false); throw new FormatException("KdbFormat"); } else
{
Debug.Assert(false);
throw new FormatException("KdbFormat");
}
using (m_xmlWriter = XmlWriter.Create(writerStream, new XmlWriterSettings {Encoding = encNoBom})) using (m_xmlWriter = XmlWriter.Create(writerStream, new XmlWriterSettings {Encoding = encNoBom}))
{ {
@@ -130,6 +134,10 @@ namespace ModernKeePassLib.Serialization
writerStream.Dispose(); writerStream.Dispose();
} }
GC.KeepAlive(bw); GC.KeepAlive(bw);
}
catch (Exception ex)
{
} }
finally { CommonCleanUpWrite(sSaveTo, hashedStream); } finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
} }