Console autoupdate fix #4352

This commit is contained in:
rusefillc 2022-07-17 03:10:42 -04:00
parent a0f1c1bfd4
commit b2fcb56e93
6 changed files with 89 additions and 32 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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<JProgressBar> 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();
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);
}
}