headless autoupdate
This commit is contained in:
parent
69395b4691
commit
423e913ad5
|
@ -15,6 +15,7 @@ import java.net.URLClassLoader;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ public class Autoupdate {
|
||||||
private static final int STEPS = 1000;
|
private static final int STEPS = 1000;
|
||||||
private static final String RUSEFI_CONSOLE_JAR = "rusefi_console.jar";
|
private static final String RUSEFI_CONSOLE_JAR = "rusefi_console.jar";
|
||||||
private static final String COM_RUSEFI_LAUNCHER = "com.rusefi.Launcher";
|
private static final String COM_RUSEFI_LAUNCHER = "com.rusefi.Launcher";
|
||||||
|
private static final boolean runHeadless = Boolean.getBoolean("run_headless") || GraphicsEnvironment.isHeadless();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
UpdateMode mode = getMode();
|
UpdateMode mode = getMode();
|
||||||
|
@ -115,13 +117,17 @@ public class Autoupdate {
|
||||||
|
|
||||||
int printedPercentage = 0;
|
int printedPercentage = 0;
|
||||||
|
|
||||||
FrameHelper frameHelper = new FrameHelper();
|
FrameHelper frameHelper = null;
|
||||||
frameHelper.getFrame().setTitle(TITLE);
|
final AtomicReference<JProgressBar> jProgressBarAtomicReference = new AtomicReference<>();
|
||||||
|
if (!runHeadless) {
|
||||||
|
frameHelper = new FrameHelper();
|
||||||
|
JProgressBar jProgressBar = new JProgressBar();
|
||||||
|
|
||||||
final JProgressBar jProgressBar = new JProgressBar();
|
frameHelper.getFrame().setTitle(TITLE);
|
||||||
jProgressBar.setMaximum(STEPS);
|
jProgressBar.setMaximum(STEPS);
|
||||||
|
jProgressBarAtomicReference.set(jProgressBar);
|
||||||
frameHelper.showFrame(jProgressBar, true);
|
frameHelper.showFrame(jProgressBar, true);
|
||||||
|
}
|
||||||
|
|
||||||
while ((newDataSize = in.read(data, 0, BUFFER_SIZE)) >= 0) {
|
while ((newDataSize = in.read(data, 0, BUFFER_SIZE)) >= 0) {
|
||||||
downloadedFileSize += newDataSize;
|
downloadedFileSize += newDataSize;
|
||||||
|
@ -135,20 +141,33 @@ public class Autoupdate {
|
||||||
printedPercentage = currentPercentage;
|
printedPercentage = currentPercentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> jProgressBar.setValue(currentProgress));
|
if (!runHeadless) {
|
||||||
|
SwingUtilities.invokeLater(() -> jProgressBarAtomicReference.get().setValue(currentProgress));
|
||||||
|
}
|
||||||
|
|
||||||
bout.write(data, 0, newDataSize);
|
bout.write(data, 0, newDataSize);
|
||||||
}
|
}
|
||||||
bout.close();
|
bout.close();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
frameHelper.getFrame().dispose();
|
if (!runHeadless) {
|
||||||
|
frameHelper.getFrame().dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean askUserIfUpdateIsDesired() {
|
private static boolean askUserIfUpdateIsDesired() {
|
||||||
AtomicBoolean doUpdate = new AtomicBoolean();
|
AtomicBoolean doUpdate = new AtomicBoolean();
|
||||||
CountDownLatch frameClosed = new CountDownLatch(1);
|
CountDownLatch frameClosed = new CountDownLatch(1);
|
||||||
|
|
||||||
|
if (runHeadless) {
|
||||||
|
// todo: command line ask for options
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return askUserIfUpdateIsDesiredWithGUI(doUpdate, frameClosed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean askUserIfUpdateIsDesiredWithGUI(AtomicBoolean doUpdate, CountDownLatch frameClosed) {
|
||||||
FrameHelper frameHelper = new FrameHelper() {
|
FrameHelper frameHelper = new FrameHelper() {
|
||||||
@Override
|
@Override
|
||||||
protected void onWindowClosed() {
|
protected void onWindowClosed() {
|
||||||
|
@ -205,7 +224,6 @@ public class Autoupdate {
|
||||||
});
|
});
|
||||||
middle.add(always);
|
middle.add(always);
|
||||||
|
|
||||||
|
|
||||||
choice.add(middle, BorderLayout.CENTER);
|
choice.add(middle, BorderLayout.CENTER);
|
||||||
|
|
||||||
frameHelper.showFrame(choice, true);
|
frameHelper.showFrame(choice, true);
|
||||||
|
|
Loading…
Reference in New Issue