@@ -9,50 +9,57 @@ public class ConsolePatchAccessor : PatchAccessor, IDisposable
9
9
{
10
10
private readonly FtpClient _client ;
11
11
private const string BasePath = "/dev_hdd0/" ;
12
+ private readonly string _remoteIp ;
12
13
13
14
public readonly Lazy < byte [ ] ? > IdpsFile ;
14
15
15
16
public ConsolePatchAccessor ( string remoteIp )
16
17
{
18
+ this . _remoteIp = remoteIp ;
19
+
17
20
this . _client = new FtpClient ( remoteIp , "anonymous" , "" ) ;
18
21
this . _client . Config . LogToConsole = true ;
19
22
this . _client . Config . ConnectTimeout = 5000 ;
20
23
21
24
FtpProfile ? profile = this . _client . AutoConnect ( ) ;
22
25
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 ;
23
41
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 )
25
56
{
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
+ }
29
61
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 ;
56
63
}
57
64
58
65
private static string GetPath ( string path )
0 commit comments