diff --git a/firmware/CHANGELOG.md b/firmware/CHANGELOG.md index 306c0c02c0..819c3bb25f 100644 --- a/firmware/CHANGELOG.md +++ b/firmware/CHANGELOG.md @@ -32,6 +32,7 @@ Release template (copy/paste this for new release): - Lua CAN reception fixed for 11-bit IDs where the frame would be received, but a corrupt ID was passed to the handler function. #4321 - Many drop downs menues are now sorted #4339 - rusEFI TS plugin launcher fixed + - Console autoupdate error dialogs #4352 ### Removed - ICU trigger input logic since it is unused in any current ECU #639 diff --git a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java index ecab859220..a9f7e7a77b 100644 --- a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java +++ b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/Autoupdate.java @@ -21,7 +21,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; public class Autoupdate { - private static final String TITLE = "rusEFI Bundle Updater 20210212"; + private static final String TITLE = "rusEFI Bundle Updater 20220717"; private static final String BUNDLE_NAME_FILE = "../bundle_name.txt"; private static final String AUTOUPDATE_MODE = "autoupdate"; private static final String RUSEFI_CONSOLE_JAR = "rusefi_console.jar"; @@ -33,18 +33,17 @@ public class Autoupdate { if (args.length > 0 && args[0].equalsIgnoreCase("release")) { System.out.println("Release update requested"); handleBundle(bundleFullName, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE); - return; - } - - System.out.println("Latest update requested"); - UpdateMode mode = getMode(); - if (mode != UpdateMode.NEVER) { - if (bundleFullName != null) { - System.out.println("Handling " + bundleFullName); - handleBundle(bundleFullName, mode, ConnectionAndMeta.BASE_URL_LATEST); - } } else { - System.out.println("Update mode: NEVER"); + UpdateMode mode = getMode(); + if (mode != UpdateMode.NEVER) { + System.out.println("Snapshot requested"); + if (bundleFullName != null) { + System.out.println("Handling " + bundleFullName); + handleBundle(bundleFullName, mode, ConnectionAndMeta.BASE_URL_LATEST); + } + } else { + System.out.println("Update mode: NEVER"); + } } startConsole(args); } @@ -104,8 +103,17 @@ public class Autoupdate { System.out.println("Downloaded " + file.length() + " bytes"); FileUtil.unzip(zipFileName, new File("..")); - } catch (Exception e) { - System.err.println(e); + } catch (ReportedIOException e) { + // we had already reported error with a UI dialog when we had parent frame + System.err.println("Error downloading bundle: " + e); + } catch (IOException e) { + // we are here if error happened while we did not have UI frame + // todo: open frame prior to network connection and keep frame opened while uncompressing? + System.err.println("Error downloading bundle: " + e); + if (!AutoupdateUtil.runHeadless) { + JOptionPane.showMessageDialog(null, "Error downloading " + e, "Error", + JOptionPane.ERROR_MESSAGE); + } } } @@ -190,6 +198,9 @@ public class Autoupdate { return doUpdate.get(); } + /** + * @return null in case of error + */ @Nullable public static String readBundleFullName() { try { diff --git a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/AutoupdateUtil.java b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/AutoupdateUtil.java index 1b242c4323..3f47d6cb74 100644 --- a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/AutoupdateUtil.java +++ b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/AutoupdateUtil.java @@ -28,29 +28,55 @@ public class AutoupdateUtil { return result; } - public static void downloadAutoupdateFile(String localZipFileName, ConnectionAndMeta connectionAndMeta, String title) throws IOException { - FrameHelper frameHelper = null; - final AtomicReference jProgressBarAtomicReference = new AtomicReference<>(); - if (!runHeadless) { - frameHelper = new FrameHelper(); + static class ProgressView { + private final FrameHelper frameHelper; + private JProgressBar progressBar; + + ProgressView(FrameHelper frameHelper, JProgressBar progressBar) { + this.frameHelper = frameHelper; + this.progressBar = progressBar; + } + + public void dispose() { + if (frameHelper != null) { + frameHelper.getFrame().dispose(); + } + } + } + + private static ProgressView createProgressView(String title) { + if (runHeadless) { + return new ProgressView(null, null); + } else { + FrameHelper frameHelper = new FrameHelper(); JProgressBar jProgressBar = new JProgressBar(); frameHelper.getFrame().setTitle(title); jProgressBar.setMaximum(ConnectionAndMeta.CENTUM); - jProgressBarAtomicReference.set(jProgressBar); frameHelper.showFrame(jProgressBar, true); + return new ProgressView(frameHelper, jProgressBar); } + } - ConnectionAndMeta.DownloadProgressListener listener = currentProgress -> { - if (!runHeadless) { - SwingUtilities.invokeLater(() -> jProgressBarAtomicReference.get().setValue(currentProgress)); - } - }; + public static void downloadAutoupdateFile(String localZipFileName, ConnectionAndMeta connectionAndMeta, String title) throws IOException { + ProgressView view = createProgressView(title); - ConnectionAndMeta.downloadFile(localZipFileName, connectionAndMeta, listener); + try { + ConnectionAndMeta.DownloadProgressListener listener = currentProgress -> { + if (!runHeadless) { + SwingUtilities.invokeLater(() -> view.progressBar.setValue(currentProgress)); + } + }; - if (!runHeadless) { - frameHelper.getFrame().dispose(); + ConnectionAndMeta.downloadFile(localZipFileName, connectionAndMeta, listener); + } catch (IOException e) { + if (view.progressBar!=null) { + JOptionPane.showMessageDialog(view.progressBar, "Error downloading: " + e, "Error", JOptionPane.ERROR_MESSAGE); + throw new ReportedIOException(e); + } else + throw e; + } finally { + view.dispose(); } } diff --git a/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/ReportedIOException.java b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/ReportedIOException.java new file mode 100644 index 0000000000..255654db19 --- /dev/null +++ b/java_console/autoupdate/src/main/java/com/rusefi/autoupdate/ReportedIOException.java @@ -0,0 +1,14 @@ +package com.rusefi.autoupdate; + +import java.io.IOException; + +/** + * IO Exception which was already reported with a UI dialog + */ +public class ReportedIOException extends IOException { + private IOException e; + + public ReportedIOException(IOException e) { + this.e = e; + } +} diff --git a/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java b/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java index 6e814a7a41..5e5afc4723 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java +++ b/java_console/shared_io/src/main/java/com/rusefi/shared/ConnectionAndMeta.java @@ -69,10 +69,15 @@ public class ConnectionAndMeta { return lastModified; } - public ConnectionAndMeta invoke(String baseUrl) throws IOException, NoSuchAlgorithmException, KeyManagementException { + public ConnectionAndMeta invoke(String baseUrl) throws IOException { // user can have java with expired certificates or funny proxy, we shall accept any certificate :( - SSLContext ctx = SSLContext.getInstance("TLS"); - ctx.init(new KeyManager[0], new TrustManager[]{new AcceptAnyCertificateTrustManager()}, new SecureRandom()); + SSLContext ctx = null; + try { + ctx = SSLContext.getInstance("TLS"); + ctx.init(new KeyManager[0], new TrustManager[]{new AcceptAnyCertificateTrustManager()}, new SecureRandom()); + } catch (NoSuchAlgorithmException | KeyManagementException e) { + throw new IOException("TLS exception", e); + } URL url = new URL(baseUrl + zipFileName); System.out.println("Connecting to " + url); diff --git a/java_console/shared_ui/src/main/java/com/rusefi/ui/AuthTokenPanel.java b/java_console/shared_ui/src/main/java/com/rusefi/ui/AuthTokenPanel.java index 4fa9053de2..4941bb1791 100644 --- a/java_console/shared_ui/src/main/java/com/rusefi/ui/AuthTokenPanel.java +++ b/java_console/shared_ui/src/main/java/com/rusefi/ui/AuthTokenPanel.java @@ -135,6 +135,6 @@ public class AuthTokenPanel { } public static void showError(JComponent parent) { - JOptionPane.showMessageDialog(parent, "Does not work without auth token, see below."); + JOptionPane.showMessageDialog(parent, "Does not work without auth token, see below.", "Auth Token", JOptionPane.ERROR_MESSAGE); } }