Skip to content

Commit aa5a2c9

Browse files
committed
App crash fixed, if updater has no network connection
1 parent 66a91c6 commit aa5a2c9

6 files changed

Lines changed: 69 additions & 22 deletions

File tree

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ protected override void OnContentRendered(EventArgs e)
308308

309309
// Chech for updates...
310310
if (SettingsManager.Current.Update_CheckForUpdatesAtStartup)
311-
CheckForUpdates();
311+
CheckForUpdates();
312312
}
313313

314314
private void LoadApplicationList()
315315
{
316316
_applications = CollectionViewSource.GetDefaultView(ApplicationViewManager.List);
317-
317+
318318
Applications.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); // Always have the same order, even if it is translated
319319
Applications.Filter = o =>
320320
{
@@ -570,10 +570,15 @@ private void CheckForUpdates()
570570
Updater updater = new Updater();
571571

572572
updater.UpdateAvailable += Updater_UpdateAvailable;
573-
573+
updater.Error += Updater_Error;
574574
updater.Check();
575575
}
576576

577+
private void Updater_Error(object sender, EventArgs e)
578+
{
579+
// Log
580+
}
581+
577582
private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
578583
{
579584
UpdateText = string.Format(System.Windows.Application.Current.Resources["String_VersionxxAvailable"] as string, e.Version);

Source/NETworkManager/Models/Update/Updater.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,38 @@ protected virtual void OnNoUpdateAvailable()
2222
{
2323
NoUpdateAvailable?.Invoke(this, EventArgs.Empty);
2424
}
25+
26+
public event EventHandler Error;
27+
28+
protected virtual void OnError()
29+
{
30+
Error?.Invoke(this, EventArgs.Empty);
31+
}
2532
#endregion
2633

2734
#region Methods
2835
public void Check()
2936
{
3037
Task.Run(() =>
3138
{
32-
GitHubClient client = new GitHubClient(new ProductHeaderValue(Resources.NETworkManager_ProjectName));
39+
try
40+
{
41+
GitHubClient client = new GitHubClient(new ProductHeaderValue(Resources.NETworkManager_ProjectName));
42+
43+
Task<Release> latestRelease = client.Repository.Release.GetLatest(Resources.NETworkManager_GitHub_User, Resources.NETworkManager_GitHub_Repo);
3344

34-
Task<Release> latestRelease = client.Repository.Release.GetLatest(Resources.NETworkManager_GitHub_User, Resources.NETworkManager_GitHub_Repo);
35-
36-
Version latestVersion = new Version(latestRelease.Result.TagName.TrimStart('v'));
45+
Version latestVersion = new Version(latestRelease.Result.TagName.TrimStart('v'));
3746

38-
// Compare versions (tag=v1.4.2.0, version=1.4.2.0)
39-
if (latestVersion > AssemblyManager.Current.Version)
40-
OnUpdateAvailable(new UpdateAvailableArgs(latestVersion));
41-
else
42-
OnNoUpdateAvailable();
47+
// Compare versions (tag=v1.4.2.0, version=1.4.2.0)
48+
if (latestVersion > AssemblyManager.Current.Version)
49+
OnUpdateAvailable(new UpdateAvailableArgs(latestVersion));
50+
else
51+
OnNoUpdateAvailable();
52+
}
53+
catch
54+
{
55+
OnError();
56+
}
4357
});
4458
}
4559
#endregion

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
<system:String x:Key="String_NoUpdateAvailable">Kein Update verfügbar!</system:String>
359359
<system:String x:Key="String_InstallRDP8dot1Message">Sie müssen das Remotedesktopprotokoll (RDP) Version 8.1 auf Ihrem System installieren, um die Remotedesktopfunktionalität zu verwenden.</system:String>
360360
<system:String x:Key="String_TheProcessCanTakeUpSomeTimeAndResources">Der Vorgang kann einige Zeit und Ressourcen in Anspruch nehmen (CPU / RAM).</system:String>
361+
<system:String x:Key="String_ErrorCheckingApiGithubComVerifyYourNetworkConnection">Fehler beim Überprüfen von 'api.github.com', überprüfen Sie Ihre Netzwerkverbindung!</system:String>
361362

362363
<!-- Documentation title -->
363364
<system:String x:Key="String_DocumentationTitle_00001">Wie installiere ich RDP 8.1 unter Windows 7 / Server 2008 R2?</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
<system:String x:Key="String_NoUpdateAvailable">No update available!</system:String>
359359
<system:String x:Key="String_InstallRDP8dot1Message">You must install the Remote Desktop Protocol (RDP) version 8.1 on your system to use the Remote Desktop functionality!</system:String>
360360
<system:String x:Key="String_TheProcessCanTakeUpSomeTimeAndResources">The process can take up some time and resources (CPU / RAM).</system:String>
361+
<system:String x:Key="String_ErrorCheckingApiGithubComVerifyYourNetworkConnection">Error checking 'api.github.com', check your network connection!</system:String>
361362

362363
<!-- Documentation title -->
363364
<system:String x:Key="String_DocumentationTitle_00001">How to install RDP 8.1 on Windows 7/Server 2008 R2?</system:String>

Source/NETworkManager/ViewModels/Settings/AboutViewModel.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Windows;
55
using NETworkManager.Models.Update;
6+
using System;
67

78
namespace NETworkManager.ViewModels.Settings
89
{
@@ -94,16 +95,30 @@ public string UpdateText
9495
}
9596
}
9697

