66import javafx .event .ActionEvent ;
77import javafx .fxml .FXML ;
88import javafx .scene .control .*;
9+ import javafx .scene .control .Button ;
10+ import javafx .scene .control .Label ;
11+ import javafx .scene .control .TextField ;
912import javafx .scene .effect .DropShadow ;
1013import javafx .scene .paint .Color ;
1114
15+ import java .awt .*;
16+ import java .awt .datatransfer .StringSelection ;
1217import java .io .*;
18+ import java .net .URI ;
1319import java .net .URISyntaxException ;
1420import java .util .ArrayList ;
1521import java .util .Arrays ;
@@ -43,6 +49,9 @@ public class Controller {
4349
4450 private DropShadow errorBorder = new DropShadow ();
4551
52+ private ButtonType redditPM = new ButtonType ("PM on Reddit" );
53+ private ButtonType githubIssue = new ButtonType ("Create Issue on Github" );
54+
4655 @ SuppressWarnings ("unchecked" )
4756 @ FXML
4857 public void initialize () {
@@ -108,8 +117,7 @@ public void initialize() {
108117 }
109118 });
110119 identifierField .textProperty ().addListener ((observable , oldValue , newValue ) -> {
111- String v = newValue ;
112- if (v .equals ("iPhone8,1" ) || v .equals ("iPhone8,2" ) || v .equals ("iPhone8,4" )) {
120+ if (newValue .equals ("iPhone8,1" ) || newValue .equals ("iPhone8,2" ) || newValue .equals ("iPhone8,4" )) {
113121 int depth = 20 ;
114122 DropShadow borderGlow = new DropShadow ();
115123 borderGlow .setOffsetY (0f );
@@ -138,7 +146,7 @@ public void initialize() {
138146 }
139147
140148 private void run (String device ) {
141- ArrayList <String > args = new ArrayList <String >(Arrays .asList (getClass ().getResource ("tsschecker" ).getPath (), "-d" , device , "-s" , "-e" , ecidField .getText ()));
149+ ArrayList <String > args = new ArrayList <>(Arrays .asList (getClass ().getResource ("tsschecker" ).getPath (), "-d" , device , "-s" , "-e" , ecidField .getText ()));
142150 if (boardConfig ) {
143151 args .add ("--boardconfig" );
144152 args .add (boardConfigField .getText ());
@@ -157,6 +165,20 @@ private void run(String device) {
157165 try {
158166 proc = new ProcessBuilder (args ).start ();
159167 } catch (IOException e ) {
168+ Alert alert = new Alert (Alert .AlertType .ERROR , "There was an error starting tsschecker.\n \n Please create a new issue on Github or PM me on Reddit. The crash log has been copied to your clipboard" , githubIssue , redditPM , ButtonType .CANCEL );
169+ StringSelection stringSelection = new StringSelection (e .toString ());
170+ Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection , null );
171+ alert .showAndWait ();
172+ try {
173+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
174+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
175+
176+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
177+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
178+ }
179+ } catch (IOException | URISyntaxException ee ) {
180+ ee .printStackTrace ();
181+ }
160182 e .printStackTrace ();
161183 }
162184 try (BufferedReader reader = new BufferedReader (new InputStreamReader (proc .getInputStream ()))) {
@@ -165,13 +187,40 @@ private void run(String device) {
165187 System .out .print (line + "\n " );
166188 }
167189 } catch (IOException e ) {
190+ Alert alert = new Alert (Alert .AlertType .ERROR , "There was an error getting the tsschecker log.\n \n Please create a new issue on Github or PM me on Reddit. The crash log has been copied to your clipboard" , githubIssue , redditPM , ButtonType .CANCEL );
191+ StringSelection stringSelection = new StringSelection (e .toString ());
192+ Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection , null );
193+ alert .showAndWait ();
194+ try {
195+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
196+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
197+
198+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
199+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
200+ }
201+ } catch (IOException | URISyntaxException ee ) {
202+ ee .printStackTrace ();
203+ }
168204 e .printStackTrace ();
169205 }
170206
171207 try {
172208 proc .waitFor ();
173209 } catch (InterruptedException e ) {
174- e .printStackTrace ();
210+ Alert alert = new Alert (Alert .AlertType .ERROR , "The tsschecker process was interrupted.\n \n Please create a new issue on Github or PM me on Reddit. The crash log has been copied to your clipboard" , githubIssue , redditPM , ButtonType .CANCEL );
211+ StringSelection stringSelection = new StringSelection (e .toString ());
212+ Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection , null );
213+ alert .showAndWait ();
214+ try {
215+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
216+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
217+
218+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
219+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
220+ }
221+ } catch (IOException | URISyntaxException ee ) {
222+ ee .printStackTrace ();
223+ }
175224 }
176225 }
177226
@@ -212,6 +261,7 @@ public void versionCheckBoxHandler() {
212261 }
213262 }
214263
264+ @ SuppressWarnings ("unchecked" )
215265 public void identifierCheckBoxHandler () {
216266 if (identifierCheckBox .isSelected ()) {
217267 identifierField .setDisable (false );
@@ -236,6 +286,7 @@ public void identifierCheckBoxHandler() {
236286 }
237287 }
238288
289+ @ SuppressWarnings ("unchecked" )
239290 private void loadPreset (int preset ) {
240291 File file ;
241292 try {
@@ -245,19 +296,39 @@ private void loadPreset(int preset) {
245296 try (InputStream input = new FileInputStream (file )) {
246297 prop .load (input );
247298 ecidField .setText (prop .getProperty ("ecid" ));
248- deviceTypeChoiceBox .setValue (prop .getProperty ("deviceType" ));
249- deviceModelChoiceBox .setValue (prop .getProperty ("deviceModel" ));
299+ if (prop .getProperty ("deviceModel" ).equals ("none" )) {
300+ identifierCheckBox .fire ();
301+ identifierField .setText (prop .getProperty ("deviceIdentifier" ));
302+ } else {
303+ deviceTypeChoiceBox .setValue (prop .getProperty ("deviceType" ));
304+ deviceModelChoiceBox .setValue (prop .getProperty ("deviceModel" ));
305+ }
250306 if (!prop .getProperty ("boardConfig" ).equals ("none" )) {
251307 boardConfigField .setText (prop .getProperty ("boardConfig" ));
252308 }
253309 } catch (IOException e ) {
310+ Alert alert = new Alert (Alert .AlertType .ERROR , "There was an error loading the profile.\n \n Please create a new issue on Github or PM me on Reddit. The crash log has been copied to your clipboard" , githubIssue , redditPM , ButtonType .CANCEL );
311+ StringSelection stringSelection = new StringSelection (e .toString ());
312+ Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection , null );
313+ alert .showAndWait ();
314+ try {
315+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
316+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
317+
318+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
319+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
320+ }
321+ } catch (IOException | URISyntaxException ee ) {
322+ ee .printStackTrace ();
323+ }
254324 e .printStackTrace ();
255325 }
256326 }
257327 } catch (URISyntaxException e ) {
258328 e .printStackTrace ();
259329 } catch (NullPointerException e ) {
260- System .out .println ("No options file" );
330+ Alert alert = new Alert (Alert .AlertType .ERROR , "Preset " + preset + " does not have anything" , ButtonType .OK );
331+ alert .showAndWait ();
261332 }
262333 }
263334
@@ -274,19 +345,60 @@ public void presetButtonHandler(ActionEvent evt) {
274345 }
275346
276347 private void saveOptions (int preset ) {
348+ boolean doReturn = false ;
349+ if (ecidField .getText ().equals ("" )) {
350+ ecidField .setEffect (errorBorder );
351+ doReturn = true ;
352+ }
353+ if (!identifierCheckBox .isSelected () && ((deviceModelChoiceBox .getValue () == null ) || (deviceModelChoiceBox .getValue () == "" ))) {
354+ deviceModelChoiceBox .setEffect (errorBorder );
355+ doReturn = true ;
356+ }
357+ if (identifierCheckBox .isSelected () && identifierField .getText ().equals ("" )) {
358+ identifierField .setEffect (errorBorder );
359+ doReturn = true ;
360+ }
361+ if (boardConfig && boardConfigField .getText ().equals ("" )) {
362+ boardConfigField .setEffect (errorBorder );
363+ doReturn = true ;
364+ }
365+ if (doReturn ) {
366+ return ;
367+ }
277368 Properties prop = new Properties ();
278369 File file = new File (getClass ().getResource ("" ).toString ().substring (5 ), "preset" + Integer .toString (preset ) + ".properties" );
279370 try (OutputStream output = new FileOutputStream (file )) {
280371 prop .setProperty ("ecid" , ecidField .getText ());
281- prop .setProperty ("deviceType" , (String ) deviceTypeChoiceBox .getValue ());
282- prop .setProperty ("deviceModel" , (String ) deviceModelChoiceBox .getValue ());
372+ if (identifierCheckBox .isSelected ()) {
373+ prop .setProperty ("deviceType" , "none" );
374+ prop .setProperty ("deviceModel" , "none" );
375+ prop .setProperty ("deviceIdentifier" , identifierField .getText ());
376+ } else {
377+ prop .setProperty ("deviceType" , (String ) deviceTypeChoiceBox .getValue ());
378+ prop .setProperty ("deviceModel" , (String ) deviceModelChoiceBox .getValue ());
379+ }
283380 if (boardConfig ) {
284381 prop .setProperty ("boardConfig" , boardConfigField .getText ());
285382 } else {
286383 prop .setProperty ("boardConfig" , "none" );
287384 }
288385 prop .store (output , null );
289386 } catch (IOException e ) {
387+ Alert alert = new Alert (Alert .AlertType .ERROR , "There was an error while saving the data.\n \n Please create a new issue on Github or PM me on Reddit. The crash log has been copied to your clipboard" , githubIssue , redditPM , ButtonType .CANCEL );
388+ StringSelection stringSelection = new StringSelection (e .toString ());
389+ Toolkit .getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection , null );
390+ alert .showAndWait ();
391+ try {
392+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
393+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
394+
395+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
396+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
397+ }
398+ } catch (IOException | URISyntaxException ee ) {
399+ ee .printStackTrace ();
400+ }
401+
290402 e .printStackTrace ();
291403 }
292404 }
@@ -316,7 +428,6 @@ public void saveOptionsHandler() {
316428 preset2Button .setText ("Load Preset 2" );
317429 preset3Button .setText ("Load Preset 3" );
318430 }
319- System .out .println (editingPresets );
320431 }
321432
322433
@@ -570,12 +681,45 @@ public void go() {
570681 run ("iPad7,6" );
571682 break ;
572683 case "" :
573- if (!identifierField .getText ().equals ("" )) {
574- run (identifierField .getText ());
684+ String identifierText = identifierField .getText ();
685+ try {
686+ // Throws StringIndexOutOfBoundsException even if identifier is correct if I don't do it like this:
687+ if (identifierText .substring (0 , 4 ).equals ("iPad" )) {
688+ run (identifierField .getText ());
689+ } else if (identifierText .substring (0 , 4 ).equals ("iPod" )) {
690+ run (identifierField .getText ());
691+ } else if (identifierText .substring (0 , 6 ).equals ("iPhone" )) {
692+ run (identifierField .getText ());
693+ } else if (identifierText .substring (0 , 7 ).equals ("AppleTV" )) {
694+ run (identifierField .getText ());
695+ } else {
696+ Alert alert = new Alert (Alert .AlertType .ERROR , "\" " + identifierText +
697+ "\" is not a valid identifier" , ButtonType .OK , ButtonType .CANCEL );
698+ alert .showAndWait ();
699+ return ;
700+ }
701+ } catch (StringIndexOutOfBoundsException e ) {
702+ Alert alert = new Alert (Alert .AlertType .ERROR , "\" " + identifierText +
703+ "\" is not a valid identifier" , ButtonType .OK , ButtonType .CANCEL );
704+ alert .showAndWait ();
705+ return ;
575706 }
707+
576708 break ;
577709 default :
578- System .out .print ("" ); // TODO: Show an error
710+ Alert alert = new Alert (Alert .AlertType .ERROR , "Could not find: \" " + deviceModel +
711+ "\" \n \n Please create a new Github issue or PM me on Reddit" , githubIssue , redditPM , ButtonType .CANCEL );
712+ alert .showAndWait ();
713+ try {
714+ if (alert .getResult ().equals (githubIssue ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
715+ Desktop .getDesktop ().browse (new URI ("https://github.com/airsquared/blobsaver/issues/new" ));
716+
717+ } else if (alert .getResult ().equals (redditPM ) && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
718+ Desktop .getDesktop ().browse (new URI ("https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Bug+Report" ));
719+ }
720+ } catch (IOException | URISyntaxException ee ) {
721+ ee .printStackTrace ();
722+ }
579723 break ;
580724 }
581725 }
0 commit comments