Skip to content

Commit 59ae473

Browse files
authored
Feature: Check for Pre-releases (#1574)
* Feature: Check for Pre-releases * Docs: Add #1574
1 parent f1c809b commit 59ae473

File tree

12 files changed

+110
-26
lines changed

12 files changed

+110
-26
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -3221,4 +3221,7 @@ If not set, the default AWS CLI settings are used.</value>
32213221
<data name="AWSSessionManagerPluginIsNotInstalled" xml:space="preserve">
32223222
<value>AWS Session Manager Plugin is not installed!</value>
32233223
</data>
3224+
<data name="CheckForPreReleases" xml:space="preserve">
3225+
<value>Check for pre-releases</value>
3226+
</data>
32243227
</root>

Source/NETworkManager.Settings/SettingsInfo.cs

+15
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,21 @@ public bool Update_CheckForUpdatesAtStartup
417417
}
418418
}
419419

420+
private bool _update_CheckForPreReleases;
421+
public bool Update_CheckForPreReleases
422+
{
423+
get => _update_CheckForPreReleases;
424+
set
425+
{
426+
if (value == _update_CheckForPreReleases)
427+
return;
428+
429+
_update_CheckForPreReleases = value;
430+
OnPropertyChanged();
431+
SettingsChanged = true;
432+
}
433+
}
434+
420435
// Profiles
421436
private string _profiles_CustomProfilesLocation;
422437
public string Profiles_CustomProfilesLocation
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Octokit;
2+
using System;
23

34
namespace NETworkManager.Update
45
{
@@ -8,17 +9,17 @@ namespace NETworkManager.Update
89
public class UpdateAvailableArgs : EventArgs
910
{
1011
/// <summary>
11-
/// Version of the program update.
12+
/// Release of the program update.
1213
/// </summary>
13-
public Version Version { get; private set; }
14+
public Release Release { get; private set; }
1415

1516
/// <summary>
16-
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class and passes the <see cref="Version"/> as paramter.
17+
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class and passes the <see cref="Release"/> as paramter.
1718
/// </summary>
18-
/// <param name="version">Version of the program update.</param>
19-
public UpdateAvailableArgs(Version version)
19+
/// <param name="release">Release of the program update.</param>
20+
public UpdateAvailableArgs(Release release)
2021
{
21-
Version = version;
22+
Release = release;
2223
}
2324
}
2425
}

Source/NETworkManager.Update/Updater.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,24 @@ protected virtual void OnError()
5858
/// <param name="userName">GitHub username like "BornToBeRoot".</param>
5959
/// <param name="projectName">GitHub repository like "NETworkManager".</param>
6060
/// <param name="currentVersion">Version like 1.2.0.0.</param>
61-
public void CheckOnGitHub(string userName, string projectName, Version currentVersion)
61+
public void CheckOnGitHub(string userName, string projectName, Version currentVersion, bool includePreRelease)
6262
{
6363
Task.Run(() =>
6464
{
6565
try
6666
{
6767
var client = new GitHubClient(new ProductHeaderValue(userName + "_" + projectName));
6868

69-
var latestVersion = new Version(client.Repository.Release.GetLatest(userName, projectName).Result.TagName);
69+
Release release = null;
70+
71+
if (includePreRelease)
72+
release = client.Repository.Release.GetAll(userName, projectName).Result[0];
73+
else
74+
release = client.Repository.Release.GetLatest(userName, projectName).Result;
7075

7176
// Compare versions (tag=2021.2.15.0, version=2021.2.15.0)
72-
if (latestVersion > currentVersion)
73-
OnUpdateAvailable(new UpdateAvailableArgs(latestVersion));
77+
if (new Version(release.TagName) > currentVersion)
78+
OnUpdateAvailable(new UpdateAvailableArgs(release));
7479
else
7580
OnNoUpdateAvailable();
7681
}

Source/NETworkManager/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<mah:MetroWindow.RightWindowCommands>
7575
<mah:WindowCommands ShowLastSeparator="False">
7676
<StackPanel Orientation="Horizontal">
77-
<Button Command="{Binding OpenWebsiteCommand}" Opacity="1" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" CommandParameter="{x:Static resources:Resources.NETworkManager_LatestReleaseUrl}" Cursor="Hand">
77+
<Button Command="{Binding OpenWebsiteCommand}" Opacity="1" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Cursor="Hand">
7878
<StackPanel Orientation="Horizontal">
7979
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
8080
<Rectangle.OpacityMask>

Source/NETworkManager/MainWindow.xaml.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ public bool IsUpdateAvailable
254254
}
255255
}
256256

257+
private string _updateReleaseUrl;
258+
public string UpdateReleaseUrl
259+
{
260+
get => _updateReleaseUrl;
261+
set
262+
{
263+
if (value == _updateReleaseUrl)
264+
return;
265+
266+
_updateReleaseUrl = value;
267+
OnPropertyChanged();
268+
}
269+
}
270+
257271
private ICollectionView _profileFiles;
258272
public ICollectionView ProfileFiles
259273
{
@@ -1162,7 +1176,7 @@ private void CheckForUpdates()
11621176

11631177
updater.UpdateAvailable += Updater_UpdateAvailable;
11641178
updater.Error += Updater_Error;
1165-
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version);
1179+
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version, SettingsManager.Current.Update_CheckForPreReleases);
11661180
}
11671181

