Skip to content

Commit 8891894

Browse files
committed
Rework Update checker
1 parent 76e32f8 commit 8891894

15 files changed

Lines changed: 219 additions & 51 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![license](https://img.shields.io/github/license/bitbeans/SimpleDnsCrypt.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/blob/master/LICENSE.md) [![Build status](https://img.shields.io/appveyor/ci/bitbeans/simplednscrypt/master.svg?style=flat-square)](https://ci.appveyor.com/project/bitbeans/simplednscrypt/branch/master) [![Github All Releases](https://img.shields.io/github/release/bitbeans/SimpleDnsCrypt.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/releases/latest) [![dnscrypt--proxy](https://img.shields.io/badge/dnscrypt--proxy-2.0.0rc2-orange.svg?style=flat-square)](https://github.com/jedisct1/dnscrypt-proxy) [![Github All Releases](https://img.shields.io/github/downloads/bitbeans/SimpleDnsCrypt/total.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/releases/latest) [![donate PayPal](https://img.shields.io/badge/donate-PayPal-green.svg?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=c.hermann@bitbeans.de&item_name=Donation+to+the+Simple+DNSCrypt+project) [![donate pledgie](https://img.shields.io/badge/donate-pledgie-green.svg?style=flat-square)](https://pledgie.com/campaigns/32588)
1+
[![license](https://img.shields.io/github/license/bitbeans/SimpleDnsCrypt.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/blob/master/LICENSE.md) [![Build status](https://img.shields.io/appveyor/ci/bitbeans/simplednscrypt/master.svg?style=flat-square)](https://ci.appveyor.com/project/bitbeans/simplednscrypt/branch/master) [![Github All Releases](https://img.shields.io/github/release/bitbeans/SimpleDnsCrypt.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/releases/latest) [![dnscrypt--proxy](https://img.shields.io/badge/dnscrypt--proxy-2.0.0-orange.svg?style=flat-square)](https://github.com/jedisct1/dnscrypt-proxy) [![Github All Releases](https://img.shields.io/github/downloads/bitbeans/SimpleDnsCrypt/total.svg?style=flat-square)](https://github.com/bitbeans/SimpleDnsCrypt/releases/latest) [![donate PayPal](https://img.shields.io/badge/donate-PayPal-green.svg?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=c.hermann@bitbeans.de&item_name=Donation+to+the+Simple+DNSCrypt+project) [![donate pledgie](https://img.shields.io/badge/donate-pledgie-green.svg?style=flat-square)](https://pledgie.com/campaigns/32588)
22

33
# ![Simple DNSCrypt](https://raw.githubusercontent.com/bitbeans/SimpleDnsCrypt/master/img/icons/256x256.png)
44

SimpleDnsCrypt/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
<setting name="PreferredLanguage" serializeAs="String">
4848
<value />
4949
</setting>
50+
<setting name="MinUpdateType" serializeAs="String">
51+
<value>2</value>
52+
</setting>
53+
<setting name="AutoUpdate" serializeAs="String">
54+
<value>True</value>
55+
</setting>
5056
</SimpleDnsCrypt.Properties.Settings>
5157
</userSettings>
5258
</configuration>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using SimpleDnsCrypt.Helper;
2+
using SimpleDnsCrypt.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Globalization;
6+
using System.Windows.Data;
7+
using System.Windows.Markup;
8+
9+
namespace SimpleDnsCrypt.Converters
10+
{
11+
[ValueConversion(typeof(Enum), typeof(IEnumerable<ValueDescription>))]
12+
public class EnumToCollectionConverter : MarkupExtension, IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
return EnumHelper.GetAllValuesAndDescriptions(value.GetType());
17+
}
18+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
{
20+
return null;
21+
}
22+
public override object ProvideValue(IServiceProvider serviceProvider)
23+
{
24+
return this;
25+
}
26+
}
27+
}

SimpleDnsCrypt/Helper/ApplicationUpdater.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ public static class ApplicationUpdater
1717
{
1818
private static readonly ILog Log = LogManagerHelper.Factory();
1919

20-
public static async Task<RemoteUpdate> CheckForRemoteUpdateAsync()
20+
/// <summary>
21+
/// Check for a new version on the remote server (github.com).
22+
/// </summary>
23+
/// <param name="minUpdateType"></param>
24+
/// <returns></returns>
25+
public static async Task<RemoteUpdate> CheckForRemoteUpdateAsync(UpdateType minUpdateType = UpdateType.Stable)
2126
{
2227
var remoteUpdate = new RemoteUpdate();
2328
try
@@ -56,7 +61,14 @@ public static async Task<RemoteUpdate> CheckForRemoteUpdateAsync()
5661
else
5762
{
5863
// the remote version is newer as the local version
59-
remoteUpdate.CanUpdate = true;
64+
if ((int)remoteUpdate.Update.Type >= (int)minUpdateType)
65+
{
66+
remoteUpdate.CanUpdate = true;
67+
}
68+
else
69+
{
70+
remoteUpdate.CanUpdate = false;
71+
}
6072
}
6173
}
6274
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using SimpleDnsCrypt.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Globalization;
6+
using System.Linq;
7+
8+
namespace SimpleDnsCrypt.Helper
9+
{
10+
public static class EnumHelper
11+
{
12+
public static string Description(this Enum eValue)
13+
{
14+
var nAttributes = eValue.GetType().GetField(eValue.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
15+
if (nAttributes.Any())
16+
return (nAttributes.First() as DescriptionAttribute).Description;
17+
18+
var oTi = CultureInfo.CurrentCulture.TextInfo;
19+
return oTi.ToTitleCase(oTi.ToLower(eValue.ToString()));
20+
}
21+
22+
public static IEnumerable<ValueDescription> GetAllValuesAndDescriptions(Type t)
23+
{
24+
if (!t.IsEnum)
25+
throw new ArgumentException("t must be an enum type");
26+
27+
return Enum.GetValues(t).Cast<Enum>().Select((e) => new ValueDescription() { Value = e, Description = e.Description() }).ToList();
28+
}
29+
}
30+
}

SimpleDnsCrypt/Models/RemoteUpdate.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using YamlDotNet.Core;
3-
using YamlDotNet.RepresentationModel;
4-
using YamlDotNet.Serialization;
5-
using YamlDotNet.Serialization.NodeTypeResolvers;
2+
using System.ComponentModel;
63
using Version = System.Version;
74

85
namespace SimpleDnsCrypt.Models
@@ -29,14 +26,22 @@ public class RemoteUpdate
2926
public enum UpdateType
3027
{
3128
/// <summary>
32-
/// A regular update.
29+
/// A critical update, which should be done as soon as possible.
3330
/// </summary>
34-
Standard = 0,
31+
[Description("Critical")]
32+
Critical = 0,
3533

3634
/// <summary>
37-
/// A critical update, which should be done as soon as possible.
35+
/// A stable update.
36+
/// </summary>
37+
[Description("Stable")]
38+
Stable = 1,
39+
40+
/// <summary>
41+
/// A preview version.
3842
/// </summary>
39-
Critical = 1
43+
[Description("Preview")]
44+
Preview = 2
4045
}
4146

4247
/// <summary>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SimpleDnsCrypt.Models
2+
{
3+
public class ValueDescription
4+
{
5+
public object Description { get; set; }
6+
public object Value { get; set; }
7+
}
8+
}

SimpleDnsCrypt/Properties/Settings.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SimpleDnsCrypt/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@
2323
<Setting Name="PreferredLanguage" Type="System.String" Scope="User">
2424
<Value Profile="(Default)" />
2525
</Setting>
26+
<Setting Name="MinUpdateType" Type="System.Int32" Scope="User">
27+
<Value Profile="(Default)">2</Value>
28+
</Setting>
29+
<Setting Name="AutoUpdate" Type="System.Boolean" Scope="User">
30+
<Value Profile="(Default)">True</Value>
31+
</Setting>
2632
</Settings>
2733
</SettingsFile>

SimpleDnsCrypt/SimpleDnsCrypt.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<Compile Include="Converters\BoolToTextConverter.cs" />
138138
<Compile Include="Converters\BoolToVisibilityConverter.cs" />
139139
<Compile Include="Converters\BoolToVisibilityCollapsedConverter.cs" />
140+
<Compile Include="Converters\EnumToCollectionConverter.cs" />
140141
<Compile Include="Converters\IntegerBoolToVisibilityConverter.cs" />
141142
<Compile Include="Converters\IntegerToBoolConverter.cs" />
142143
<Compile Include="Converters\IntegerToVisibilityConverter.cs" />
@@ -156,6 +157,7 @@
156157
<Compile Include="Helper\AuthenticodeTools.cs" />
157158
<Compile Include="Helper\DnscryptProxyConfigurationManager.cs" />
158159
<Compile Include="Helper\DnsCryptProxyManager.cs" />
160+
<Compile Include="Helper\EnumHelper.cs" />
159161
<Compile Include="Helper\LocalizationEx.cs" />
160162
<Compile Include="Helper\LocalNetworkInterfaceManager.cs" />
161163
<Compile Include="Helper\LogManagerHelper.cs" />
@@ -178,6 +180,7 @@
178180
<Compile Include="Models\QueryLogLineType.cs" />
179181
<Compile Include="Models\RemoteUpdate.cs" />
180182
<Compile Include="Models\Stamp.cs" />
183+
<Compile Include="Models\ValueDescription.cs" />
181184
<Compile Include="Resources\Translation.Designer.cs">
182185
<AutoGen>True</AutoGen>
183186
<DesignTime>True</DesignTime>

0 commit comments

Comments
 (0)