TS plugin

This commit is contained in:
rusefi 2020-06-17 22:14:22 -04:00
parent fba3dc6186
commit cfd6f06ae5
5 changed files with 55 additions and 13 deletions

View File

@ -70,7 +70,7 @@ public class Autoupdate {
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(zipFileName).invoke();
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
if (hasExistingFile(zipFileName, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
if (AutoupdateUtil.hasExistingFile(zipFileName, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
System.out.println("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
return;
}
@ -88,7 +88,7 @@ public class Autoupdate {
System.out.println(bundleFullName + " " + completeFileSize + " bytes, last modified " + new Date(lastModified));
AutoupdateUtil.downloadAutoupdateFile(zipFileName, httpConnection, completeFileSize, TITLE);
AutoupdateUtil.downloadAutoupdateFile(zipFileName, connectionAndMeta, TITLE);
File file = new File(zipFileName);
file.setLastModified(lastModified);
@ -180,12 +180,6 @@ public class Autoupdate {
return doUpdate.get();
}
private 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()));
return file.length() == completeFileSize && file.lastModified() == lastModified;
}
public static String readBundleFullName() {
try {
BufferedReader r = new BufferedReader(new FileReader(BUNDLE_NAME_FILE));

View File

@ -10,6 +10,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
@ -19,7 +20,9 @@ public class AutoupdateUtil {
private static final int BUFFER_SIZE = 32 * 1024;
private static final int STEPS = 1000;
public static void downloadAutoupdateFile(String localZipFileName, HttpURLConnection httpConnection, long completeFileSize, String title) throws IOException {
public static void downloadAutoupdateFile(String localZipFileName, ConnectionAndMeta connectionAndMeta, String title) throws IOException {
HttpURLConnection httpConnection = connectionAndMeta.httpConnection;
long completeFileSize = connectionAndMeta.completeFileSize;
Objects.requireNonNull(httpConnection, "httpConnection");
BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream());
FileOutputStream fos = new FileOutputStream(localZipFileName);
@ -62,6 +65,7 @@ public class AutoupdateUtil {
}
bout.close();
in.close();
new File(localZipFileName).setLastModified(connectionAndMeta.lastModified);
if (!runHeadless) {
frameHelper.getFrame().dispose();
@ -84,6 +88,12 @@ public class AutoupdateUtil {
component.repaint();
}
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()));
return file.length() == completeFileSize && file.lastModified() == lastModified;
}
public static class ConnectionAndMeta {
private String zipFileName;
private HttpURLConnection httpConnection;

View File

@ -49,6 +49,6 @@
</target>
<target name="body_local_install" depends="jar">
<copy file="${jar_file}" todir="${user.home}/.efianalytics/TunerStudio/plugins"/>
<copy file="${jar_file}" todir="${user.home}/.rusEFI/"/>
</target>
</project>

View File

@ -25,6 +25,7 @@ import java.util.jar.Manifest;
* TsPlugin launcher creates an instance of this class via reflection.
*/
public class PluginEntry implements TsPluginBody {
public static final String BUILT_DATE = "Built-Date";
private final AuthTokenPanel tokenPanel = new AuthTokenPanel();
private final JComponent content = new JPanel();
@ -148,10 +149,16 @@ public class PluginEntry implements TsPluginBody {
Manifest manifest = new Manifest(stream);
Attributes attributes = manifest.getMainAttributes();
System.out.println("Attributed " + attributes);
System.out.println("Attributed " + attributes.keySet());
System.out.println("Attributed " + attributes.getValue("Class-Path"));
System.out.println("Attributed " + attributes.getValue("Main-Class"));
String result = attributes.getValue("Built-Date");
String result = attributes.getValue(BUILT_DATE);
System.out.println(BUILT_DATE + " " + result);
return result == null ? "Unknown version" : result;
} catch (IOException e) {
e.printStackTrace();
return "Unknown version";
}
}

View File

@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.util.Date;
import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
@ -26,8 +27,11 @@ public class Updater {
content.add(new JLabel("" + VERSION));
String version = null;
if (new File(LOCAL_JAR_FILE_NAME).exists()) {
long localJarTimestamp = 0;
File localFile = new File(LOCAL_JAR_FILE_NAME);
if (localFile.exists()) {
version = getVersion();
}
JButton download = new JButton("Download latest");
@ -47,6 +51,30 @@ public class Updater {
content.add(run);
}
new Thread(new Runnable() {
@Override
public void run() {
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = null;
try {
connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(PLUGIN_BODY_JAR).invoke();
} catch (IOException e) {
e.printStackTrace();
return;
}
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
if (AutoupdateUtil.hasExistingFile(LOCAL_JAR_FILE_NAME, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
System.out.println("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
SwingUtilities.invokeLater(() -> {
download.setText("We have latest plugin version");
download.setEnabled(false);
});
return;
}
}
}).start();
download.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
@ -78,7 +106,7 @@ public class Updater {
try {
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(PLUGIN_BODY_JAR).invoke();
AutoupdateUtil.downloadAutoupdateFile(LOCAL_JAR_FILE_NAME, connectionAndMeta.getHttpConnection(), connectionAndMeta.getCompleteFileSize(),
AutoupdateUtil.downloadAutoupdateFile(LOCAL_JAR_FILE_NAME, connectionAndMeta,
TITLE);
startPlugin();
@ -109,6 +137,9 @@ public class Updater {
content.removeAll();
content.add(instance.getContent());
AutoupdateUtil.trueLayout(content.getParent());
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(content);
topFrame.pack();
AutoupdateUtil.trueLayout(topFrame);
}
public JPanel getContent() {