11681182
private static void Updater_Error(object sender, EventArgs e)
@@ -1172,6 +1186,7 @@ private static void Updater_Error(object sender, EventArgs e)
11721186

11731187
private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
11741188
{
1189+
UpdateReleaseUrl = e.Release.Prerelease ? e.Release.HtmlUrl : Properties.Resources.NETworkManager_LatestReleaseUrl;
11751190
IsUpdateAvailable = true;
11761191
}
11771192
#endregion

Source/NETworkManager/ViewModels/AboutViewModel.cs

+26-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
using NETworkManager.Localization.Resources;
99
using NETworkManager.Utilities;
1010
using NETworkManager.Documentation;
11+
using NETworkManager.Properties;
1112

1213
namespace NETworkManager.ViewModels
1314
{
1415
public class AboutViewModel : ViewModelBase
1516
{
1617
#region Variables
1718
public string Version => $"{Strings.Version} {AssemblyManager.Current.Version}";
18-
public string DevelopedByText => string.Format(Strings.DevelopedAndMaintainedByX + " ", Properties.Resources.NETworkManager_GitHub_User);
19+
public string DevelopedByText => string.Format(Strings.DevelopedAndMaintainedByX + " ", Resources.NETworkManager_GitHub_User);
1920

2021
private bool _isUpdateCheckRunning;
2122
public bool IsUpdateCheckRunning
@@ -31,16 +32,16 @@ public bool IsUpdateCheckRunning
3132
}
3233
}
3334

34-
private bool _updateAvailable;
35-
public bool UpdateAvailable
35+
private bool _isUpdateAvailable;
36+
public bool IsUpdateAvailable
3637
{
37-
get => _updateAvailable;
38+
get => _isUpdateAvailable;
3839
set
3940
{
40-
if (value == _updateAvailable)
41+
if (value == _isUpdateAvailable)
4142
return;
4243

43-
_updateAvailable = value;
44+
_isUpdateAvailable = value;
4445
OnPropertyChanged();
4546
}
4647
}
@@ -59,6 +60,20 @@ public string UpdateText
5960
}
6061
}
6162

63+
private string _updateReleaseUrl;
64+
public string UpdateReleaseUrl
65+
{
66+
get => _updateReleaseUrl;
67+
set
68+
{
69+
if (value == _updateReleaseUrl)
70+
return;
71+
72+
_updateReleaseUrl = value;
73+
OnPropertyChanged();
74+
}
75+
}
76+
6277
private bool _showUpdaterMessage;
6378
public bool ShowUpdaterMessage
6479
{
@@ -186,7 +201,7 @@ private void OpenLicenseFolderAction()
186201
#region Methods
187202
private void CheckForUpdates()
188203
{
189-
UpdateAvailable = false;
204+
IsUpdateAvailable = false;
190205
ShowUpdaterMessage = false;
191206

192207
IsUpdateCheckRunning = true;
@@ -197,17 +212,18 @@ private void CheckForUpdates()
197212
updater.NoUpdateAvailable += Updater_NoUpdateAvailable;
198213
updater.Error += Updater_Error;
199214

200-
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version);
215+
updater.CheckOnGitHub(Resources.NETworkManager_GitHub_User, Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version, SettingsManager.Current.Update_CheckForPreReleases);
201216
}
202217
#endregion
203218

