add back custom ColorTranslator, fixes PlatformnotSupportedException, closes https://github.com/PhilippC/keepass2android/issues/1679
This commit is contained in:
@@ -24,9 +24,6 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using keepass2android;
|
using keepass2android;
|
||||||
#if !KeePassUAP
|
|
||||||
using System.Drawing;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Collections;
|
using KeePassLib.Collections;
|
||||||
|
|||||||
@@ -67,6 +67,51 @@ namespace KeePassLib.Serialization
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class KdbxFile
|
public sealed partial class KdbxFile
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// System.Drawing.ColorTranslator is not supported on Android. Provide a custom implementation here for loading colors from file.
|
||||||
|
/// </summary>
|
||||||
|
private class ColorTranslator
|
||||||
|
{
|
||||||
|
public static Color FromHtml(String colorString)
|
||||||
|
{
|
||||||
|
Color color;
|
||||||
|
|
||||||
|
if (colorString.StartsWith("#"))
|
||||||
|
{
|
||||||
|
colorString = colorString.Substring(1);
|
||||||
|
}
|
||||||
|
if (colorString.EndsWith(";"))
|
||||||
|
{
|
||||||
|
colorString = colorString.Substring(0, colorString.Length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int red, green, blue;
|
||||||
|
switch (colorString.Length)
|
||||||
|
{
|
||||||
|
case 6:
|
||||||
|
red = int.Parse(colorString.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
green = int.Parse(colorString.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
blue = int.Parse(colorString.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
color = Color.FromArgb(red, green, blue);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
red = int.Parse(colorString.Substring(0, 1), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
green = int.Parse(colorString.Substring(1, 1), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
blue = int.Parse(colorString.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
color = Color.FromArgb(red, green, blue);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
red = green = blue = int.Parse(colorString.Substring(0, 1), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
color = Color.FromArgb(red, green, blue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Invalid color: " + colorString);
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File identifier, first 32-bit value.
|
/// File identifier, first 32-bit value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user