97-
private bool _noUpdateAvailable;
98-
public bool NoUpdateAvailable
98+
private bool _showUpdaterMessage;
99+
public bool ShowUpdaterMessage
99100
{
100-
get { return _noUpdateAvailable; }
101+
get { return _showUpdaterMessage; }
101102
set
102103
{
103-
if (value == _noUpdateAvailable)
104+
if (value == _showUpdaterMessage)
104105
return;
105106

106-
_noUpdateAvailable = value;
107+
_showUpdaterMessage = value;
108+
OnPropertyChanged();
109+
}
110+
}
111+
112+
private string _updaterMessage;
113+
public string UpdaterMessage
114+
{
115+
get { return _updaterMessage; }
116+
set
117+
{
118+
if (value == _updaterMessage)
119+
return;
120+
121+
_updaterMessage = value;
107122
OnPropertyChanged();
108123
}
109124
}
@@ -143,14 +158,15 @@ private void OpenWebsiteAction(object url)
143158
private void CheckForUpdates()
144159
{
145160
UpdateAvailable = false;
146-
NoUpdateAvailable = false;
161+
ShowUpdaterMessage = false;
147162

148163
IsUpdateCheckRunning = true;
149164

150165
Updater updater = new Updater();
151166

152167
updater.UpdateAvailable += Updater_UpdateAvailable;
153168
updater.NoUpdateAvailable += Updater_NoUpdateAvailable;
169+
updater.Error += Updater_Error;
154170

155171
updater.Check();
156172
}
@@ -161,14 +177,24 @@ private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
161177
{
162178
UpdateText = string.Format(Application.Current.Resources["String_VersionxxAvailable"] as string, e.Version);
163179

164-
IsUpdateCheckRunning = false;
165-
UpdateAvailable = true;
180+
IsUpdateCheckRunning = false;
181+
UpdateAvailable = true;
166182
}
167183

168184
private void Updater_NoUpdateAvailable(object sender, System.EventArgs e)
169185
{
186+
UpdaterMessage = Application.Current.Resources["String_NoUpdateAvailable"] as string;
187+
188+
IsUpdateCheckRunning = false;
189+
ShowUpdaterMessage = true;
190+
}
191+
192+
private void Updater_Error(object sender, EventArgs e)
193+
{
194+
UpdaterMessage = Application.Current.Resources["String_ErrorCheckingApiGithubComVerifyYourNetworkConnection"] as string; ;
195+
170196
IsUpdateCheckRunning = false;
171-
NoUpdateAvailable = true;
197+
ShowUpdaterMessage = true;
172198
}
173199
#endregion
174200
}

Source/NETworkManager/Views/Settings/AboutView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<TextBlock Text="{Binding UpdateText}" VerticalAlignment="Center" FontSize="14" Margin="10,0,0,0" />
7979
</StackPanel>
8080
<Controls:ProgressRing Grid.Column="2" Visibility="{Binding IsUpdateCheckRunning, Converter={StaticResource BooleanToVisibilityConverter}}" Height="{Binding ElementName=btnCheckForUpdates, Path=ActualHeight}" Width="{Binding ElementName=btnCheckForUpdates, Path=ActualHeight}" HorizontalAlignment="Left" IsActive="True" />
81-
<TextBlock Grid.Column="2" Text="{DynamicResource String_NoUpdateAvailable}" Visibility="{Binding NoUpdateAvailable, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource CenterTextBlock}" Margin="10,0,0,0" />
81+
<TextBlock Grid.Column="2" Text="{Binding UpdaterMessage}" Visibility="{Binding ShowUpdaterMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource CenterTextBlock}" Margin="10,0,0,0" />
8282
</Grid>
8383
<TextBlock Grid.Row="3" Text="{DynamicResource String_Header_Libraries}" Style="{StaticResource HeaderTextBlock}"/>
8484
<ScrollViewer Grid.Row="4" Style="{StaticResource DefaulScrollViewer}" Margin="0,0,0,20">

0 commit comments

Comments
 (0)