36
36
import java .util .List ;
37
37
import java .util .Map ;
38
38
import java .util .Objects ;
39
- import java .util .regex .Matcher ;
40
39
import java .util .regex .Pattern ;
41
40
import java .util .stream .Stream ;
42
41
49
48
50
49
public class TSS extends Task <String > {
51
50
52
- // note: Matcher is NOT thread safe
53
- private static final Matcher ipswURLMatcher = Pattern .compile ("(https?://|file:/).*\\ .ipsw" ).matcher ("" );
54
- private static final Matcher versionMatcher = Pattern .compile ("[0-9]+\\ .[0-9]+\\ .?[0-9]*(?<!\\ .)" ).matcher ("" );
51
+ private static final Pattern ipswURLPattern = Pattern .compile ("(https?://|file:/).*\\ .ipsw" );
52
+ private static final Pattern versionPattern = Pattern .compile ("[0-9]+\\ .[0-9]+\\ .?[0-9]*(?<!\\ .)" );
55
53
56
54
private final String deviceIdentifier ;
57
55
private final String ecid ;
@@ -103,7 +101,15 @@ protected String call() throws TSSException {
103
101
104
102
// can't use forEach() because exception won't be caught
105
103
for (Utils .IOSVersion iosVersion : iosVersions ) {
106
- saveFor (iosVersion , args );
104
+ try {
105
+ saveFor (iosVersion , args );
106
+ } catch (TSSException e ) {
107
+ if ((manualVersion == null && manualIpswURL == null ) && e .getMessage ().contains ("not being signed" )) {
108
+ System .out .println ("Warning: ignoring unsigned version; API is likely out of date" );
109
+ continue ; // ignore not being signed (API might not be updated)
110
+ }
111
+ throw e ;
112
+ }
107
113
108
114
if (iosVersion .versionString () != null ) {
109
115
responseBuilder .append (iosVersion .versionString ());
@@ -140,12 +146,6 @@ private void saveFor(Utils.IOSVersion iosVersion, ArrayList<String> args) throws
140
146
parseTSSLog (tssLog );
141
147
} catch (IOException e ) {
142
148
throw new TSSException ("There was an error starting tsschecker." , true , e );
143
- } catch (TSSException e ) {
144
- if ((manualVersion == null && manualIpswURL == null ) && e .getMessage ().contains ("not being signed" )) {
145
- System .out .println ("Warning: ignoring unsigned version; API might be out of date" );
146
- return ; // ignore not being signed (API might not be updated)
147
- }
148
- throw e ;
149
149
}
150
150
}
151
151
@@ -160,7 +160,7 @@ private void checkInputs() throws TSSException {
160
160
}
161
161
if (manualIpswURL != null ) { // check URL
162
162
try {
163
- if (!ipswURLMatcher . reset (manualIpswURL ).matches ()) {
163
+ if (!ipswURLPattern . matcher (manualIpswURL ).matches ()) {
164
164
throw new MalformedURLException ("Doesn't match ipsw URL regex" );
165
165
}
166
166
new URL (manualIpswURL ); // check URL
@@ -172,7 +172,7 @@ private void checkInputs() throws TSSException {
172
172
} catch (IllegalArgumentException | URISyntaxException | IOException e ) {
173
173
throw new TSSException ("The IPSW URL is not valid.\n \n Make sure it's a valid file URL to a local .ipsw file." , false , e );
174
174
}
175
- } else if (manualVersion != null && !versionMatcher . reset (manualVersion ).matches ()) {
175
+ } else if (manualVersion != null && !versionPattern . matcher (manualVersion ).matches ()) {
176
176
throw new TSSException ("Invalid version. Make sure it follows the convention X.X.X or X.X, like \" 13.1\" or \" 13.5.5\" " , false );
177
177
}
178
178
}
@@ -198,7 +198,11 @@ private List<Utils.IOSVersion> getIOSVersions() throws TSSException {
198
198
return getSignedFirmwares (deviceIdentifier ).toList ();
199
199
}
200
200
} catch (FileNotFoundException e ) {
201
- throw new TSSException ("The device \" " + deviceIdentifier + "\" could not be found." , false , e );
201
+ var message = "The device \" " + deviceIdentifier + "\" could not be found." ;
202
+ if (includeBetas ) {
203
+ message += " This device may not have any beta versions available; try without including beta versions." ;
204
+ }
205
+ throw new TSSException (message , false , e );
202
206
} catch (IOException e ) {
203
207
throw new TSSException ("Saving blobs failed. Check your internet connection." , false , e );
204
208
}
@@ -225,7 +229,7 @@ private ArrayList<String> constructArgs() {
225
229
}
226
230
227
231
private String getBoardConfig () {
228
- return Objects . requireNonNullElse (boardConfig , Devices .getBoardConfig (deviceIdentifier ));
232
+ return Utils . defaultIfNull (boardConfig , Devices .getBoardConfig (deviceIdentifier ));
229
233
}
230
234
231
235
@ SuppressWarnings ("TextBlockMigration" )
@@ -363,6 +367,15 @@ public TSSException(String message, boolean isReportable, Throwable cause) {
363
367
this .tssLog = null ;
364
368
}
365
369
370
+ public void showErrorAlert () {
371
+ if (isReportable && tssLog != null ) {
372
+ Utils .showReportableError (getMessage (), tssLog );
373
+ } else if (isReportable ) {
374
+ Utils .showReportableError (getMessage (), Utils .exceptionToString (this ));
375
+ } else {
376
+ Utils .showUnreportableError (getMessage ());
377
+ }
378
+ }
366
379
}
367
380
368
381
private void saveBlobsTSSSaver (StringBuilder responseBuilder ) {
0 commit comments