3636import java .util .List ;
3737import java .util .Map ;
3838import java .util .Objects ;
39- import java .util .regex .Matcher ;
4039import java .util .regex .Pattern ;
4140import java .util .stream .Stream ;
4241
4948
5049public class TSS extends Task <String > {
5150
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]*(?<!\\ .)" );
5553
5654 private final String deviceIdentifier ;
5755 private final String ecid ;
@@ -103,7 +101,15 @@ protected String call() throws TSSException {
103101
104102 // can't use forEach() because exception won't be caught
105103 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+ }
107113
108114 if (iosVersion .versionString () != null ) {
109115 responseBuilder .append (iosVersion .versionString ());
@@ -140,12 +146,6 @@ private void saveFor(Utils.IOSVersion iosVersion, ArrayList<String> args) throws
140146 parseTSSLog (tssLog );
141147 } catch (IOException e ) {
142148 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 ;
149149 }
150150 }
151151
@@ -160,7 +160,7 @@ private void checkInputs() throws TSSException {
160160 }
161161 if (manualIpswURL != null ) { // check URL
162162 try {
163- if (!ipswURLMatcher . reset (manualIpswURL ).matches ()) {
163+ if (!ipswURLPattern . matcher (manualIpswURL ).matches ()) {
164164 throw new MalformedURLException ("Doesn't match ipsw URL regex" );
165165 }
166166 new URL (manualIpswURL ); // check URL
@@ -172,7 +172,7 @@ private void checkInputs() throws TSSException {
172172 } catch (IllegalArgumentException | URISyntaxException | IOException e ) {
173173 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 );
174174 }
175- } else if (manualVersion != null && !versionMatcher . reset (manualVersion ).matches ()) {
175+ } else if (manualVersion != null && !versionPattern . matcher (manualVersion ).matches ()) {
176176 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 );
177177 }
178178 }
@@ -198,7 +198,11 @@ private List<Utils.IOSVersion> getIOSVersions() throws TSSException {
198198 return getSignedFirmwares (deviceIdentifier ).toList ();
199199 }
200200 } 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 );
202206 } catch (IOException e ) {
203207 throw new TSSException ("Saving blobs failed. Check your internet connection." , false , e );
204208 }
@@ -225,7 +229,7 @@ private ArrayList<String> constructArgs() {
225229 }
226230
227231 private String getBoardConfig () {
228- return Objects . requireNonNullElse (boardConfig , Devices .getBoardConfig (deviceIdentifier ));
232+ return Utils . defaultIfNull (boardConfig , Devices .getBoardConfig (deviceIdentifier ));
229233 }
230234
231235 @ SuppressWarnings ("TextBlockMigration" )
@@ -363,6 +367,15 @@ public TSSException(String message, boolean isReportable, Throwable cause) {
363367 this .tssLog = null ;
364368 }
365369
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+ }
366379 }
367380
368381 private void saveBlobsTSSSaver (StringBuilder responseBuilder ) {
0 commit comments