mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Better error messages when webservice host ping fails
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user