mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 15:40:20 -04:00
Setup solution
This commit is contained in:
400
ModernKeePassLib/Translation/KPControlCustomization.cs
Normal file
400
ModernKeePassLib/Translation/KPControlCustomization.cs
Normal file
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
public sealed class KpccLayout
|
||||
{
|
||||
public enum LayoutParameterEx
|
||||
{
|
||||
X, Y, Width, Height
|
||||
}
|
||||
|
||||
private const string m_strControlRelative = @"%c";
|
||||
|
||||
internal const NumberStyles m_nsParser = (NumberStyles.AllowLeadingSign |
|
||||
NumberStyles.AllowDecimalPoint);
|
||||
internal static readonly CultureInfo m_lclInv = CultureInfo.InvariantCulture;
|
||||
|
||||
private string m_strPosX = string.Empty;
|
||||
[XmlAttribute]
|
||||
[DefaultValue("")]
|
||||
public string X
|
||||
{
|
||||
get { return m_strPosX; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strPosX = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strPosY = string.Empty;
|
||||
[XmlAttribute]
|
||||
[DefaultValue("")]
|
||||
public string Y
|
||||
{
|
||||
get { return m_strPosY; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strPosY = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strSizeW = string.Empty;
|
||||
[XmlAttribute]
|
||||
[DefaultValue("")]
|
||||
public string Width
|
||||
{
|
||||
get { return m_strSizeW; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strSizeW = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strSizeH = string.Empty;
|
||||
[XmlAttribute]
|
||||
[DefaultValue("")]
|
||||
public string Height
|
||||
{
|
||||
get { return m_strSizeH; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strSizeH = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetControlRelativeValue(LayoutParameterEx lp, string strValue)
|
||||
{
|
||||
Debug.Assert(strValue != null);
|
||||
if(strValue == null) throw new ArgumentNullException("strValue");
|
||||
|
||||
if(strValue.Length > 0) strValue += m_strControlRelative;
|
||||
|
||||
if(lp == LayoutParameterEx.X) m_strPosX = strValue;
|
||||
else if(lp == LayoutParameterEx.Y) m_strPosY = strValue;
|
||||
else if(lp == LayoutParameterEx.Width) m_strSizeW = strValue;
|
||||
else if(lp == LayoutParameterEx.Height) m_strSizeH = strValue;
|
||||
else { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
internal void ApplyTo(Control c)
|
||||
{
|
||||
Debug.Assert(c != null); if(c == null) return;
|
||||
|
||||
int? v;
|
||||
v = GetModControlParameter(c, LayoutParameterEx.X, m_strPosX);
|
||||
if(v.HasValue) c.Left = v.Value;
|
||||
v = GetModControlParameter(c, LayoutParameterEx.Y, m_strPosY);
|
||||
if(v.HasValue) c.Top = v.Value;
|
||||
v = GetModControlParameter(c, LayoutParameterEx.Width, m_strSizeW);
|
||||
if(v.HasValue) c.Width = v.Value;
|
||||
v = GetModControlParameter(c, LayoutParameterEx.Height, m_strSizeH);
|
||||
if(v.HasValue) c.Height = v.Value;
|
||||
}
|
||||
|
||||
private static int? GetModControlParameter(Control c, LayoutParameterEx p,
|
||||
string strModParam)
|
||||
{
|
||||
if(strModParam.Length == 0) return null;
|
||||
|
||||
Debug.Assert(c.Left == c.Location.X);
|
||||
Debug.Assert(c.Top == c.Location.Y);
|
||||
Debug.Assert(c.Width == c.Size.Width);
|
||||
Debug.Assert(c.Height == c.Size.Height);
|
||||
|
||||
int iPrev;
|
||||
if(p == LayoutParameterEx.X) iPrev = c.Left;
|
||||
else if(p == LayoutParameterEx.Y) iPrev = c.Top;
|
||||
else if(p == LayoutParameterEx.Width) iPrev = c.Width;
|
||||
else if(p == LayoutParameterEx.Height) iPrev = c.Height;
|
||||
else { Debug.Assert(false); return null; }
|
||||
|
||||
double? dRel = ToControlRelativePercent(strModParam);
|
||||
if(dRel.HasValue)
|
||||
return (iPrev + (int)((dRel.Value * (double)iPrev) / 100.0));
|
||||
|
||||
Debug.Assert(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double? ToControlRelativePercent(string strEncoded)
|
||||
{
|
||||
Debug.Assert(strEncoded != null);
|
||||
if(strEncoded == null) throw new ArgumentNullException("strEncoded");
|
||||
|
||||
if(strEncoded.Length == 0) return null;
|
||||
|
||||
if(strEncoded.EndsWith(m_strControlRelative))
|
||||
{
|
||||
string strValue = strEncoded.Substring(0, strEncoded.Length -
|
||||
m_strControlRelative.Length);
|
||||
if((strValue.Length == 1) && (strValue == "-"))
|
||||
strValue = "0";
|
||||
|
||||
double dRel;
|
||||
if(double.TryParse(strValue, m_nsParser, m_lclInv, out dRel))
|
||||
{
|
||||
return dRel;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Assert(false);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static string ToControlRelativeString(string strEncoded)
|
||||
{
|
||||
Debug.Assert(strEncoded != null);
|
||||
if(strEncoded == null) throw new ArgumentNullException("strEncoded");
|
||||
|
||||
if(strEncoded.Length == 0) return string.Empty;
|
||||
|
||||
if(strEncoded.EndsWith(m_strControlRelative))
|
||||
return strEncoded.Substring(0, strEncoded.Length -
|
||||
m_strControlRelative.Length);
|
||||
|
||||
Debug.Assert(false);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class KPControlCustomization : IComparable<KPControlCustomization>
|
||||
{
|
||||
private string m_strMemberName = string.Empty;
|
||||
/// <summary>
|
||||
/// Member variable name of the control to be translated.
|
||||
/// </summary>
|
||||
[XmlAttribute]
|
||||
public string Name
|
||||
{
|
||||
get { return m_strMemberName; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strMemberName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strHash = string.Empty;
|
||||
[XmlAttribute]
|
||||
public string BaseHash
|
||||
{
|
||||
get { return m_strHash; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strHash = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strText = string.Empty;
|
||||
[DefaultValue("")]
|
||||
public string Text
|
||||
{
|
||||
get { return m_strText; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strText = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strEngText = string.Empty;
|
||||
[XmlIgnore]
|
||||
public string TextEnglish
|
||||
{
|
||||
get { return m_strEngText; }
|
||||
set { m_strEngText = value; }
|
||||
}
|
||||
|
||||
private KpccLayout m_layout = new KpccLayout();
|
||||
public KpccLayout Layout
|
||||
{
|
||||
get { return m_layout; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_layout = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo(KPControlCustomization kpOther)
|
||||
{
|
||||
if(kpOther == null) { Debug.Assert(false); return 1; }
|
||||
|
||||
return m_strMemberName.CompareTo(kpOther.Name);
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
private static readonly Type[] m_vTextControls = new Type[] {
|
||||
typeof(MenuStrip), typeof(PictureBox), typeof(ListView),
|
||||
typeof(TreeView), typeof(ToolStrip), typeof(WebBrowser),
|
||||
typeof(Panel), typeof(StatusStrip), typeof(ProgressBar),
|
||||
typeof(NumericUpDown), typeof(TabControl)
|
||||
};
|
||||
|
||||
public static bool ControlSupportsText(object oControl)
|
||||
{
|
||||
if(oControl == null) return false;
|
||||
|
||||
Type t = oControl.GetType();
|
||||
for(int i = 0; i < m_vTextControls.Length; ++i)
|
||||
{
|
||||
if(t == m_vTextControls[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Name-unchecked (!) property application method
|
||||
internal void ApplyTo(Control c)
|
||||
{
|
||||
if((m_strText.Length > 0) && ControlSupportsText(c) &&
|
||||
(c.Text.Length > 0))
|
||||
{
|
||||
c.Text = m_strText;
|
||||
}
|
||||
|
||||
m_layout.ApplyTo(c);
|
||||
}
|
||||
|
||||
public static string HashControl(Control c)
|
||||
{
|
||||
if(c == null) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
WriteCpiParam(sb, c.Text);
|
||||
|
||||
if(c is Form)
|
||||
{
|
||||
WriteCpiParam(sb, c.ClientSize.Width.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.ClientSize.Height.ToString(KpccLayout.m_lclInv));
|
||||
}
|
||||
else // Normal control
|
||||
{
|
||||
WriteCpiParam(sb, c.Left.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.Top.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.Width.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.Height.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.Dock.ToString());
|
||||
}
|
||||
|
||||
WriteCpiParam(sb, c.Font.Name);
|
||||
WriteCpiParam(sb, c.Font.SizeInPoints.ToString(KpccLayout.m_lclInv));
|
||||
WriteCpiParam(sb, c.Font.Bold ? "B" : "N");
|
||||
WriteCpiParam(sb, c.Font.Italic ? "I" : "N");
|
||||
WriteCpiParam(sb, c.Font.Underline ? "U" : "N");
|
||||
WriteCpiParam(sb, c.Font.Strikeout ? "S" : "N");
|
||||
|
||||
WriteControlDependentParams(sb, c);
|
||||
|
||||
byte[] pb = StrUtil.Utf8.GetBytes(sb.ToString());
|
||||
byte[] pbSha = CryptoUtil.HashSha256(pb);
|
||||
|
||||
// See also MatchHash
|
||||
return "v1:" + Convert.ToBase64String(pbSha, 0, 3,
|
||||
Base64FormattingOptions.None);
|
||||
}
|
||||
|
||||
private static void WriteControlDependentParams(StringBuilder sb, Control c)
|
||||
{
|
||||
CheckBox cb = (c as CheckBox);
|
||||
RadioButton rb = (c as RadioButton);
|
||||
Button btn = (c as Button);
|
||||
Label l = (c as Label);
|
||||
LinkLabel ll = (c as LinkLabel);
|
||||
|
||||
if(cb != null)
|
||||
{
|
||||
WriteCpiParam(sb, cb.AutoSize ? "A" : "F");
|
||||
WriteCpiParam(sb, cb.TextAlign.ToString());
|
||||
WriteCpiParam(sb, cb.TextImageRelation.ToString());
|
||||
WriteCpiParam(sb, cb.Appearance.ToString());
|
||||
WriteCpiParam(sb, cb.CheckAlign.ToString());
|
||||
}
|
||||
else if(rb != null)
|
||||
{
|
||||
WriteCpiParam(sb, rb.AutoSize ? "A" : "F");
|
||||
WriteCpiParam(sb, rb.TextAlign.ToString());
|
||||
WriteCpiParam(sb, rb.TextImageRelation.ToString());
|
||||
WriteCpiParam(sb, rb.Appearance.ToString());
|
||||
WriteCpiParam(sb, rb.CheckAlign.ToString());
|
||||
}
|
||||
else if(btn != null)
|
||||
{
|
||||
WriteCpiParam(sb, btn.AutoSize ? "A" : "F");
|
||||
WriteCpiParam(sb, btn.TextAlign.ToString());
|
||||
WriteCpiParam(sb, btn.TextImageRelation.ToString());
|
||||
}
|
||||
else if(l != null)
|
||||
{
|
||||
WriteCpiParam(sb, l.AutoSize ? "A" : "F");
|
||||
WriteCpiParam(sb, l.TextAlign.ToString());
|
||||
}
|
||||
else if(ll != null)
|
||||
{
|
||||
WriteCpiParam(sb, ll.AutoSize ? "A" : "F");
|
||||
WriteCpiParam(sb, ll.TextAlign.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteCpiParam(StringBuilder sb, string strProp)
|
||||
{
|
||||
sb.Append('/');
|
||||
sb.Append(strProp);
|
||||
}
|
||||
|
||||
public bool MatchHash(string strHash)
|
||||
{
|
||||
if(strHash == null) throw new ArgumentNullException("strHash");
|
||||
|
||||
// Currently only v1: is supported, see HashControl
|
||||
return (m_strHash == strHash);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
108
ModernKeePassLib/Translation/KPFormCustomization.cs
Normal file
108
ModernKeePassLib/Translation/KPFormCustomization.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Windows.Forms;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
public sealed class KPFormCustomization
|
||||
{
|
||||
private string m_strFQName = string.Empty;
|
||||
/// <summary>
|
||||
/// The fully qualified name of the form.
|
||||
/// </summary>
|
||||
[XmlAttribute]
|
||||
public string FullName
|
||||
{
|
||||
get { return m_strFQName; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strFQName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private KPControlCustomization m_ccWindow = new KPControlCustomization();
|
||||
public KPControlCustomization Window
|
||||
{
|
||||
get { return m_ccWindow; }
|
||||
set { m_ccWindow = value; }
|
||||
}
|
||||
|
||||
private List<KPControlCustomization> m_vControls =
|
||||
new List<KPControlCustomization>();
|
||||
[XmlArray("ChildControls")]
|
||||
[XmlArrayItem("Control")]
|
||||
public List<KPControlCustomization> Controls
|
||||
{
|
||||
get { return m_vControls; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
m_vControls = value;
|
||||
}
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
private Form m_formEnglish = null;
|
||||
[XmlIgnore]
|
||||
public Form FormEnglish
|
||||
{
|
||||
get { return m_formEnglish; }
|
||||
set { m_formEnglish = value; }
|
||||
}
|
||||
|
||||
public void ApplyTo(Form form)
|
||||
{
|
||||
Debug.Assert(form != null); if(form == null) throw new ArgumentNullException("form");
|
||||
|
||||
// Not supported by TrlUtil (preview form):
|
||||
// Debug.Assert(form.GetType().FullName == m_strFQName);
|
||||
|
||||
m_ccWindow.ApplyTo(form);
|
||||
|
||||
if(m_vControls.Count == 0) return;
|
||||
foreach(Control c in form.Controls) ApplyToControl(c);
|
||||
}
|
||||
|
||||
private void ApplyToControl(Control c)
|
||||
{
|
||||
foreach(KPControlCustomization cc in m_vControls)
|
||||
{
|
||||
if(c.Name == cc.Name)
|
||||
{
|
||||
cc.ApplyTo(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(Control cSub in c.Controls) ApplyToControl(cSub);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
102
ModernKeePassLib/Translation/KPStringTable.cs
Normal file
102
ModernKeePassLib/Translation/KPStringTable.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Windows.Forms;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
public sealed class KPStringTable
|
||||
{
|
||||
private string m_strName = string.Empty;
|
||||
[XmlAttribute]
|
||||
public string Name
|
||||
{
|
||||
get { return m_strName; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_strName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private List<KPStringTableItem> m_vItems = new List<KPStringTableItem>();
|
||||
|
||||
[XmlArrayItem("Data")]
|
||||
public List<KPStringTableItem> Strings
|
||||
{
|
||||
get { return m_vItems; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
m_vItems = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> ToDictionary()
|
||||
{
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
|
||||
foreach(KPStringTableItem kpstItem in m_vItems)
|
||||
{
|
||||
if(kpstItem.Value.Length > 0)
|
||||
dict[kpstItem.Name] = kpstItem.Value;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
public void ApplyTo(ToolStripItemCollection tsic)
|
||||
{
|
||||
if(tsic == null) throw new ArgumentNullException("tsic");
|
||||
|
||||
Dictionary<string, string> dict = this.ToDictionary();
|
||||
if(dict.Count == 0) return;
|
||||
|
||||
this.ApplyTo(tsic, dict);
|
||||
}
|
||||
|
||||
private void ApplyTo(ToolStripItemCollection tsic, Dictionary<string, string> dict)
|
||||
{
|
||||
if(tsic == null) return;
|
||||
|
||||
foreach(ToolStripItem tsi in tsic)
|
||||
{
|
||||
if(tsi.Text.Length == 0) continue;
|
||||
|
||||
string strTrl;
|
||||
if(dict.TryGetValue(tsi.Name, out strTrl))
|
||||
tsi.Text = strTrl;
|
||||
|
||||
ToolStripMenuItem tsmi = tsi as ToolStripMenuItem;
|
||||
if((tsmi != null) && (tsmi.DropDownItems != null))
|
||||
this.ApplyTo(tsmi.DropDownItems);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
51
ModernKeePassLib/Translation/KPStringTableItem.cs
Normal file
51
ModernKeePassLib/Translation/KPStringTableItem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
public sealed class KPStringTableItem
|
||||
{
|
||||
private string m_strName = string.Empty;
|
||||
public string Name
|
||||
{
|
||||
get { return m_strName; }
|
||||
set { m_strName = value; }
|
||||
}
|
||||
|
||||
private string m_strValue = string.Empty;
|
||||
public string Value
|
||||
{
|
||||
get { return m_strValue; }
|
||||
set { m_strValue = value; }
|
||||
}
|
||||
|
||||
private string m_strEnglish = string.Empty;
|
||||
[XmlIgnore]
|
||||
public string ValueEnglish
|
||||
{
|
||||
get { return m_strEnglish; }
|
||||
set { m_strEnglish = value; }
|
||||
}
|
||||
}
|
||||
}
|
325
ModernKeePassLib/Translation/KPTranslation.cs
Normal file
325
ModernKeePassLib/Translation/KPTranslation.cs
Normal file
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
#if !KeePassUAP
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
#endif
|
||||
|
||||
#if KeePassLibSD
|
||||
using ICSharpCode.SharpZipLib.GZip;
|
||||
#else
|
||||
using System.IO.Compression;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
[XmlRoot("Translation")]
|
||||
public sealed class KPTranslation
|
||||
{
|
||||
public static readonly string FileExtension = "lngx";
|
||||
|
||||
private KPTranslationProperties m_props = new KPTranslationProperties();
|
||||
public KPTranslationProperties Properties
|
||||
{
|
||||
get { return m_props; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
m_props = value;
|
||||
}
|
||||
}
|
||||
|
||||
private List<KPStringTable> m_vStringTables = new List<KPStringTable>();
|
||||
|
||||
[XmlArrayItem("StringTable")]
|
||||
public List<KPStringTable> StringTables
|
||||
{
|
||||
get { return m_vStringTables; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
m_vStringTables = value;
|
||||
}
|
||||
}
|
||||
|
||||
private List<KPFormCustomization> m_vForms = new List<KPFormCustomization>();
|
||||
|
||||
[XmlArrayItem("Form")]
|
||||
public List<KPFormCustomization> Forms
|
||||
{
|
||||
get { return m_vForms; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
m_vForms = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strUnusedText = string.Empty;
|
||||
[DefaultValue("")]
|
||||
public string UnusedText
|
||||
{
|
||||
get { return m_strUnusedText; }
|
||||
set
|
||||
{
|
||||
if(value == null) throw new ArgumentNullException("value");
|
||||
|
||||
m_strUnusedText = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(KPTranslation kpTrl, string strFileName,
|
||||
IXmlSerializerEx xs)
|
||||
{
|
||||
using(FileStream fs = new FileStream(strFileName, FileMode.Create,
|
||||
FileAccess.Write, FileShare.None))
|
||||
{
|
||||
Save(kpTrl, fs, xs);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(KPTranslation kpTrl, Stream sOut,
|
||||
IXmlSerializerEx xs)
|
||||
{
|
||||
if(xs == null) throw new ArgumentNullException("xs");
|
||||
|
||||
#if !KeePassLibSD
|
||||
using(GZipStream gz = new GZipStream(sOut, CompressionMode.Compress))
|
||||
#else
|
||||
using(GZipOutputStream gz = new GZipOutputStream(sOut))
|
||||
#endif
|
||||
{
|
||||
using(XmlWriter xw = XmlUtilEx.CreateXmlWriter(gz))
|
||||
{
|
||||
xs.Serialize(xw, kpTrl);
|
||||
}
|
||||
}
|
||||
|
||||
sOut.Close();
|
||||
}
|
||||
|
||||
public static KPTranslation Load(string strFile, IXmlSerializerEx xs)
|
||||
{
|
||||
KPTranslation kpTrl = null;
|
||||
|
||||
using(FileStream fs = new FileStream(strFile, FileMode.Open,
|
||||
FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
kpTrl = Load(fs, xs);
|
||||
}
|
||||
|
||||
return kpTrl;
|
||||
}
|
||||
|
||||
public static KPTranslation Load(Stream s, IXmlSerializerEx xs)
|
||||
{
|
||||
if(xs == null) throw new ArgumentNullException("xs");
|
||||
|
||||
KPTranslation kpTrl = null;
|
||||
|
||||
#if !KeePassLibSD
|
||||
using(GZipStream gz = new GZipStream(s, CompressionMode.Decompress))
|
||||
#else
|
||||
using(GZipInputStream gz = new GZipInputStream(s))
|
||||
#endif
|
||||
{
|
||||
kpTrl = (xs.Deserialize(gz) as KPTranslation);
|
||||
}
|
||||
|
||||
s.Close();
|
||||
return kpTrl;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> SafeGetStringTableDictionary(
|
||||
string strTableName)
|
||||
{
|
||||
foreach(KPStringTable kpst in m_vStringTables)
|
||||
{
|
||||
if(kpst.Name == strTableName) return kpst.ToDictionary();
|
||||
}
|
||||
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
#if (!KeePassLibSD && !KeePassUAP)
|
||||
public void ApplyTo(Form form)
|
||||
{
|
||||
if(form == null) throw new ArgumentNullException("form");
|
||||
|
||||
if(m_props.RightToLeft)
|
||||
{
|
||||
try
|
||||
{
|
||||
form.RightToLeft = RightToLeft.Yes;
|
||||
form.RightToLeftLayout = true;
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
string strTypeName = form.GetType().FullName;
|
||||
foreach(KPFormCustomization kpfc in m_vForms)
|
||||
{
|
||||
if(kpfc.FullName == strTypeName)
|
||||
{
|
||||
kpfc.ApplyTo(form);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_props.RightToLeft)
|
||||
{
|
||||
try { RtlApplyToControls(form.Controls); }
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
}
|
||||
|
||||
private static void RtlApplyToControls(Control.ControlCollection cc)
|
||||
{
|
||||
foreach(Control c in cc)
|
||||
{
|
||||
if(c.Controls.Count > 0) RtlApplyToControls(c.Controls);
|
||||
|
||||
if(c is DateTimePicker)
|
||||
((DateTimePicker)c).RightToLeftLayout = true;
|
||||
else if(c is ListView)
|
||||
((ListView)c).RightToLeftLayout = true;
|
||||
else if(c is MonthCalendar)
|
||||
((MonthCalendar)c).RightToLeftLayout = true;
|
||||
else if(c is ProgressBar)
|
||||
((ProgressBar)c).RightToLeftLayout = true;
|
||||
else if(c is TabControl)
|
||||
((TabControl)c).RightToLeftLayout = true;
|
||||
else if(c is TrackBar)
|
||||
((TrackBar)c).RightToLeftLayout = true;
|
||||
else if(c is TreeView)
|
||||
((TreeView)c).RightToLeftLayout = true;
|
||||
// else if(c is ToolStrip)
|
||||
// RtlApplyToToolStripItems(((ToolStrip)c).Items);
|
||||
/* else if(c is Button) // Also see Label
|
||||
{
|
||||
Button btn = (c as Button);
|
||||
Image img = btn.Image;
|
||||
if(img != null)
|
||||
{
|
||||
Image imgNew = (Image)img.Clone();
|
||||
imgNew.RotateFlip(RotateFlipType.RotateNoneFlipX);
|
||||
btn.Image = imgNew;
|
||||
}
|
||||
}
|
||||
else if(c is Label) // Also see Button
|
||||
{
|
||||
Label lbl = (c as Label);
|
||||
Image img = lbl.Image;
|
||||
if(img != null)
|
||||
{
|
||||
Image imgNew = (Image)img.Clone();
|
||||
imgNew.RotateFlip(RotateFlipType.RotateNoneFlipX);
|
||||
lbl.Image = imgNew;
|
||||
}
|
||||
} */
|
||||
|
||||
if(IsRtlMoveChildsRequired(c)) RtlMoveChildControls(c);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsRtlMoveChildsRequired(Control c)
|
||||
{
|
||||
if(c == null) { Debug.Assert(false); return false; }
|
||||
|
||||
return ((c is GroupBox) || (c is Panel));
|
||||
}
|
||||
|
||||
private static void RtlMoveChildControls(Control cParent)
|
||||
{
|
||||
int nParentWidth = cParent.Size.Width;
|
||||
|
||||
foreach(Control c in cParent.Controls)
|
||||
{
|
||||
DockStyle ds = c.Dock;
|
||||
if(ds == DockStyle.Left)
|
||||
c.Dock = DockStyle.Right;
|
||||
else if(ds == DockStyle.Right)
|
||||
c.Dock = DockStyle.Left;
|
||||
else
|
||||
{
|
||||
Point ptCur = c.Location;
|
||||
c.Location = new Point(nParentWidth - c.Size.Width - ptCur.X, ptCur.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* private static readonly string[] g_vRtlMirrorItemNames = new string[] { };
|
||||
private static void RtlApplyToToolStripItems(ToolStripItemCollection tsic)
|
||||
{
|
||||
foreach(ToolStripItem tsi in tsic)
|
||||
{
|
||||
if(tsi == null) { Debug.Assert(false); continue; }
|
||||
|
||||
if(Array.IndexOf<string>(g_vRtlMirrorItemNames, tsi.Name) >= 0)
|
||||
tsi.RightToLeftAutoMirrorImage = true;
|
||||
|
||||
ToolStripDropDownItem tsdd = (tsi as ToolStripDropDownItem);
|
||||
if(tsdd != null)
|
||||
RtlApplyToToolStripItems(tsdd.DropDownItems);
|
||||
}
|
||||
} */
|
||||
|
||||
public void ApplyTo(string strTableName, ToolStripItemCollection tsic)
|
||||
{
|
||||
if(tsic == null) throw new ArgumentNullException("tsic");
|
||||
|
||||
KPStringTable kpst = null;
|
||||
foreach(KPStringTable kpstEnum in m_vStringTables)
|
||||
{
|
||||
if(kpstEnum.Name == strTableName)
|
||||
{
|
||||
kpst = kpstEnum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(kpst != null) kpst.ApplyTo(tsic);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal bool IsFor(string strIso6391Code)
|
||||
{
|
||||
if(strIso6391Code == null) { Debug.Assert(false); return false; }
|
||||
|
||||
return string.Equals(strIso6391Code, m_props.Iso6391Code,
|
||||
StrUtil.CaseIgnoreCmp);
|
||||
}
|
||||
}
|
||||
}
|
105
ModernKeePassLib/Translation/KPTranslationProperties.cs
Normal file
105
ModernKeePassLib/Translation/KPTranslationProperties.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ModernKeePassLib.Translation
|
||||
{
|
||||
public sealed class KPTranslationProperties
|
||||
{
|
||||
private string m_strApp = string.Empty;
|
||||
public string Application
|
||||
{
|
||||
get { return m_strApp; }
|
||||
set { m_strApp = value; }
|
||||
}
|
||||
|
||||
private string m_strForVersion = string.Empty;
|
||||
public string ApplicationVersion
|
||||
{
|
||||
get { return m_strForVersion; }
|
||||
set { m_strForVersion = value; }
|
||||
}
|
||||
|
||||
private string m_strNameEnglish = string.Empty;
|
||||
public string NameEnglish
|
||||
{
|
||||
get { return m_strNameEnglish; }
|
||||
set { m_strNameEnglish = value; }
|
||||
}
|
||||
|
||||
private string m_strNameNative = string.Empty;
|
||||
public string NameNative
|
||||
{
|
||||
get { return m_strNameNative; }
|
||||
set { m_strNameNative = value; }
|
||||
}
|
||||
|
||||
private string m_strIso6391Code = string.Empty;
|
||||
public string Iso6391Code
|
||||
{
|
||||
get { return m_strIso6391Code; }
|
||||
set { m_strIso6391Code = value; }
|
||||
}
|
||||
|
||||
private bool m_bRtl = false;
|
||||
public bool RightToLeft
|
||||
{
|
||||
get { return m_bRtl; }
|
||||
set { m_bRtl = value; }
|
||||
}
|
||||
|
||||
private string m_strAuthorName = string.Empty;
|
||||
public string AuthorName
|
||||
{
|
||||
get { return m_strAuthorName; }
|
||||
set { m_strAuthorName = value; }
|
||||
}
|
||||
|
||||
private string m_strAuthorContact = string.Empty;
|
||||
public string AuthorContact
|
||||
{
|
||||
get { return m_strAuthorContact; }
|
||||
set { m_strAuthorContact = value; }
|
||||
}
|
||||
|
||||
private string m_strGen = string.Empty;
|
||||
public string Generator
|
||||
{
|
||||
get { return m_strGen; }
|
||||
set { m_strGen = value; }
|
||||
}
|
||||
|
||||
private string m_strUuid = string.Empty;
|
||||
public string FileUuid
|
||||
{
|
||||
get { return m_strUuid; }
|
||||
set { m_strUuid = value; }
|
||||
}
|
||||
|
||||
private string m_strLastModified = string.Empty;
|
||||
public string LastModified
|
||||
{
|
||||
get { return m_strLastModified; }
|
||||
set { m_strLastModified = value; }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user