Skip to content

Commit f3b897c

Browse files
author
HyperPolygon64
committed
Fixed application hanging for awhile with no network connection
modified: Sonic-06-Mod-Manager/src/Environment3/RushInterface.Designer.cs modified: Sonic-06-Mod-Manager/src/Environment3/RushInterface.cs modified: Sonic-06-Mod-Manager/src/UnifyNetworking.cs
1 parent 9b693f2 commit f3b897c

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

Sonic-06-Mod-Manager/src/Environment3/RushInterface.Designer.cs

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

Sonic-06-Mod-Manager/src/Environment3/RushInterface.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public RushInterface() {
6464
if (Paths.IsDirectoryEmpty(Program.Patches)) {
6565
Properties.Settings.Default.General_LastPatchUpdate = DateTime.Now.Ticks;
6666
// Update patches synchronously
67-
Task.Run(() => UpdatePatches()).GetAwaiter().GetResult();
67+
if (Client.CheckNetworkConnection().Result) Task.Run(() => UpdatePatches()).GetAwaiter().GetResult();
6868

6969
// Reset update button for future checking
7070
SectionButton_FetchPatches.Enabled = true;
@@ -449,25 +449,31 @@ private async void CheckForUpdates(string versionURI, string changelogsURI) {
449449
SectionButton_CheckForSoftwareUpdates.Enabled = false;
450450

451451
try {
452-
string latestVersion = await Client.RequestString(versionURI), // Request version number
453-
changelogs = await Client.RequestString(changelogsURI);
454-
455-
// New update available!
456-
if (Program.VersionNumber != latestVersion && latestVersion.StartsWith("Version"))
457-
if (InvokeRequired)
458-
Invoke(new MethodInvoker(delegate { OnCheckForUpdates(latestVersion, changelogs); }));
459-
else
460-
OnCheckForUpdates(latestVersion, changelogs);
452+
if (Client.CheckNetworkConnection().Result) {
453+
string latestVersion = await Client.RequestString(versionURI), // Request version number
454+
changelogs = await Client.RequestString(changelogsURI); // Request changelogs
455+
456+
// New update available!
457+
if (Program.VersionNumber != latestVersion && latestVersion.StartsWith("Version"))
458+
if (InvokeRequired)
459+
Invoke(new MethodInvoker(delegate { OnCheckForUpdates(latestVersion, changelogs); }));
460+
else
461+
OnCheckForUpdates(latestVersion, changelogs);
461462

462-
// String was downloaded, but invalid
463-
else if (!latestVersion.StartsWith("Version"))
464-
throw new WebException();
463+
// String was downloaded, but invalid
464+
else if (!latestVersion.StartsWith("Version"))
465+
throw new WebException("Invalid version number - server might be down...");
466+
} else
467+
throw new WebException("Could not establish a connection...");
465468
} catch {
466469
try {
467470
// Check for updates via SEGA Carnival
468-
CheckForUpdates(Properties.Resources.VersionURI_SEGACarnival, Properties.Resources.ChangelogsURI_SEGACarnival);
469-
Properties.Settings.Default.General_LastSoftwareUpdate = DateTime.Now.Ticks;
470-
_useBackupServer = true;
471+
if (Client.CheckNetworkConnection().Result) {
472+
CheckForUpdates(Properties.Resources.VersionURI_SEGACarnival, Properties.Resources.ChangelogsURI_SEGACarnival);
473+
Properties.Settings.Default.General_LastSoftwareUpdate = DateTime.Now.Ticks;
474+
_useBackupServer = true;
475+
} else
476+
throw new WebException("Could not establish a connection...");
471477
} catch (Exception ex) {
472478
Label_UpdaterStatus.Text = "Connection error";
473479
PictureBox_UpdaterIcon.BackgroundImage = Properties.Resources.Exception_Logo;

Sonic-06-Mod-Manager/src/UnifyNetworking.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ class Client
4141
/// Asynchronously grabs a string from the specified URI.
4242
/// </summary>
4343
public static async Task<string> RequestString(string uri) { return await new WebClient().DownloadStringTaskAsync(uri); }
44+
45+
public static async Task<bool> CheckNetworkConnection() {
46+
try {
47+
using (var client = new WebClient())
48+
using (client.OpenRead("http://google.com/generate_204"))
49+
return true;
50+
} catch {
51+
return false;
52+
}
53+
}
4454
}
4555
}
4656

0 commit comments

Comments
 (0)