autoupdate DOES IT WORK?!
This commit is contained in:
parent
9679d5623d
commit
7a5fd95bf0
|
@ -9,7 +9,9 @@ import java.io.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
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;
|
||||||
|
@ -20,10 +22,12 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||||
|
|
||||||
public class Autoupdate {
|
public class Autoupdate {
|
||||||
private static final String TITLE = "rusEFI Bundle Updater 20200607";
|
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 String AUTOUPDATE_MODE = "autoupdate";
|
||||||
private static final int BUFFER_SIZE = 32 * 1024;
|
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) {
|
public static void main(String[] args) {
|
||||||
UpdateMode mode = getMode();
|
UpdateMode mode = getMode();
|
||||||
|
@ -33,8 +37,9 @@ public class Autoupdate {
|
||||||
System.out.println("Handling " + bundleFullName);
|
System.out.println("Handling " + bundleFullName);
|
||||||
handleBundle(bundleFullName, mode);
|
handleBundle(bundleFullName, mode);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Update mode: NEVER");
|
||||||
}
|
}
|
||||||
|
|
||||||
startConsole(args);
|
startConsole(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +47,16 @@ public class Autoupdate {
|
||||||
try {
|
try {
|
||||||
// we want to make sure that files are available to write so we use reflection to get lazy class initialization
|
// 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");
|
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());
|
Method mainMethod = mainClass.getMethod("main", args.getClass());
|
||||||
mainMethod.invoke(null, new Object[]{args});
|
mainMethod.invoke(null, new Object[]{args});
|
||||||
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | MalformedURLException e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +98,7 @@ public class Autoupdate {
|
||||||
file.setLastModified(lastModified);
|
file.setLastModified(lastModified);
|
||||||
System.out.println("Downloaded " + file.length() + " bytes");
|
System.out.println("Downloaded " + file.length() + " bytes");
|
||||||
|
|
||||||
unzip(zipFileName, ".");
|
unzip(zipFileName, "..");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e);
|
System.err.println(e);
|
||||||
}
|
}
|
||||||
|
@ -219,6 +230,7 @@ public class Autoupdate {
|
||||||
return null; // just paranoia check
|
return null; // just paranoia check
|
||||||
return fullName;
|
return fullName;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error reading " + BUNDLE_NAME_FILE);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +242,19 @@ public class Autoupdate {
|
||||||
ZipEntry zipEntry = zis.getNextEntry();
|
ZipEntry zipEntry = zis.getNextEntry();
|
||||||
while (zipEntry != null) {
|
while (zipEntry != null) {
|
||||||
File newFile = newFile(destDir, zipEntry);
|
File newFile = newFile(destDir, zipEntry);
|
||||||
|
if (newFile.isDirectory()) {
|
||||||
|
System.out.println("Nothing to do for directory " + newFile);
|
||||||
|
} else {
|
||||||
|
unzipFile(buffer, zis, newFile);
|
||||||
|
}
|
||||||
|
zipEntry = zis.getNextEntry();
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
zis.close();
|
||||||
|
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);
|
System.out.println("Unzipping " + newFile);
|
||||||
FileOutputStream fos = new FileOutputStream(newFile);
|
FileOutputStream fos = new FileOutputStream(newFile);
|
||||||
int len;
|
int len;
|
||||||
|
@ -237,11 +262,6 @@ public class Autoupdate {
|
||||||
fos.write(buffer, 0, len);
|
fos.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
fos.close();
|
fos.close();
|
||||||
zipEntry = zis.getNextEntry();
|
|
||||||
}
|
|
||||||
zis.closeEntry();
|
|
||||||
zis.close();
|
|
||||||
System.out.println("Unzip " + zipFileName + " to " + destPath + " worked!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
||||||
|
|
Binary file not shown.
|
@ -2,7 +2,7 @@
|
||||||
<launch4jConfig>
|
<launch4jConfig>
|
||||||
<dontWrapJar>true</dontWrapJar>
|
<dontWrapJar>true</dontWrapJar>
|
||||||
<headerType>gui</headerType>
|
<headerType>gui</headerType>
|
||||||
<jar></jar>
|
<jar>rusefi_autoupdate.jar</jar>
|
||||||
<outfile>c:\stuff\rusefi\misc\console_launcher\rusefi_autoupdate.exe</outfile>
|
<outfile>c:\stuff\rusefi\misc\console_launcher\rusefi_autoupdate.exe</outfile>
|
||||||
<errTitle></errTitle>
|
<errTitle></errTitle>
|
||||||
<cmdLine></cmdLine>
|
<cmdLine></cmdLine>
|
||||||
|
@ -14,11 +14,6 @@
|
||||||
<restartOnCrash>false</restartOnCrash>
|
<restartOnCrash>false</restartOnCrash>
|
||||||
<manifest></manifest>
|
<manifest></manifest>
|
||||||
<icon>c:\stuff\rusefi\misc\console_launcher\favicon.ico</icon>
|
<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>
|
<jre>
|
||||||
<path></path>
|
<path></path>
|
||||||
<bundledJre64Bit>false</bundledJre64Bit>
|
<bundledJre64Bit>false</bundledJre64Bit>
|
||||||
|
|
Loading…
Reference in New Issue