Skip to content

Commit 2452280

Browse files
committed
Fallback to dev_usb000 if IDPS is not found on dev_hdd0
Weird webman quirk
1 parent 7a9c7e8 commit 2452280

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

Refresher/Accessors/ConsolePatchAccessor.cs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,57 @@ public class ConsolePatchAccessor : PatchAccessor, IDisposable
99
{
1010
private readonly FtpClient _client;
1111
private const string BasePath = "/dev_hdd0/";
12+
private readonly string _remoteIp;
1213

1314
public readonly Lazy<byte[]?> IdpsFile;
1415

1516
public ConsolePatchAccessor(string remoteIp)
1617
{
18+
this._remoteIp = remoteIp;
19+
1720
this._client = new FtpClient(remoteIp, "anonymous", "");
1821
this._client.Config.LogToConsole = true;
1922
this._client.Config.ConnectTimeout = 5000;
2023

2124
FtpProfile? profile = this._client.AutoConnect();
2225
if (profile == null) throw new FTPConnectionFailureException();
26+
27+
this.IdpsFile = new Lazy<byte[]?>(this.GetIdps);
28+
}
29+
30+
private byte[]? GetIdps()
31+
{
32+
Program.Log("Getting IDPS...", "IDPS");
33+
UriBuilder idpsPs3 = new("http", this._remoteIp, 80, "idps.ps3");
34+
UriBuilder idpsHex = new("http", this._remoteIp, 80, "dev_hdd0/idps.hex");
35+
UriBuilder idpsHexUsb = new("http", this._remoteIp, 80, "dev_usb000/idps.hex");
36+
37+
HttpClient httpClient = new();
38+
39+
HttpResponseMessage? response = this.IdpsRequestStep("Triggering generation of IDPS file", httpClient, idpsPs3.Uri);
40+
if (response == null) return null;
2341

24-
this.IdpsFile = new Lazy<byte[]?>(() =>
42+
response = this.IdpsRequestStep("Downloading IDPS hex (HDD)", httpClient, idpsHex.Uri);
43+
response ??= this.IdpsRequestStep("Downloading IDPS hex (USB)", httpClient, idpsHexUsb.Uri);
44+
45+
//Return the IDPS key
46+
return response?.Content.ReadAsByteArrayAsync().Result;
47+
}
48+
49+
private HttpResponseMessage? IdpsRequestStep(ReadOnlySpan<char> stepName, HttpClient client, Uri uri)
50+
{
51+
Program.Log($" {stepName} ({uri.AbsolutePath})", "IDPS");
52+
HttpResponseMessage response = client.GetAsync(uri).Result;
53+
Program.Log($" {(int)response.StatusCode} {response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");
54+
55+
if (!response.IsSuccessStatusCode)
2556
{
26-
Program.Log("Getting IDPS...", "IDPS");
27-
UriBuilder idpsPs3 = new("http", remoteIp, 80, "idps.ps3");
28-
UriBuilder idpsHex = new("http", remoteIp, 80, "dev_hdd0/idps.hex");
57+
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
58+
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
59+
return null;
60+
}
2961

30-
HttpClient httpClient = new();
31-
32-
// Get the /idps.ps3 path, this creates the idps.hex file we can grab.
33-
Program.Log(" Triggering generation of IDPS file", "IDPS");
34-
HttpResponseMessage response = httpClient.GetAsync(idpsPs3.Uri).Result;
35-
Program.Log($" {response.StatusCode} {(int)response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");
36-
if (!response.IsSuccessStatusCode)
37-
{
38-
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
39-
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
40-
return null;
41-
}
42-
43-
Program.Log(" Downloading IDPS hex", "IDPS");
44-
response = httpClient.GetAsync(idpsHex.Uri).Result;
45-
Program.Log($" {response.StatusCode} {(int)response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");
46-
if (!response.IsSuccessStatusCode)
47-
{
48-
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
49-
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
50-
return null;
51-
}
52-
53-
//Return the IDPS key
54-
return response.Content.ReadAsByteArrayAsync().Result;
55-
});
62+
return response;
5663
}
5764

5865
private static string GetPath(string path)

0 commit comments

Comments
 (0)