Skip to content

Commit acdf44e

Browse files
authored
Merge pull request #5213 from retailcoder/versioncheck
Versioncheck tweaks and accidental fix for xml-doc analyzer
2 parents 9439c65 + a4b574a commit acdf44e

File tree

12 files changed

+216
-71
lines changed

12 files changed

+216
-71
lines changed

Rubberduck.Core/Settings/GeneralSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IGeneralSettings
1313
DisplayLanguageSetting Language { get; set; }
1414
bool CanShowSplash { get; set; }
1515
bool CanCheckVersion { get; set; }
16+
bool IncludePreRelease { get; set; }
1617
bool CompileBeforeParse { get; set; }
1718
bool IsSmartIndenterPrompted { get; set; }
1819
bool IsAutoSaveEnabled { get; set; }
@@ -43,6 +44,7 @@ public DisplayLanguageSetting Language
4344

4445
public bool CanShowSplash { get; set; }
4546
public bool CanCheckVersion { get; set; }
47+
public bool IncludePreRelease { get; set; }
4648
public bool CompileBeforeParse { get; set; }
4749
public bool IsSmartIndenterPrompted { get; set; }
4850
public bool IsAutoSaveEnabled { get; set; }
@@ -89,6 +91,7 @@ public bool Equals(GeneralSettings other)
8991
Language.Equals(other.Language) &&
9092
CanShowSplash == other.CanShowSplash &&
9193
CanCheckVersion == other.CanCheckVersion &&
94+
IncludePreRelease == other.IncludePreRelease &&
9295
CompileBeforeParse == other.CompileBeforeParse &&
9396
IsSmartIndenterPrompted == other.IsSmartIndenterPrompted &&
9497
IsAutoSaveEnabled == other.IsAutoSaveEnabled &&

Rubberduck.Core/UI/Command/VersionCheckCommand.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Rubberduck.Interaction;
44
using Rubberduck.VersionCheck;
55
using Rubberduck.Resources;
6+
using Rubberduck.SettingsProvider;
7+
using Rubberduck.Settings;
68

79
namespace Rubberduck.UI.Command
810
{
@@ -28,37 +30,46 @@ public class VersionCheckCommand : CommandBase
2830
private readonly IVersionCheck _versionCheck;
2931
private readonly IMessageBox _prompt;
3032
private readonly IExternalProcess _process;
33+
IConfigurationService<Configuration> _config;
3134

32-
public VersionCheckCommand(IVersionCheck versionCheck, IMessageBox prompt, IExternalProcess process)
35+
public VersionCheckCommand(IVersionCheck versionCheck, IMessageBox prompt, IExternalProcess process, IConfigurationService<Configuration> config)
3336
{
3437
_versionCheck = versionCheck;
3538
_prompt = prompt;
3639
_process = process;
40+
_config = config;
3741
}
3842

3943
protected override async void OnExecute(object parameter)
4044
{
41-
Logger.Info("Executing version check.");
45+
var settings = _config.Read().UserSettings.GeneralSettings;
46+
Logger.Info("Executing version check...");
4247
await _versionCheck
43-
.GetLatestVersionAsync()
48+
.GetLatestVersionAsync(settings)
4449
.ContinueWith(t =>
4550
{
4651
if (_versionCheck.CurrentVersion < t.Result)
4752
{
48-
PromptAndBrowse(t.Result);
53+
PromptAndBrowse(t.Result, settings.IncludePreRelease);
4954
}
5055
});
5156
}
5257

53-
private void PromptAndBrowse(Version latestVersion)
58+
private void PromptAndBrowse(Version latestVersion, bool includePreRelease)
5459
{
55-
var prompt = string.Format(RubberduckUI.VersionCheck_NewVersionAvailable, latestVersion);
60+
var buildType = includePreRelease
61+
? RubberduckUI.VersionCheck_BuildType_PreRelease
62+
: RubberduckUI.VersionCheck_BuildType_Release;
63+
var prompt = string.Format(RubberduckUI.VersionCheck_NewVersionAvailable, _versionCheck.CurrentVersion, latestVersion, buildType);
5664
if (!_prompt.Question(prompt, RubberduckUI.Rubberduck))
5765
{
5866
return;
5967
}
6068

61-
_process.Start("https://github.com/rubberduck-vba/Rubberduck/releases/latest");
69+
var url = includePreRelease
70+
? "https://github.com/rubberduck-vba/Rubberduck/releases"
71+
: "https://github.com/rubberduck-vba/Rubberduck/releases/latest";
72+
_process.Start(url);
6273
}
6374
}
6475
}

