Skip to content

Commit

Permalink
Fallback to dev_usb000 if IDPS is not found on dev_hdd0
Browse files Browse the repository at this point in the history
Weird webman quirk
  • Loading branch information
jvyden committed May 1, 2024
1 parent 7a9c7e8 commit 2452280
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions Refresher/Accessors/ConsolePatchAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,57 @@ public class ConsolePatchAccessor : PatchAccessor, IDisposable
{
private readonly FtpClient _client;
private const string BasePath = "/dev_hdd0/";
private readonly string _remoteIp;

public readonly Lazy<byte[]?> IdpsFile;

public ConsolePatchAccessor(string remoteIp)
{
this._remoteIp = remoteIp;

this._client = new FtpClient(remoteIp, "anonymous", "");
this._client.Config.LogToConsole = true;
this._client.Config.ConnectTimeout = 5000;

FtpProfile? profile = this._client.AutoConnect();
if (profile == null) throw new FTPConnectionFailureException();

this.IdpsFile = new Lazy<byte[]?>(this.GetIdps);
}

private byte[]? GetIdps()
{
Program.Log("Getting IDPS...", "IDPS");
UriBuilder idpsPs3 = new("http", this._remoteIp, 80, "idps.ps3");
UriBuilder idpsHex = new("http", this._remoteIp, 80, "dev_hdd0/idps.hex");
UriBuilder idpsHexUsb = new("http", this._remoteIp, 80, "dev_usb000/idps.hex");

HttpClient httpClient = new();

HttpResponseMessage? response = this.IdpsRequestStep("Triggering generation of IDPS file", httpClient, idpsPs3.Uri);
if (response == null) return null;

this.IdpsFile = new Lazy<byte[]?>(() =>
response = this.IdpsRequestStep("Downloading IDPS hex (HDD)", httpClient, idpsHex.Uri);
response ??= this.IdpsRequestStep("Downloading IDPS hex (USB)", httpClient, idpsHexUsb.Uri);

//Return the IDPS key
return response?.Content.ReadAsByteArrayAsync().Result;
}

private HttpResponseMessage? IdpsRequestStep(ReadOnlySpan<char> stepName, HttpClient client, Uri uri)
{
Program.Log($" {stepName} ({uri.AbsolutePath})", "IDPS");
HttpResponseMessage response = client.GetAsync(uri).Result;
Program.Log($" {(int)response.StatusCode} {response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");

if (!response.IsSuccessStatusCode)
{
Program.Log("Getting IDPS...", "IDPS");
UriBuilder idpsPs3 = new("http", remoteIp, 80, "idps.ps3");
UriBuilder idpsHex = new("http", remoteIp, 80, "dev_hdd0/idps.hex");
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
return null;
}

HttpClient httpClient = new();

// Get the /idps.ps3 path, this creates the idps.hex file we can grab.
Program.Log(" Triggering generation of IDPS file", "IDPS");
HttpResponseMessage response = httpClient.GetAsync(idpsPs3.Uri).Result;
Program.Log($" {response.StatusCode} {(int)response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");
if (!response.IsSuccessStatusCode)
{
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
return null;
}

Program.Log(" Downloading IDPS hex", "IDPS");
response = httpClient.GetAsync(idpsHex.Uri).Result;
Program.Log($" {response.StatusCode} {(int)response.StatusCode} (success: {response.IsSuccessStatusCode})", "IDPS");
if (!response.IsSuccessStatusCode)
{
Program.Log("Couldn't fetch the IDPS from the PS3 because of a bad status code.", "IDPS", BreadcrumbLevel.Error);
Program.Log(response.Content.ReadAsStringAsync().Result, "IDPS", BreadcrumbLevel.Debug);
return null;
}

//Return the IDPS key
return response.Content.ReadAsByteArrayAsync().Result;
});
return response;
}

private static string GetPath(string path)
Expand Down

0 comments on commit 2452280

Please sign in to comment.