Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Update to net5 #3

Open
wants to merge 11 commits into
base: stable
Choose a base branch
from
1,716 changes: 858 additions & 858 deletions KeePass/Forms/DatabaseSettingsForm.cs

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions KeePass/KeePass.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net40</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>KeePass.ico</ApplicationIcon>
<AssemblyOriginatorKeyFile>KeePass.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\KeePassLib\KeePassLib.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Security" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion KeePass/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ internal static Mutex TryGlobalInstanceNotify(string strBaseName)
ms.AddAccessRule(mar);

bool bCreatedNew;
return new Mutex(false, strName, out bCreatedNew, ms);
return new Mutex(false, strName, out bCreatedNew);
}
catch(Exception) { } // Windows 9x and Mono 2.0+ (AddAccessRule) throw

Expand Down
32 changes: 16 additions & 16 deletions KeePass/UI/ColorMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You should have received a copy of the GNU General Public License

namespace KeePass.UI
{
public sealed class ColorMenuItem : MenuItem
public sealed class ColorMenuItem : ToolStripMenuItem
{
private Color m_clr;
private int m_qSize;
Expand All @@ -41,27 +41,27 @@ public ColorMenuItem(Color clr, int qSize) : base()
m_clr = clr;
m_qSize = qSize;

Debug.Assert(this.CanRaiseEvents);
this.ShowShortcut = false;
this.OwnerDraw = true;
Debug.Assert(CanRaiseEvents);
}

protected override void OnDrawItem(DrawItemEventArgs e)

protected override void OnPaint(PaintEventArgs e)
{
// base.OnDrawItem(e);

Graphics g = e.Graphics;
Rectangle rectBounds = e.Bounds;
Rectangle rectBounds = e.ClipRectangle;
Rectangle rectFill = new Rectangle(rectBounds.Left + 2,
rectBounds.Top + 2, rectBounds.Width - 4, rectBounds.Height - 4);

bool bFocused = (((e.State & DrawItemState.Focus) != DrawItemState.None) ||
((e.State & DrawItemState.Selected) != DrawItemState.None));
//bool bFocused = (((State & DrawItemState.Focus) != DrawItemState.None) ||
// ((e.State & DrawItemState.Selected) != DrawItemState.None));

// e.DrawBackground();
// e.DrawFocusRectangle();
using(SolidBrush sbBack = new SolidBrush(bFocused ?
SystemColors.Highlight : SystemColors.Menu))
//using(SolidBrush sbBack = new SolidBrush(bFocused ?
// SystemColors.Highlight : SystemColors.Menu))
using (SolidBrush sbBack = new SolidBrush(SystemColors.Menu))
{
g.FillRectangle(sbBack, rectBounds);
}
Expand All @@ -72,12 +72,12 @@ protected override void OnDrawItem(DrawItemEventArgs e)
}
}

protected override void OnMeasureItem(MeasureItemEventArgs e)
{
// base.OnMeasureItem(e);
//protected override void OnMeasureItem(MeasureItemEventArgs e)
//{
// // base.OnMeasureItem(e);

e.ItemWidth = m_qSize;
e.ItemHeight = m_qSize;
}
// e.ItemWidth = m_qSize;
// e.ItemHeight = m_qSize;
//}
}
}
29 changes: 14 additions & 15 deletions KeePass/UI/CustomContextMenuEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ You should have received a copy of the GNU General Public License

