Skip to content

Commit

Permalink
remove dynamic keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
smorks committed Jun 6, 2020
1 parent 381c68f commit 16fea3e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
end_of_line = lf
trim_trailing_whitespace = true
18 changes: 10 additions & 8 deletions KeePassNatMsg/KeePassNatMsg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
</Compile>
<Compile Include="Entry\EntryConfig.cs" />
<Compile Include="ConfigOpt.cs" />
<Compile Include="Options\DatabaseItem.cs" />
<Compile Include="Options\OptionsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Options\OptionsForm.Designer.cs">
<DependentUpon>OptionsForm.cs</DependentUpon>
</Compile>
<Compile Include="Protocol\Listener\SocketReadState.cs" />
<Compile Include="Utils\EnumExtension.cs" />
<Compile Include="NativeMessaging\BrowserSelectForm.cs">
Expand All @@ -78,12 +85,6 @@
<Compile Include="NativeMessaging\NativeMessagingHost.cs" />
<Compile Include="NativeMessaging\PosixHost.cs" />
<Compile Include="NativeMessaging\WindowsHost.cs" />
<Compile Include="OptionsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="OptionsForm.Designer.cs">
<DependentUpon>OptionsForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -129,7 +130,7 @@
<EmbeddedResource Include="NativeMessaging\BrowserSelectForm.resx">
<DependentUpon>BrowserSelectForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="OptionsForm.resx">
<EmbeddedResource Include="Options\OptionsForm.resx">
<DependentUpon>OptionsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
Expand All @@ -140,6 +141,7 @@
<ItemGroup>
<None Include="Resources\earth_lock.png" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -148,4 +150,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
23 changes: 12 additions & 11 deletions KeePassNatMsg/KeePassNatMsgExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
using KeePass.Plugins;
using KeePass.UI;
using KeePass.Util.Spr;
using KeePassNatMsg.Entry;
using KeePassNatMsg.Protocol;
using KeePassNatMsg.Protocol.Action;
using KeePassNatMsg.Protocol.Crypto;
using KeePassNatMsg.Protocol.Listener;
using KeePassLib;
using KeePassLib.Cryptography;
using KeePassLib.Cryptography.PasswordGenerator;
using KeePassLib.Security;
using KeePassLib.Utility;
using KeePassNatMsg.Entry;
using KeePassNatMsg.Options;
using KeePassNatMsg.Protocol;
using KeePassNatMsg.Protocol.Action;
using KeePassNatMsg.Protocol.Crypto;
using KeePassNatMsg.Protocol.Listener;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand Down Expand Up @@ -289,13 +290,13 @@ internal string GetDbHash(PwDatabase db)
return ByteToHexBitFiddle(hashBytes);
}

internal string GetDbHash()
{
return GetDbHash(GetConnectionDatabase());
}
internal string GetDbHash()
{
return GetDbHash(GetConnectionDatabase());
}

// wizard magic courtesy of https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa/14333437#14333437
static string ByteToHexBitFiddle(byte[] bytes)
// wizard magic courtesy of https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa/14333437#14333437
static string ByteToHexBitFiddle(byte[] bytes)
{
char[] c = new char[bytes.Length * 2];
int b;
Expand Down
8 changes: 8 additions & 0 deletions KeePassNatMsg/Options/DatabaseItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace KeePassNatMsg.Options
{
class DatabaseItem
{
public string Id { get; set; }
public string DbHash { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using KeePassNatMsg.NativeMessaging;
using KeePassNatMsg.Utils;
using KeePassLib;
using KeePassLib;
using KeePassLib.Collections;
using KeePassNatMsg.NativeMessaging;
using KeePassNatMsg.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KeePassNatMsg
namespace KeePassNatMsg.Options
{
public partial class OptionsForm : Form
{
Expand Down Expand Up @@ -50,15 +50,15 @@ private void OptionsForm_Load(object sender, EventArgs e)

this.returnStringFieldsCheckbox_CheckedChanged(null, EventArgs.Empty);

InitDatabasesDropdown();
foreach (dynamic item in comboBoxDatabases.Items)
{
if (item.DatabaseHash == _config.ConnectionDatabaseHash)
{
comboBoxDatabases.SelectedItem = item;
}
}
}
InitDatabasesDropdown();
foreach (DatabaseItem item in comboBoxDatabases.Items)
{
if (item.DbHash == _config.ConnectionDatabaseHash)
{
comboBoxDatabases.SelectedItem = item;
}
}
}

private void okButton_Click(object sender, EventArgs e)
{
Expand All @@ -74,9 +74,9 @@ private void okButton_Click(object sender, EventArgs e)
_config.ReturnStringFieldsWithKphOnly = returnStringFieldsWithKphOnlyCheckBox.Checked;
_config.SortResultByUsername = SortByUsernameRadioButton.Checked;
_config.OverrideKeePassXcVersion = txtKPXCVerOverride.Text;
_config.ConnectionDatabaseHash = (comboBoxDatabases.SelectedItem as dynamic)?.DatabaseHash;
_config.ConnectionDatabaseHash = (comboBoxDatabases.SelectedItem as DatabaseItem)?.DbHash;
_config.SearchUrls = chkSearchUrls.Checked;
if (_restartRequired)
{
MessageBox.Show(
Expand Down Expand Up @@ -302,21 +302,21 @@ private void GetNativeMessagingStatus()
lblProxyVersion.Text = string.Join(Environment.NewLine, lst);
}

private void InitDatabasesDropdown()
{
foreach (var item in KeePass.Program.MainForm.DocumentManager.Documents)
{
private void InitDatabasesDropdown()
{
foreach (var item in KeePass.Program.MainForm.DocumentManager.Documents)
{
if (!item.Database.IsOpen)
continue;

var dbIdentifier = item.Database.Name;
if (string.IsNullOrEmpty(dbIdentifier))
{
dbIdentifier = item.Database.IOConnectionInfo.Path;
}

comboBoxDatabases.Items.Add(new { DatabaseIdentifier = dbIdentifier, DatabaseHash = KeePassNatMsgExt.ExtInstance.GetDbHash(item.Database)});
}
}
}
if (string.IsNullOrEmpty(dbIdentifier))
{
dbIdentifier = item.Database.IOConnectionInfo.Path;
}

comboBoxDatabases.Items.Add(new DatabaseItem { Id = dbIdentifier, DbHash = KeePassNatMsgExt.ExtInstance.GetDbHash(item.Database) });
}
}
}
}
File renamed without changes.

0 comments on commit 16fea3e

Please sign in to comment.