no autoupdate (#81)

* removing autoupdate

* related cleanup

* why does autoupdate util have nothing to do with autoupdate
This commit is contained in:
Matthew Kennedy 2023-04-12 22:07:25 -07:00 committed by GitHub
parent 3f0e73708d
commit befd3ae871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 120 additions and 604 deletions

View File

@ -311,10 +311,3 @@ jobs:
with:
name: fome_bundle_${{matrix.build-target}}.zip
path: ./artifacts/fome_bundle_${{matrix.build-target}}.zip
# - name: Upload autoupdate bundle
# if: ${{ inputs.bundle || inputs.lts }}
# uses: actions/upload-artifact@v3
# with:
# name: fome_bundle_${{matrix.build-target}}_autoupdate.zip
# path: ./artifacts/fome_bundle_${{matrix.build-target}}_autoupdate.zip

View File

@ -3,7 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/autotest/autotest.iml" filepath="$PROJECT_DIR$/autotest/autotest.iml" />
<module fileurl="file://$PROJECT_DIR$/autoupdate/autoupdate.iml" filepath="$PROJECT_DIR$/autoupdate/autoupdate.iml" />
<module fileurl="file://$PROJECT_DIR$/../java_tools/configuration_definition/configuration_definition.iml" filepath="$PROJECT_DIR$/../java_tools/configuration_definition/configuration_definition.iml" />
<module fileurl="file://$PROJECT_DIR$/core_ui/core_ui.iml" filepath="$PROJECT_DIR$/core_ui/core_ui.iml" />
<module fileurl="file://$PROJECT_DIR$/../java_tools/enum_to_string/enum_to_string.iml" filepath="$PROJECT_DIR$/../java_tools/enum_to_string/enum_to_string.iml" />

View File

@ -1,54 +0,0 @@
plugins {
id 'java-library'
}
apply from: '../../java_tools/dependencies.gradle'
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
dependencies {
api global_libs.javaxJson
api project(':logging-api')
api project(':core_ui')
api project(':core_io')
api global_libs.jcip
api global_libs.json
// not 'api' since Android would use own implementation
implementation ts_plugin_libs.httpclient
// junit 4.13 does not mix well with httpclient :(
testImplementation group: 'junit', name: 'junit', version: '4.8.2'
testImplementation global_libs.mockito
}
compileJava.doLast {
jar.manifest {
attributes(
'Built-Date': new Date().toString()
)
}
}
// yes nasty sorry
evaluationDependsOn(':core_ui')
evaluationDependsOn(':core_io')
jar {
archivesBaseName = 'fome_autoupdate'
destinationDir = file("$rootDir/../java_console_binary")
// lame 'shadowJar' manual implementation causes logo.png to be include both as source ans outputs? weird
duplicatesStrategy = DuplicatesStrategy.WARN
from project.sourceSets.main.allSource
from project(':core_ui').sourceSets.main.output
from project(":core_io").sourceSets.main.output
manifest {
attributes(
'Main-Class': 'com.rusefi.autoupdate.Autoupdate'
)
}
}

View File

@ -1,220 +0,0 @@
package com.rusefi.autoupdate;
import com.rusefi.core.io.BundleUtil;
import com.rusefi.core.net.ConnectionAndMeta;
import com.rusefi.core.FileUtil;
import com.rusefi.core.preferences.storage.PersistentConfiguration;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.core.ui.FrameHelper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
public class Autoupdate {
private static final String LOGO_PATH = "/com/rusefi/";
private static final String LOGO = LOGO_PATH + "logo.png";
private static final String TITLE = "rusEFI Bundle Updater 20230130";
private static final String AUTOUPDATE_MODE = "autoupdate";
private static final String RUSEFI_CONSOLE_JAR = "fome_console.jar";
private static final String COM_RUSEFI_LAUNCHER = "com.rusefi.Launcher";
public static void main(String[] args) {
String bundleFullName = BundleUtil.readBundleFullName();
if (args.length > 0 && args[0].equalsIgnoreCase("release")) {
System.out.println("Release update requested");
handleBundle(bundleFullName, UpdateMode.ALWAYS, ConnectionAndMeta.BASE_URL_RELEASE);
} else {
UpdateMode mode = getMode();
if (mode != UpdateMode.NEVER) {
System.out.println("Snapshot requested");
if (bundleFullName != null) {
System.out.println("Handling " + bundleFullName);
String branchName = bundleFullName.split("\\.")[1];
if ( branchName.equals("snapshot") ) {
handleBundle(bundleFullName, mode, ConnectionAndMeta.BASE_URL_LATEST);
} else {
handleBundle(bundleFullName, mode, String.format(ConnectionAndMeta.BASE_URL_LTS, branchName));
}
} else {
System.err.println("ERROR: Autoupdate: unable to perform without bundleFullName");
}
} else {
System.out.println("Update mode: NEVER");
}
}
startConsole(args);
}
private static void startConsole(String[] args) {
try {
// we want to make sure that files are available to write so we use reflection to get lazy class initialization
System.out.println("Running rusEFI console with " + Arrays.toString(args));
// since we are overriding file we cannot just use static java classpath while launching
URLClassLoader jarClassLoader = AutoupdateUtil.getClassLoaderByJar(RUSEFI_CONSOLE_JAR);
Class mainClass = Class.forName(COM_RUSEFI_LAUNCHER, true, jarClassLoader);
Method mainMethod = mainClass.getMethod("main", args.getClass());
mainMethod.invoke(null, new Object[]{args});
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | MalformedURLException e) {
System.out.println(e);
}
}
private static UpdateMode getMode() {
String value = PersistentConfiguration.getConfig().getRoot().getProperty(AUTOUPDATE_MODE);
try {
return UpdateMode.valueOf(value);
} catch (Throwable e) {
return UpdateMode.ASK;
}
}
private static void handleBundle(String bundleFullName, UpdateMode mode, String baseUrl) {
try {
String boardName = bundleFullName.split("\\.")[2];
String zipFileName = "rusefi_bundle_" + boardName + "_autoupdate" + ".zip";
ConnectionAndMeta connectionAndMeta = new ConnectionAndMeta(zipFileName).invoke(baseUrl);
System.out.println("Remote file " + zipFileName);
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
if (AutoupdateUtil.hasExistingFile(zipFileName, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
System.out.println("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
return;
}
if (mode != UpdateMode.ALWAYS) {
boolean doUpdate = askUserIfUpdateIsDesired();
if (!doUpdate)
return;
}
// todo: user could have waited hours to respond to question above, we probably need to re-establish connection
long completeFileSize = connectionAndMeta.getCompleteFileSize();
long lastModified = connectionAndMeta.getLastModified();
System.out.println(bundleFullName + " " + completeFileSize + " bytes, last modified " + new Date(lastModified));
AutoupdateUtil.downloadAutoupdateFile(zipFileName, connectionAndMeta, TITLE);
File file = new File(zipFileName);
file.setLastModified(lastModified);
System.out.println("Downloaded " + file.length() + " bytes");
FileUtil.unzip(zipFileName, new File(".."));
} 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);
}
}
}
private static boolean askUserIfUpdateIsDesired() {
CountDownLatch frameClosed = new CountDownLatch(1);
if (AutoupdateUtil.runHeadless) {
// todo: command line ask for options
return true;
}
return askUserIfUpdateIsDesiredWithGUI(frameClosed);
}
private static boolean askUserIfUpdateIsDesiredWithGUI(CountDownLatch frameClosed) {
AtomicBoolean doUpdate = new AtomicBoolean();
FrameHelper frameHelper = new FrameHelper() {
@Override
protected void onWindowClosed() {
frameClosed.countDown();
}
};
JFrame frame = frameHelper.getFrame();
frame.setTitle(TITLE);
ImageIcon icon = AutoupdateUtil.loadIcon(LOGO);
if (icon != null)
frame.setIconImage(icon.getImage());
JPanel choice = new JPanel(new BorderLayout());
choice.add(new JLabel("Do you want to update bundle to latest version?"), BorderLayout.NORTH);
JPanel middle = new JPanel(new FlowLayout());
JButton never = new JButton("Never");
never.setBackground(Color.red);
never.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PersistentConfiguration.getConfig().getRoot().setProperty(AUTOUPDATE_MODE, UpdateMode.NEVER.toString());
frame.dispose();
}
});
middle.add(never);
JButton no = new JButton("No");
no.setBackground(Color.red);
no.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
middle.add(no);
JButton once = new JButton("Once");
once.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
doUpdate.set(true);
frame.dispose();
}
});
middle.add(once);
JButton always = new JButton("Always");
always.setBackground(Color.green);
always.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PersistentConfiguration.getConfig().getRoot().setProperty(AUTOUPDATE_MODE, UpdateMode.ALWAYS.toString());
doUpdate.set(true);
frame.dispose();
}
});
middle.add(always);
choice.add(middle, BorderLayout.CENTER);
frameHelper.showFrame(choice, true);
try {
frameClosed.await();
} catch (InterruptedException e) {
// ignore
}
return doUpdate.get();
}
enum UpdateMode {
ALWAYS,
NEVER,
ASK
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -1,36 +0,0 @@
#!/bin/bash
#
# broadcast.sh
# this file is part of rusEFI
#
while true
do
echo Starting network_connector
java -jar console/fome_console.jar network_connector
exit_status=$?
echo Exit code: ${exit_status}
# in java code that's UPDATE_SBC_EXIT_CODE magic number
if [ $exit_status -eq 15 ]; then
echo Connector software update to latest was requested
bin/update_bundle.sh
fi
# in java code that's UPDATE_RELEASE_SBC_EXIT_CODE magic number
if [ $exit_status -eq 17 ]; then
echo Connector software update to release was requested
bin/update_bundle_release.sh
fi
# in java code that's UPDATE_FIRMWARE_EXIT_CODE magic number
if [ $exit_status -eq 16 ]; then
echo Firmware update was requested
bin/update_bundle.sh
# todo: we need to start validating that SBC software matches board type, maybe update bundle type based on existing controller?
bin/dfu_switch_and_program.sh
fi
# in java code that's UPDATE_RELEASE_FIRMWARE_EXIT_CODE magic number
if [ $exit_status -eq 18 ]; then
echo Firmware update was requested
bin/update_bundle_release.sh
# todo: we need to start validating that SBC software matches board type, maybe update bundle type based on existing controller?
bin/dfu_switch_and_program.sh
fi
done

View File

@ -1,7 +0,0 @@
#!/bin/bash
cd console
java -jar fome_autoupdate.jar version
# https://github.com/rusefi/rusefi/issues/2601
chmod +x ../bin/*.sh

View File

@ -1,8 +0,0 @@
#!/bin/bash
cd console
java -jar fome_autoupdate.jar release
echo Release update done.
# https://github.com/rusefi/rusefi/issues/2601
chmod +x ../bin/*.sh

View File

@ -1,190 +0,0 @@
package com.rusefi.core.ui;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.autoupdate.ReportedIOException;
import com.rusefi.core.net.ConnectionAndMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.util.Date;
public class AutoupdateUtil {
public static final boolean runHeadless = Boolean.getBoolean("run_headless") || GraphicsEnvironment.isHeadless();
// todo: figure out a better way to work with absolute path
private static final String APPICON = "/appicon.png";
public static JComponent wrap(JComponent component) {
AutoupdateUtil.assertAwtThread();
JPanel result = new JPanel();
result.add(component);
return result;
}
static class ProgressView {
private final FrameHelper frameHelper;
private final 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);
frameHelper.showFrame(jProgressBar, true);
return new ProgressView(frameHelper, jProgressBar);
}
}
public static void downloadAutoupdateFile(String localZipFileName, ConnectionAndMeta connectionAndMeta, String title) throws IOException {
ProgressView view = createProgressView(title);
try {
ConnectionAndMeta.DownloadProgressListener listener = currentProgress -> {
if (!runHeadless) {
SwingUtilities.invokeLater(() -> view.progressBar.setValue(currentProgress));
}
};
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();
}
}
private static class DynamicForResourcesURLClassLoader extends URLClassLoader {
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent ) { super( urls, parent ); }
public DynamicForResourcesURLClassLoader( URL[] urls ) { super( urls ); }
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory ) { super( urls, parent, factory ); }
@Override
public void addURL( URL url ) {
super.addURL( url );
}
/**
* Let's here emulate Class.getResource() logic
* @param name resource name
* @return resource url
*/
@Nullable
@Override
public URL getResource( String name ) {
if ( name.startsWith( "/" ) )
name = name.substring( 1 );
return super.getResource( name );
}
}
private static final DynamicForResourcesURLClassLoader dynamicResourcesLoader = new DynamicForResourcesURLClassLoader( new URL[ 0 ], AutoupdateUtil.class.getClassLoader() );
@NotNull
public static URLClassLoader getClassLoaderByJar(String jar) throws MalformedURLException {
final URL jarURL = new File( jar ).toURI().toURL();
dynamicResourcesLoader.addURL( jarURL );
return new URLClassLoader(
new URL[]{ new File( jar ).toURI().toURL() },
dynamicResourcesLoader
);
}
public static void trueLayout(Component component) {
assertAwtThread();
if (component == null)
return;
component.invalidate();
component.validate();
component.repaint();
}
private static Window getSelectedWindow(Window[] windows) {
for (Window window : windows) {
if (window.isActive()) {
return window;
} else {
Window[] ownedWindows = window.getOwnedWindows();
if (ownedWindows != null) {
return getSelectedWindow(ownedWindows);
}
}
}
return null;
}
public static void assertAwtThread() {
if (!SwingUtilities.isEventDispatchThread()) {
Exception e = new IllegalStateException("Not on AWT thread but " + Thread.currentThread().getName());
StringBuilder trace = new StringBuilder(e + "\n");
for(StackTraceElement element : e.getStackTrace())
trace.append(element.toString()).append("\n");
SwingUtilities.invokeLater(() -> {
Window w = getSelectedWindow(Window.getWindows());
JOptionPane.showMessageDialog(w, trace, "Error", JOptionPane.ERROR_MESSAGE);
});
}
}
public static boolean hasExistingFile(String zipFileName, long completeFileSize, long lastModified) {
File file = new File(zipFileName);
System.out.println("We have " + file.length() + " " + new Date(file.lastModified()) + " " + file.getAbsolutePath());
return file.length() == completeFileSize && file.lastModified() == lastModified;
}
public static ImageIcon loadIcon( String strPath ) {
URL imgURL = dynamicResourcesLoader.getResource( strPath );
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
imgURL = dynamicResourcesLoader.getResource("/com/rusefi/" + strPath);
if (imgURL != null) {
return new ImageIcon(imgURL);
}
return null;
}
}
public static void setAppIcon(JFrame frame) {
ImageIcon icon = loadIcon(APPICON);
if (icon != null)
frame.setIconImage(icon.getImage());
}
public static void pack(Window window) {
trueLayout(window);
if (window != null)
window.pack();
trueLayout(window);
}
}