204219
#region Events
205220
private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
206221
{
207-
UpdateText = string.Format(Strings.VersionxxIsAvailable, e.Version);
222+
UpdateText = string.Format(Strings.VersionxxIsAvailable, e.Release.TagName);
223+
UpdateReleaseUrl = e.Release.Prerelease ? e.Release.HtmlUrl : Resources.NETworkManager_LatestReleaseUrl;
208224

209225
IsUpdateCheckRunning = false;
210-
UpdateAvailable = true;
226+
IsUpdateAvailable = true;
211227
}
212228

213229
private void Updater_NoUpdateAvailable(object sender, EventArgs e)

Source/NETworkManager/ViewModels/SettingsUpdateViewModel.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NETworkManager.Settings;
2-
using NETworkManager.Utilities;
32

43
namespace NETworkManager.ViewModels
54
{
@@ -24,6 +23,23 @@ public bool CheckForUpdatesAtStartup
2423
OnPropertyChanged();
2524
}
2625
}
26+
27+
private bool _checkForPreReleases;
28+
public bool CheckForPreReleases
29+
{
30+
get => _checkForPreReleases;
31+
set
32+
{
33+
if (value == _checkForPreReleases)
34+
return;
35+
36+
if (!_isLoading)
37+
SettingsManager.Current.Update_CheckForPreReleases = value;
38+
39+
_checkForPreReleases = value;
40+
OnPropertyChanged();
41+
}
42+
}
2743
#endregion
2844

2945
#region Constructor, LoadSettings
@@ -39,6 +55,7 @@ public SettingsUpdateViewModel()
3955
private void LoadSettings()
4056
{
4157
CheckForUpdatesAtStartup = SettingsManager.Current.Update_CheckForUpdatesAtStartup;
58+
CheckForPreReleases = SettingsManager.Current.Update_CheckForPreReleases;
4259
}
4360
#endregion
4461
}

Source/NETworkManager/Views/AboutView.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@
155155
<ColumnDefinition Width="*" />
156156
</Grid.ColumnDefinitions>
157157
<Button Grid.Column="0" x:Name="ButtonCheckForUpdates" HorizontalAlignment="Left" Command="{Binding CheckForUpdatesCommand}" IsEnabled="{Binding IsUpdateCheckRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource DefaultButton}" Content="{x:Static localization:Strings.CheckForUpdates}" />
158-
<StackPanel Grid.Column="2" Orientation="Horizontal" Visibility="{Binding UpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}">
158+
<StackPanel Grid.Column="2" Orientation="Horizontal" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}">
159159
<StackPanel.InputBindings>
160-
<MouseBinding Gesture="LeftClick" Command="{Binding OpenWebsiteCommand}" CommandParameter="{x:Static resources:Resources.NETworkManager_LatestReleaseUrl}" />
160+
<MouseBinding Gesture="LeftClick" Command="{Binding OpenWebsiteCommand}" CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
161161
</StackPanel.InputBindings>
162162
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
163163
<Rectangle.OpacityMask>

Source/NETworkManager/Views/SettingsUpdateView.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
</Rectangle.Resources>
1818
</Rectangle>
1919
</StackPanel>
20+
<mahAppsControls:ToggleSwitch Header="{x:Static localization:Strings.CheckForPreReleases}" IsOn="{Binding CheckForPreReleases}" />
2021
</StackPanel>
2122
</UserControl>

docs/Changelog/next-release.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ permalink: /Changelog/next-release
3030
- Detect if PuTTY is installed at first run [#1542](https://github.com/BornToBeRoot/NETworkManager/pull/1542){:target="\_blank"}
3131
- Discovery Protocol
3232
- Add local connection & local interface to output [#1533](https://github.com/BornToBeRoot/NETworkManager/pull/1533){:target="\_blank"}
33+
- Settings > Update
34+
- Option to check for pre-releases added [#1574](https://github.com/BornToBeRoot/NETworkManager/pull/1574){:target="\_blank"}
3335
- Profiles > Group Dialog
3436
- Remove checkboxes in group dialog [#1530](https://github.com/BornToBeRoot/NETworkManager/pull/1530){:target="\_blank"}
3537
- log4net added for error handling (Log file: `%LocalAppData%\NETworkManager\NETworkManager.log`) [#1539](https://github.com/BornToBeRoot/NETworkManager/pull/1539){:target="\_blank"}

0 commit comments

Comments
 (0)