(String suggestedClassName, boolean usingProgrammer)
| 706 | } |
| 707 | |
| 708 | private boolean upload(String suggestedClassName, boolean usingProgrammer) throws Exception { |
| 709 | |
| 710 | UploaderUtils uploaderInstance = new UploaderUtils(); |
| 711 | Uploader uploader = uploaderInstance.getUploaderByPreferences(false); |
| 712 | |
| 713 | EditorConsole.setCurrentEditorConsole(editor.console); |
| 714 | |
| 715 | boolean success = false; |
| 716 | do { |
| 717 | if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) { |
| 718 | PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(editor, tr("Type board password to upload a new sketch")); |
| 719 | dialog.setLocationRelativeTo(editor); |
| 720 | dialog.setVisible(true); |
| 721 | |
| 722 | if (dialog.isCancelled()) { |
| 723 | editor.statusNotice(tr("Upload cancelled")); |
| 724 | return false; |
| 725 | } |
| 726 | |
| 727 | PreferencesData.set(uploader.getAuthorizationKey(), dialog.getPassword()); |
| 728 | } |
| 729 | |
| 730 | List<String> warningsAccumulator = new LinkedList<>(); |
| 731 | try { |
| 732 | success = uploaderInstance.upload(sketch, uploader, suggestedClassName, usingProgrammer, false, warningsAccumulator); |
| 733 | } finally { |
| 734 | if (uploader.requiresAuthorization() && !success) { |
| 735 | PreferencesData.remove(uploader.getAuthorizationKey()); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | for (String warning : warningsAccumulator) { |
| 740 | System.out.print(tr("Warning")); |
| 741 | System.out.print(": "); |
| 742 | System.out.println(warning); |
| 743 | } |
| 744 | |
| 745 | } while (uploader.requiresAuthorization() && !success); |
| 746 | |
| 747 | if (!success) { |
| 748 | String errorMessage = uploader.getFailureMessage(); |
| 749 | if (errorMessage.equals("")) { |
| 750 | errorMessage = tr("An error occurred while uploading the sketch"); |
| 751 | } |
| 752 | editor.statusError(errorMessage); |
| 753 | } |
| 754 | |
| 755 | return success; |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Make sure the sketch hasn't been moved or deleted by some |
no test coverage detected