Skip to content

Commit

Permalink
Restore compatibility with Mono
Browse files Browse the repository at this point in the history
Lower required .NET framework from 4.5 to 4.0
This will make the plugin usable on Mono

closes #27
  • Loading branch information
Rookiestyle committed Oct 18, 2020
1 parent 95ca6de commit 0ac4460
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
24 changes: 20 additions & 4 deletions src/KeePassOTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,16 @@ private void SetSeed(ProtectedString value)
}
}

private async void SetURL(string url)
/// Calculate time offset for all relevant entries
/// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono
/// Mono reports .NET 4.0.3 being installed despite higher versions can be used
/// This results in KeePass refusing to compile the plgx
private /* async */ void SetURL(string url)
{
m_url = url == null ? string.Empty : url;
await System.Threading.Tasks.Task.Run(() =>
//await - Don't use, see comment above method definition
System.Threading.Tasks.Task.Factory.StartNew(() =>
//System.Threading.Tasks.Task.Run(() =>
{
OTPTimeCorrection = GetTimeCorrection(url);
}
Expand Down Expand Up @@ -559,12 +565,20 @@ private static TimeSpan GetTimeCorrection(string value)
return timeCorrection;
}

public static async void GetTimingsAsync(KeePassLib.PwDatabase db)
/// Calculate time offset for all relevant entries
/// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono
/// Mono reports .NET 4.0.3 being installed despite higher versions can be used
/// This results in KeePass refusing to compile the plgx
public static /*async*/ void GetTimingsAsync(KeePassLib.PwDatabase db)
{
//Don't use TraverseTree as db content might change during processing
//and this will result in an exception since TraverseTree uses 'foreach'
await System.Threading.Tasks.Task.Run(() =>

//await - Don't use, see comment above method definition
System.Threading.Tasks.Task.Factory.StartNew(() =>
//System.Threading.Tasks.Task.Run(() =>
{
DateTime dtStart = DateTime.Now;
IEnumerable<string> lURL = db.RootGroup.GetEntries(true).
Where(e => OTPDAO.OTPDefined(e) != OTPDAO.OTPDefinition.None). //We're not interested in sites without OTP being set up
Select(e => e.Strings.ReadSafe(KeePassLib.PwDefs.UrlField)).Distinct(); //We're not interested in duplicate URLs
Expand All @@ -574,6 +588,8 @@ await System.Threading.Tasks.Task.Run(() =>
GetTimeCorrection(url);
System.Threading.Thread.Sleep(100);
};
DateTime dtEnd = DateTime.Now;
PluginDebug.AddInfo("Calculated OTP time corrections", 0, "Start: " + dtStart.ToLongTimeString(), "End: " + dtEnd.ToLongTimeString());
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/KeePassOTP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KeePassOTP</RootNamespace>
<AssemblyName>KeePassOTP</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>
</TargetFrameworkSubset>
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.18.1")]
[assembly: AssemblyFileVersion("0.18.1")]
[assembly: AssemblyVersion("0.18.2")]
[assembly: AssemblyFileVersion("0.18.2")]
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
KeePassOTP:0.18.1
KeePassOTP:0.18.2
KeePassOTP!de:11
KeePassOTP!fr:3
:

0 comments on commit 0ac4460

Please sign in to comment.