autoupdate DOES IT WORK?!

This commit is contained in:
rusefi 2020-06-07 00:49:38 -04:00
parent 9679d5623d
commit 7a5fd95bf0
3 changed files with 33 additions and 18 deletions

View File

@ -9,7 +9,9 @@ import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@ -20,10 +22,12 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class Autoupdate {
private static final String TITLE = "rusEFI Bundle Updater 20200607";
private static final String BUNDLE_NAME_FILE = "bundle_name.ini";
private static final String BUNDLE_NAME_FILE = "../bundle_name.ini";
private static final String AUTOUPDATE_MODE = "autoupdate";
private static final int BUFFER_SIZE = 32 * 1024;
private static final int STEPS = 100000;
private static final int STEPS = 1000;
private static final String RUSEFI_CONSOLE_JAR = "rusefi_console.jar";
private static final String COM_RUSEFI_LAUNCHER = "com.rusefi.Launcher";
public static void main(String[] args) {
UpdateMode mode = getMode();
@ -33,8 +37,9 @@ public class Autoupdate {
System.out.println("Handling " + bundleFullName);
handleBundle(bundleFullName, mode);
}
} else {
System.out.println("Update mode: NEVER");
}
startConsole(args);
}
@ -42,10 +47,16 @@ public class Autoupdate {
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");
Class mainClass = Class.forName("com.rusefi.Launcher");
// since we are overriding file we cannot just use static java classpath while launching
URLClassLoader child = new URLClassLoader(
new URL[]{new File(RUSEFI_CONSOLE_JAR).toURI().toURL()},
Autoupdate.class.getClassLoader()
);
Class mainClass = Class.forName(COM_RUSEFI_LAUNCHER, true, child);
Method mainMethod = mainClass.getMethod("main", args.getClass());
mainMethod.invoke(null, new Object[]{args});
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | MalformedURLException e) {
System.out.println(e);
}
}
@ -87,7 +98,7 @@ public class Autoupdate {
file.setLastModified(lastModified);
System.out.println("Downloaded " + file.length() + " bytes");
unzip(zipFileName, ".");
unzip(zipFileName, "..");
} catch (IOException e) {
System.err.println(e);
}
@ -219,6 +230,7 @@ public class Autoupdate {
return null; // just paranoia check
return fullName;
} catch (IOException e) {
System.err.println("Error reading " + BUNDLE_NAME_FILE);
return null;
}
}
@ -230,13 +242,11 @@ public class Autoupdate {
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
System.out.println("Unzipping " + newFile);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
if (newFile.isDirectory()) {
System.out.println("Nothing to do for directory " + newFile);
} else {
unzipFile(buffer, zis, newFile);
}
fos.close();
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
@ -244,6 +254,16 @@ public class Autoupdate {
System.out.println("Unzip " + zipFileName + " to " + destPath + " worked!");
}
private static void unzipFile(byte[] buffer, ZipInputStream zis, File newFile) throws IOException {
System.out.println("Unzipping " + newFile);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());

View File

@ -2,7 +2,7 @@
<launch4jConfig>
<dontWrapJar>true</dontWrapJar>
<headerType>gui</headerType>
<jar></jar>
<jar>rusefi_autoupdate.jar</jar>
<outfile>c:\stuff\rusefi\misc\console_launcher\rusefi_autoupdate.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
@ -14,11 +14,6 @@
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>c:\stuff\rusefi\misc\console_launcher\favicon.ico</icon>
<classPath>
<mainClass>com.rusefi.autoupdate.Autoupdate</mainClass>
<cp>rusefi_console.jar</cp>
<cp>rusefi_autoupdate.jar</cp>
</classPath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>