View File

@ -26,6 +26,7 @@ dependencies {
shadowJar {
archivesBaseName = 'fome_console'
destinationDir = file("$rootDir/../java_console_binary")
archiveClassifier = ''
manifest {

View File

@ -1,6 +1,5 @@
package com.rusefi;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.ui.UIContext;
import com.rusefi.ui.util.UiUtils;
import org.jetbrains.annotations.NotNull;
@ -24,7 +23,7 @@ abstract class CommandControl {
public CommandControl(UIContext uiContext, String labelText, String iconFileName, String buttonText, JComponent... components) {
this.uiContext = uiContext;
ImageIcon icon = AutoupdateUtil.loadIcon(iconFileName);
ImageIcon icon = UiUtils.loadIcon(iconFileName);
JPanel rightVerticalPanel = new JPanel(new VerticalFlowLayout());
rightVerticalPanel.add(new JLabel(labelText));
for (JComponent component : components)

View File

@ -14,8 +14,7 @@ import com.rusefi.ui.engine.EngineSnifferPanel;
import com.rusefi.ui.lua.LuaScriptPanel;
import com.rusefi.ui.util.DefaultExceptionHandler;
import com.rusefi.ui.util.JustOneInstance;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.ui.util.UiUtils;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@ -126,7 +125,7 @@ public class ConsoleUI {
}
});
AutoupdateUtil.setAppIcon(mainFrame.getFrame().getFrame());
UiUtils.setAppIcon(mainFrame.getFrame().getFrame());
log.info("showFrame");
mainFrame.getFrame().showFrame(tabbedPane.tabbedPane);
}

View File

@ -4,7 +4,6 @@ import com.devexperts.logging.Logging;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.autodetect.SerialAutoChecker;
import com.rusefi.core.io.BundleUtil;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.BaudRateHolder;
import com.rusefi.maintenance.DriverInstall;
@ -84,7 +83,7 @@ public class StartupFrame {
}
}
});
AutoupdateUtil.setAppIcon(frame);
UiUtils.setAppIcon(frame);
}
@NotNull
@ -248,7 +247,7 @@ public class StartupFrame {
} else {
logoName = LOGO;
}
return AutoupdateUtil.loadIcon(logoName);
return UiUtils.loadIcon(logoName);
}
private void connectButtonAction(JComboBox<String> comboSpeeds) {
@ -296,7 +295,7 @@ public class StartupFrame {
}
private Component createShowDeviceManagerButton() {
JButton showDeviceManager = new JButton(AutoupdateUtil.loadIcon("DeviceManager.png"));
JButton showDeviceManager = new JButton(UiUtils.loadIcon("DeviceManager.png"));
showDeviceManager.setMargin(new Insets(0, 0, 0, 0));
showDeviceManager.setToolTipText("Show Device Manager");
showDeviceManager.addActionListener(event -> {

View File

@ -3,7 +3,6 @@ package com.rusefi.maintenance;
import com.rusefi.Launcher;
import com.rusefi.SerialPortScanner;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.ui.StatusWindow;
import com.rusefi.ui.util.URLLabel;
import com.rusefi.ui.util.UiUtils;
@ -52,7 +51,7 @@ public class ProgramSelector {
mode.setSelectedItem(persistedMode);
JButton updateFirmware = new JButton("Update Firmware",
AutoupdateUtil.loadIcon("upload48.png"));
UiUtils.loadIcon("upload48.png"));
controls.add(updateFirmware);
updateFirmware.addActionListener(new ActionListener() {

View File

@ -2,7 +2,6 @@ package com.rusefi.ui;
import com.devexperts.logging.Logging;
import com.rusefi.AverageAnglesUtil;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.CommandQueue;
@ -49,21 +48,21 @@ public class RecentCommands {
private final static Map<String, Icon> COMMAND_ICONS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
static {
COMMAND_ICONS.put(STOPENGINE, AutoupdateUtil.loadIcon("stop.jpg"));
ImageIcon infoIcon = AutoupdateUtil.loadIcon("info.png");
COMMAND_ICONS.put(HELP, AutoupdateUtil.loadIcon("help.jpg"));
COMMAND_ICONS.put(STOPENGINE, UiUtils.loadIcon("stop.jpg"));
ImageIcon infoIcon = UiUtils.loadIcon("info.png");
COMMAND_ICONS.put(HELP, UiUtils.loadIcon("help.jpg"));
COMMAND_ICONS.put(SENSORINFO, infoIcon);
COMMAND_ICONS.put(CMD_TRIGGERINFO, AutoupdateUtil.loadIcon("trigger.jpg"));
COMMAND_ICONS.put(CMD_TRIGGERINFO, UiUtils.loadIcon("trigger.jpg"));
COMMAND_ICONS.put(IDLEINFO, infoIcon);
COMMAND_ICONS.put(TSINFO, infoIcon);
COMMAND_ICONS.put(MAPINFO, infoIcon);
COMMAND_ICONS.put(CANINFO, infoIcon);
COMMAND_ICONS.put(FUELINFO, infoIcon);
COMMAND_ICONS.put(SDINFO, AutoupdateUtil.loadIcon("sdinfo.jpg"));
COMMAND_ICONS.put(SDINFO, UiUtils.loadIcon("sdinfo.jpg"));
COMMAND_ICONS.put(FSIOINFO, infoIcon);
COMMAND_ICONS.put(PINS, infoIcon);
COMMAND_ICONS.put(Fields.CMD_WRITECONFIG, AutoupdateUtil.loadIcon("writeconfig.jpg"));
COMMAND_ICONS.put(SPEEDINFO, AutoupdateUtil.loadIcon("speedinfo.jpg"));
COMMAND_ICONS.put(Fields.CMD_WRITECONFIG, UiUtils.loadIcon("writeconfig.jpg"));
COMMAND_ICONS.put(SPEEDINFO, UiUtils.loadIcon("speedinfo.jpg"));
}
private final JPanel content = new JPanel(new GridLayout(NUMBER_OF_COMMANDS + 1, 1));
@ -149,7 +148,7 @@ public class RecentCommands {
public void run() {
content.removeAll();
JButton reset = new JButton(AutoupdateUtil.loadIcon("undo.jpg"));
JButton reset = new JButton(UiUtils.loadIcon("undo.jpg"));
reset.setContentAreaFilled(false);
reset.setFocusPainted(false);
reset.setBorder(BorderFactory.createEmptyBorder());

View File

@ -1,7 +1,7 @@
package com.rusefi.ui.util;
import com.rusefi.core.ui.AutoupdateUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.imageio.ImageIO;
import javax.swing.*;
@ -18,6 +18,11 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import static com.rusefi.ui.util.LocalizedMessages.CLEAR;
import static com.rusefi.ui.util.LocalizedMessages.PAUSE;
import static com.rusefi.ui.util.LocalizedMessages.RESUME;
@ -29,6 +34,10 @@ import static com.rusefi.ui.util.LocalizedMessages.RESUME;
public class UiUtils {
private static final String SAVE_IMAGE = "save image";
// todo: figure out a better way to work with absolute path
private static final String APPICON = "/appicon.png";
public static void saveImageWithPrompt(String fileName, Component parentForDialog, Component content) {
JFileChooser fc = getFileChooser(new FileNameExtensionFilter("PNG files", "png"));
fc.setSelectedFile(new File(fileName));
@ -57,7 +66,7 @@ public class UiUtils {
}
private static BufferedImage getScreenShot(Component component) {
AutoupdateUtil.assertAwtThread();
assertAwtThread();
// http://stackoverflow.com/questions/5853879/swing-obtain-image-of-jframe/5853992
BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
// call the Component's paint method, using
@ -93,7 +102,40 @@ public class UiUtils {
* todo: one 'trueXXX' method should be enough, which one?
*/
public static void trueLayout(Component component) {
AutoupdateUtil.trueLayout(component);
assertAwtThread();
if (component == null)
return;
component.invalidate();
component.validate();
component.repaint();
}
private static void assertAwtThread() {
if (!SwingUtilities.isEventDispatchThread()) {
Exception e = new IllegalStateException("Not on AWT thread but " + Thread.currentThread().getName());
StringBuilder trace = new StringBuilder(e + "\n");
for(StackTraceElement element : e.getStackTrace())
trace.append(element.toString()).append("\n");
SwingUtilities.invokeLater(() -> {
Window w = getSelectedWindow(Window.getWindows());
JOptionPane.showMessageDialog(w, trace, "Error", JOptionPane.ERROR_MESSAGE);
});
}
}
private static Window getSelectedWindow(Window[] windows) {
for (Window window : windows) {
if (window.isActive()) {
return window;
} else {
Window[] ownedWindows = window.getOwnedWindows();
if (ownedWindows != null) {
return getSelectedWindow(ownedWindows);
}
}
}
return null;
}
public static java.util.List<Component> getAllComponents(final Container c) {
@ -121,7 +163,10 @@ public class UiUtils {
}
public static JComponent wrap(JComponent component) {
return AutoupdateUtil.wrap(component);
assertAwtThread();
JPanel result = new JPanel();
result.add(component);
return result;
}
public static JButton createSaveImageButton() {
@ -191,4 +236,59 @@ public class UiUtils {
});
return copy;
}
private static class DynamicForResourcesURLClassLoader extends URLClassLoader {
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent ) { super( urls, parent ); }
public DynamicForResourcesURLClassLoader( URL[] urls ) { super( urls ); }
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory ) { super( urls, parent, factory ); }
@Override
public void addURL( URL url ) {
super.addURL( url );
}
/**
* Let's here emulate Class.getResource() logic
* @param name resource name
* @return resource url
*/
@Nullable
@Override
public URL getResource( String name ) {
if ( name.startsWith( "/" ) )
name = name.substring( 1 );
return super.getResource( name );
}
}
private static final DynamicForResourcesURLClassLoader dynamicResourcesLoader = new DynamicForResourcesURLClassLoader( new URL[ 0 ], UiUtils.class.getClassLoader() );
@NotNull
public static URLClassLoader getClassLoaderByJar(String jar) throws MalformedURLException {
final URL jarURL = new File( jar ).toURI().toURL();
dynamicResourcesLoader.addURL( jarURL );
return new URLClassLoader(
new URL[]{ new File( jar ).toURI().toURL() },
dynamicResourcesLoader
);
}
public static void setAppIcon(JFrame frame) {
ImageIcon icon = loadIcon(APPICON);
if (icon != null)
frame.setIconImage(icon.getImage());
}
public static ImageIcon loadIcon( String strPath ) {
URL imgURL = dynamicResourcesLoader.getResource( strPath );
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
imgURL = dynamicResourcesLoader.getResource("/com/rusefi/" + strPath);
if (imgURL != null) {
return new ImageIcon(imgURL);
}
return null;
}
}
}

View File

@ -10,7 +10,6 @@
<option name="modules">
<set>
<option value="$PROJECT_DIR$/../java_console/autotest" />
<option value="$PROJECT_DIR$/../java_console/autoupdate" />
<option value="$PROJECT_DIR$/../java_console/core_ui" />
<option value="$PROJECT_DIR$/../java_console/inifile" />
<option value="$PROJECT_DIR$/../java_console/io" />

View File

@ -2,7 +2,6 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../../java_console/autoupdate/autoupdate.iml" filepath="$PROJECT_DIR$/../../java_console/autoupdate/autoupdate.iml" />
<module fileurl="file://$PROJECT_DIR$/configuration_definition.iml" filepath="$PROJECT_DIR$/configuration_definition.iml" />
<module fileurl="file://$PROJECT_DIR$/../enum_to_string/enum_to_string.iml" filepath="$PROJECT_DIR$/../enum_to_string/enum_to_string.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/inifile/inifile.iml" filepath="$PROJECT_DIR$/../../java_console/inifile/inifile.iml" />

View File

@ -16,8 +16,6 @@ include ':config_definition_base'
project(':config_definition_base').projectDir = new File('configuration_definition_base')
include ':config_definition'
project(':config_definition').projectDir = new File('configuration_definition')
include ':autoupdate'
project(':autoupdate').projectDir = new File('../java_console/autoupdate')
include ':shared_ui'
project(':shared_ui').projectDir = new File('../java_console/shared_ui')
include ':ecu_io'

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>true</dontWrapJar>
<headerType>gui</headerType>
<jar>fome_autoupdate.jar</jar>
<outfile>fome_autoupdate.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>favicon.ico</icon>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</launch4jConfig>

View File

@ -5,7 +5,6 @@
#
FULL_BUNDLE_FILE="${BUNDLE_FULL_NAME}.zip"
UPDATE_BUNDLE_FILE="${BUNDLE_FULL_NAME}_autoupdate.zip"
echo "${BUNDLE_FULL_NAME}: Packaging temp/$FULL_BUNDLE_FILE file"
@ -46,7 +45,6 @@ else
cp $RUSEFI_CONSOLE_SETTINGS $CONSOLE_FOLDER
fi
cp java_console_binary/fome_autoupdate.jar $CONSOLE_FOLDER
cp java_console_binary/fome_console.jar $CONSOLE_FOLDER
cp simulator/build/fome_simulator.exe $CONSOLE_FOLDER
cp misc/console_launcher/fome_*.exe $CONSOLE_FOLDER
@ -121,35 +119,10 @@ mkdir -p artifacts
mv temp/$FULL_BUNDLE_FILE artifacts
echo "Removing static content from ${CONSOLE_FOLDER} and $DRIVERS_FOLDER"
rm -rf $CONSOLE_FOLDER/fome_autoupdate.exe
rm -rf $CONSOLE_FOLDER/fome_console.exe
rm -rf $CONSOLE_FOLDER/DfuSe
rm -rf $DRIVERS_FOLDER
# for autoupdate we do not want the unique folder name with timestamp
cd $FOLDER
zip -r ../$UPDATE_BUNDLE_FILE *
cd ..
ls -l $UPDATE_BUNDLE_FILE
if [ -n "$RUSEFI_SSH_USER" ]; then
retVal=0
if [ "$2" = "true" ]; then
tar -czf - $UPDATE_BUNDLE_FILE | sshpass -p $RUSEFI_SSH_PASS ssh -o StrictHostKeyChecking=no $RUSEFI_SSH_USER@$RUSEFI_SSH_SERVER "mkdir -p build_server/lts/$1/autoupdate; tar -xzf - -C build_server/lts/$1/autoupdate"
retVal=$?
else
tar -czf - $UPDATE_BUNDLE_FILE | sshpass -p $RUSEFI_SSH_PASS ssh -o StrictHostKeyChecking=no $RUSEFI_SSH_USER@$RUSEFI_SSH_SERVER "mkdir -p build_server/autoupdate; tar -xzf - -C build_server/autoupdate"
retVal=$?
fi
if [ $retVal -ne 0 ]; then
echo "autoupdate upload failed"
exit 1
fi
else
echo "Upload not configured"
fi
cd ..
mv temp/$UPDATE_BUNDLE_FILE artifacts
echo "$SCRIPT_NAME: We are back in root directory"
pwd