Rubberduck.Core/UI/Settings/GeneralSettings.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@
128128
IsChecked="{Binding ShowSplashAtStartup}" />
129129

130130
<CheckBox Margin="5,0,0,5" Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_CheckVersion}"
131-
IsChecked="{Binding CheckVersionAtStartup}" />
131+
IsChecked="{Binding CheckVersionAtStartup}"
132+
x:Name="IsVersionCheckEnabled"/>
133+
<CheckBox Margin="15,0,0,5" Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_IncludePreRelease}"
134+
IsChecked="{Binding IncludePreRelease}"
135+
IsEnabled="{Binding IsChecked, ElementName=IsVersionCheckEnabled}"/>
136+
132137
<CheckBox Margin="5,0,0,5" Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_CompileBeforeParse}"
133138
IsChecked="{Binding CompileBeforeParse}" />
134139
<CheckBox Margin="5,0,0,5" Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_SetDpiUnaware}"

Rubberduck.Core/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ public bool CheckVersionAtStartup
158158
}
159159
}
160160

161+
private bool _includePreRelease;
162+
public bool IncludePreRelease
163+
{
164+
get => _includePreRelease;
165+
set
166+
{
167+
if (_includePreRelease != value)
168+
{
169+
_includePreRelease = value;
170+
OnPropertyChanged();
171+
}
172+
}
173+
}
174+
161175
private bool _compileBeforeParse;
162176
public bool CompileBeforeParse
163177
{
@@ -289,6 +303,7 @@ private Rubberduck.Settings.GeneralSettings GetCurrentGeneralSettings()
289303
Language = SelectedLanguage,
290304
CanShowSplash = ShowSplashAtStartup,
291305
CanCheckVersion = CheckVersionAtStartup,
306+
IncludePreRelease = IncludePreRelease,
292307
CompileBeforeParse = CompileBeforeParse,
293308
SetDpiUnaware = SetDpiUnaware,
294309
IsSmartIndenterPrompted = _indenterPrompted,
@@ -314,6 +329,7 @@ private void TransferSettingsToView(IGeneralSettings general, IHotkeySettings ho
314329
: new ObservableViewModelCollection<HotkeySettingViewModel>(hotkey.Settings.Select(data => new HotkeySettingViewModel(data)));
315330
ShowSplashAtStartup = general.CanShowSplash;
316331
CheckVersionAtStartup = general.CanCheckVersion;
332+
IncludePreRelease = general.IncludePreRelease;
317333
CompileBeforeParse = general.CompileBeforeParse;
318334
SetDpiUnaware = general.SetDpiUnaware;
319335
_indenterPrompted = general.IsSmartIndenterPrompted;
@@ -376,56 +392,4 @@ protected override void ExportSettings(Rubberduck.Settings.GeneralSettings setti
376392
}
377393
}
378394
}
379-
380-
public class HotkeySettingViewModel : ViewModelBase
381-
{
382-
private readonly HotkeySetting wrapped;
383-
384-
public HotkeySettingViewModel(HotkeySetting wrapped)
385-
{
386-
this.wrapped = wrapped;
387-
}
388-
389-
public HotkeySetting Unwrap() { return wrapped; }
390-
391-
public string Key1
392-
{
393-
get { return wrapped.Key1; }
394-
set { wrapped.Key1 = value; OnPropertyChanged(); }
395-
}
396-
397-
public bool IsEnabled
398-
{
399-
get { return wrapped.IsEnabled; }
400-
set { wrapped.IsEnabled = value; OnPropertyChanged(); }
401-
}
402-
403-
public bool HasShiftModifier
404-
{
405-
get { return wrapped.HasShiftModifier; }
406-
set { wrapped.HasShiftModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
407-
}
408-
409-
public bool HasAltModifier
410-
{
411-
get { return wrapped.HasAltModifier; }
412-
set { wrapped.HasAltModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
413-
}
414-
415-
public bool HasCtrlModifier
416-
{
417-
get { return wrapped.HasCtrlModifier; }
418-
set { wrapped.HasCtrlModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
419-
}
420-
421-
public string CommandTypeName
422-
{
423-
get { return wrapped.CommandTypeName; }
424-
set { wrapped.CommandTypeName = value; OnPropertyChanged(); }
425-
}
426-
427-
public bool IsValid { get { return wrapped.IsValid; } }
428-
// FIXME If this is the only use, the property should be inlined to here
429-
public string Prompt { get { return wrapped.Prompt; } }
430-
}
431395
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Rubberduck.Settings;
2+
3+
namespace Rubberduck.UI.Settings
4+
{
5+
public class HotkeySettingViewModel : ViewModelBase
6+
{
7+
private readonly HotkeySetting wrapped;
8+
9+
public HotkeySettingViewModel(HotkeySetting wrapped)
10+
{
11+
this.wrapped = wrapped;
12+
}
13+
14+
public HotkeySetting Unwrap() { return wrapped; }
15+
16+
public string Key1
17+
{
18+
get { return wrapped.Key1; }
19+
set { wrapped.Key1 = value; OnPropertyChanged(); }
20+
}
21+
22+
public bool IsEnabled
23+
{
24+
get { return wrapped.IsEnabled; }
25+
set { wrapped.IsEnabled = value; OnPropertyChanged(); }
26+
}
27+
28+
public bool HasShiftModifier
29+
{
30+
get { return wrapped.HasShiftModifier; }
31+
set { wrapped.HasShiftModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
32+
}
33+
34+
public bool HasAltModifier
35+
{
36+
get { return wrapped.HasAltModifier; }
37+
set { wrapped.HasAltModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
38+
}
39+
40+
public bool HasCtrlModifier
41+
{
42+
get { return wrapped.HasCtrlModifier; }
43+
set { wrapped.HasCtrlModifier = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsValid)); }
44+
}
45+
46+
public string CommandTypeName
47+
{
48+
get { return wrapped.CommandTypeName; }
49+
set { wrapped.CommandTypeName = value; OnPropertyChanged(); }
50+
}
51+
52+
public bool IsValid { get { return wrapped.IsValid; } }
53+
// FIXME If this is the only use, the property should be inlined to here
54+
public string Prompt { get { return wrapped.Prompt; } }
55+
}
56+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
1+
using Rubberduck.Settings;
2+
using System;
23
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace Rubberduck.VersionCheck
67
{
78
public interface IVersionCheck
89
{
9-
Task<Version> GetLatestVersionAsync(CancellationToken token = default);
10+
Task<Version> GetLatestVersionAsync(GeneralSettings settings, CancellationToken token = default);
1011
Version CurrentVersion { get; }
1112
}
1213
}

Rubberduck.Core/VersionCheck/VersionCheck.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using Rubberduck.Settings;
2+
using Rubberduck.SettingsProvider;
3+
using System;
24
using System.Linq;
35
using System.Net.Http;
46
using System.Threading;
@@ -12,19 +14,22 @@ public class VersionCheck : IVersionCheck
1214
/// <param name="version">That would be the version of the assembly for the <c>_Extension</c> class.</param>
1315
public VersionCheck(Version version)
1416
{
15-
_currentVersion = version;
17+
_currentVersion = version;
1618
}
1719

1820
private Version _latestVersion;
19-
public async Task<Version> GetLatestVersionAsync(CancellationToken token = default)
21+
public async Task<Version> GetLatestVersionAsync(GeneralSettings settings, CancellationToken token = default)
2022
{
2123
if (_latestVersion != default) { return _latestVersion; }
2224

2325
try
2426
{
27+
var url = settings.IncludePreRelease
28+
? new Uri("http://rubberduckvba.com/build/version/prerelease")
29+
: new Uri("http://rubberduckvba.com/build/version/stable");
30+
2531
using (var client = new HttpClient())
2632
{
27-
var url = new Uri("http://rubberduckvba.com/Build/Version/Stable");
2833
var response = await client.GetAsync(url, token);
2934
var content = await response.Content.ReadAsStringAsync();
3035
var doc = new HtmlAgilityPack.HtmlDocument();

Rubberduck.Resources/RubberduckUI.Designer.cs

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

0 commit comments

Comments
 (0)