namespace KeePass.UI
{
public sealed class CustomContextMenuEx : ContextMenu
{
public CustomContextMenuEx() : base() { }
public sealed class CustomContextMenuEx : ContextMenuStrip
{
public CustomContextMenuEx() : base() { }

public void ShowEx(Control cParent)
{
if(cParent == null) { Debug.Assert(false); return; }
public void ShowEx(Control cParent)
{
if (cParent == null) { Debug.Assert(false); return; }

if(cParent.RightToLeft == RightToLeft.Yes)
{
this.RightToLeft = RightToLeft.Yes;
Show(cParent, new Point(cParent.Width, cParent.Height),
LeftRightAlignment.Left);
}
else Show(cParent, new Point(0, cParent.Height));
}
}
if (cParent.RightToLeft == RightToLeft.Yes)
{
this.RightToLeft = RightToLeft.Yes;
Show(cParent, new Point(cParent.Width, cParent.Height), ToolStripDropDownDirection.Left);
}
else Show(cParent, new Point(0, cParent.Height));
}
}
}
7 changes: 1 addition & 6 deletions KeePass/UI/EnableThemingInScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ private static bool EnsureActCtxCreated()
{
if(m_nhCtx.HasValue) return true;

string strAsmLoc;
FileIOPermission p = new FileIOPermission(PermissionState.None);
p.AllFiles = FileIOPermissionAccess.PathDiscovery;
p.Assert();
try { strAsmLoc = typeof(object).Assembly.Location; }
finally { CodeAccessPermission.RevertAssert(); }
string strAsmLoc = typeof(object).Assembly.Location;
if(string.IsNullOrEmpty(strAsmLoc)) { Debug.Assert(false); return false; }

string strInstDir = Path.GetDirectoryName(strAsmLoc);
Expand Down
7 changes: 3 additions & 4 deletions KeePass/UI/UIUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public static List<Image> BuildImageListEx(List<PwCustomIcon> lIcons,
if(img == null)
{
Debug.Assert(false);
img = UIUtil.CreateColorBitmap24(nWidth, nHeight, Color.White);
img = CreateColorBitmap24(nWidth, nHeight, Color.White);
}

if((img.Width != nWidth) || (img.Height != nHeight))
Expand Down Expand Up @@ -2629,7 +2629,7 @@ public static Image ExtractVistaIcon(Icon ico)
{
if(ico == null) { Debug.Assert(false); return null; }

MemoryStream ms = new MemoryStream();
using MemoryStream ms = new ();
try
{
ico.Save(ms);
Expand All @@ -2638,7 +2638,6 @@ public static Image ExtractVistaIcon(Icon ico)
return GfxUtil.LoadImage(pb); // Extracts best image from ICO
}
catch { Debug.Assert(false); }
finally { ms.Close(); }

return null;
}
Expand Down Expand Up @@ -3342,7 +3341,7 @@ public static bool HandleCommonKeyEvent(KeyEventArgs e, bool bDown,

if(bOp)
{
ContextMenu cm = cCtx.ContextMenu;
var cm = cCtx.ContextMenuStrip;
ContextMenuStrip cms = cCtx.ContextMenuStrip;

if(cms != null) cms.Show(Cursor.Position);
Expand Down
68 changes: 34 additions & 34 deletions KeePassLib/Cryptography/CryptoRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ You should have received a copy of the GNU General Public License
#if !KeePassUAP
using System.Drawing;
using System.Security.Cryptography;
using System.Windows.Forms;
#endif

using KeePassLib.Delegates;
using KeePassLib.Native;
using KeePassLib.Security;
using KeePassLib.Utility;
using System.Windows.Forms;

namespace KeePassLib.Cryptography
{
Expand All @@ -42,16 +42,16 @@ namespace KeePassLib.Cryptography
/// The returned values are unpredictable and cannot be reproduced.
/// <c>CryptoRandom</c> is a singleton class.
/// </summary>
public sealed class CryptoRandom
public sealed class CryptoRandom : IDisposable
{
private ProtectedBinary m_pbEntropyPool = new ProtectedBinary(
private ProtectedBinary m_pbEntropyPool = new(
true, new byte[64]);
private readonly RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
private readonly RNGCryptoServiceProvider m_rng = new();
private ulong m_uCounter;
private ulong m_uGeneratedBytesCount = 0;

private static readonly object g_oSyncRoot = new object();
private readonly object m_oSyncRoot = new object();
private static readonly object g_oSyncRoot = new();
private readonly object m_oSyncRoot = new();

private static CryptoRandom g_pInstance = null;
public static CryptoRandom Instance
Expand Down Expand Up @@ -157,33 +157,33 @@ public void AddEntropy(byte[] pbEntropy)

private byte[] GetSystemEntropy()
{
var h = new SHA512Managed();
using var h = new SHA512Managed();
var pb4 = new byte[4];
var pb8 = new byte[8];

GAction<byte[], bool> f = delegate (byte[] pbValue, bool bClearValue)
void f(byte[] pbValue, bool bClearValue)
{
if (pbValue == null) { Debug.Assert(false); return; }
if (pbValue.Length == 0) return;
h.TransformBlock(pbValue, 0, pbValue.Length, pbValue, 0);
if (bClearValue) MemUtil.ZeroByteArray(pbValue);
};
Action<int> fI32 = delegate (int iValue)
}
void fI32(int iValue)
{
MemUtil.Int32ToBytesEx(iValue, pb4, 0);
f(pb4, false);
};
Action<long> fI64 = delegate (long lValue)
}
void fI64(long lValue)
{
MemUtil.Int64ToBytesEx(lValue, pb8, 0);
f(pb8, false);
};
Action<string> fStr = delegate (string strValue)
}
void fStr(string strValue)
{
if (strValue == null) { Debug.Assert(false); return; }
if (strValue.Length == 0) return;
f(StrUtil.Utf8.GetBytes(strValue), false);
};
}

fI32(Environment.TickCount);
fI64(DateTime.UtcNow.ToBinary());
Expand Down Expand Up @@ -233,25 +233,23 @@ private byte[] GetSystemEntropy()
#if KeePassUAP
f(DiagnosticsExt.GetProcessEntropy(), true);
#elif !KeePassLibSD
using (var p = Process.GetCurrentProcess())
{
fI64(p.Handle.ToInt64());
fI32(p.HandleCount);
fI32(p.Id);
fI64(p.NonpagedSystemMemorySize64);
fI64(p.PagedMemorySize64);
fI64(p.PagedSystemMemorySize64);
fI64(p.PeakPagedMemorySize64);
fI64(p.PeakVirtualMemorySize64);
fI64(p.PeakWorkingSet64);
fI64(p.PrivateMemorySize64);
fI64(p.StartTime.ToBinary());
fI64(p.VirtualMemorySize64);
fI64(p.WorkingSet64);

// Not supported in Mono 1.2.6:
// fI32(p.SessionId);
}
using var p = Process.GetCurrentProcess();
fI64(p.Handle.ToInt64());
fI32(p.HandleCount);
fI32(p.Id);
fI64(p.NonpagedSystemMemorySize64);
fI64(p.PagedMemorySize64);
fI64(p.PagedSystemMemorySize64);
fI64(p.PeakPagedMemorySize64);
fI64(p.PeakVirtualMemorySize64);
fI64(p.PeakWorkingSet64);
fI64(p.PrivateMemorySize64);
fI64(p.StartTime.ToBinary());
fI64(p.VirtualMemorySize64);
fI64(p.WorkingSet64);

// Not supported in Mono 1.2.6:
// fI32(p.SessionId);
#endif
}
catch (Exception) { Debug.Assert(NativeLib.IsUnix()); }
Expand Down Expand Up @@ -381,5 +379,7 @@ public static Random NewWeakRandom()

return new Random(s32);
}

public void Dispose() => m_rng?.Dispose();
}
}
10 changes: 3 additions & 7 deletions KeePassLib/KeePassLib.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net40</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AssemblyOriginatorKeyFile>KeePassLib.pfx</AssemblyOriginatorKeyFile>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.Security" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>

</Project>
Loading