From 53df8b83a1f9ea35173b80d063aa9850d71e9d0c Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Tue, 19 Aug 2025 17:49:53 -0500 Subject: [PATCH] Better error messages when webservice host ping fails --- ZuneModCore/Mods/WebservicesMod.cs | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ZuneModCore/Mods/WebservicesMod.cs b/ZuneModCore/Mods/WebservicesMod.cs index bc44404..74f4942 100644 --- a/ZuneModCore/Mods/WebservicesMod.cs +++ b/ZuneModCore/Mods/WebservicesMod.cs @@ -128,6 +128,20 @@ public class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit try { + // Get and validate replacement host + string oldHost = "zune.net"; + string newHost = ((AbstractTextBox)OptionsUI![0]).Value; + if (newHost.Length != oldHost.Length) + { + return $"The new host (\"{newHost}\") must have the same length as \"{oldHost}\"."; + } + + var ping = await new System.Net.NetworkInformation.Ping().SendPingAsync(newHost); + if (ping.Status != System.Net.NetworkInformation.IPStatus.Success) + { + return $"Failed to reach \"{newHost}\". Ping status: {ping.Status}"; + } + // Open the file using FileStream zsDll = zsDllInfo.Open(FileMode.Open); using BinaryWriter zsDllWriter = new(zsDll); @@ -141,19 +155,6 @@ public class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit return "This mod has not been tested on versions earlier than 4.8."; } - // Get and validate replacement host - string oldHost = "zune.net"; - string newHost = ((AbstractTextBox)OptionsUI![0]).Value; - if (newHost.Length != oldHost.Length) - { - return $"The new host (\"{newHost}\") must have the same length as \"{oldHost}\"."; - } - var ping = await new System.Net.NetworkInformation.Ping().SendPingAsync(newHost); - if (ping.Status != System.Net.NetworkInformation.IPStatus.Success) - { - return $"Failed to reach \"{newHost}\". Ping status: {ping.Status}"; - } - // Read URL block as string zsDllReader.BaseStream.Position = ZUNESERVICES_ENDPOINTS_BLOCK_OFFSET; string endpointBlock = System.Text.Encoding.Unicode.GetString(zsDllReader.ReadBytes(ZUNESERVICES_ENDPOINTS_BLOCK_LENGTH)); @@ -167,7 +168,6 @@ public class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit catch { } // Patch ZuneServices.dll to use the new host instead of zune.net - endpointBlock = endpointBlock.Replace("resources." + oldHost, "www.zuneupdate.com"); // Use zuneupdate.com until resources.zunes.me is online endpointBlock = endpointBlock.Replace(oldHost, newHost); byte[] endpointBytes = System.Text.Encoding.Unicode.GetBytes(endpointBlock); if (endpointBytes.Length != ZUNESERVICES_ENDPOINTS_BLOCK_LENGTH) @@ -177,7 +177,6 @@ public class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit zsDllWriter.Seek(ZUNESERVICES_ENDPOINTS_BLOCK_OFFSET, SeekOrigin.Begin); zsDllWriter.Write(endpointBytes); - // Enable all feature overrides affected by new servers bool setOverrideSuccess = true; foreach (var feature in _affectedFeatures) @@ -192,6 +191,10 @@ public class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit { return $"Unable to replace '{zsDllInfo.FullName}'. Verify that the Zune software is not running and try again."; } + catch (System.Net.NetworkInformation.PingException pingEx) + { + return $"Failed to reach new host. {pingEx.InnerException?.Message ?? pingEx.Message}"; + } catch (Exception ex) { return ex.Message;