TS plugin
This commit is contained in:
parent
fba3dc6186
commit
cfd6f06ae5
|
@ -70,7 +70,7 @@ public class Autoupdate {
|
||||||
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(zipFileName).invoke();
|
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(zipFileName).invoke();
|
||||||
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
|
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()));
|
System.out.println("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class Autoupdate {
|
||||||
|
|
||||||
System.out.println(bundleFullName + " " + completeFileSize + " bytes, last modified " + new Date(lastModified));
|
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 file = new File(zipFileName);
|
||||||
file.setLastModified(lastModified);
|
file.setLastModified(lastModified);
|
||||||
|
@ -180,12 +180,6 @@ public class Autoupdate {
|
||||||
return doUpdate.get();
|
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() {
|
public static String readBundleFullName() {
|
||||||
try {
|
try {
|
||||||
BufferedReader r = new BufferedReader(new FileReader(BUNDLE_NAME_FILE));
|
BufferedReader r = new BufferedReader(new FileReader(BUNDLE_NAME_FILE));
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
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 BUFFER_SIZE = 32 * 1024;
|
||||||
private static final int STEPS = 1000;
|
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");
|
Objects.requireNonNull(httpConnection, "httpConnection");
|
||||||
BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream());
|
BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream());
|
||||||
FileOutputStream fos = new FileOutputStream(localZipFileName);
|
FileOutputStream fos = new FileOutputStream(localZipFileName);
|
||||||
|
@ -62,6 +65,7 @@ public class AutoupdateUtil {
|
||||||
}
|
}
|
||||||
bout.close();
|
bout.close();
|
||||||
in.close();
|
in.close();
|
||||||
|
new File(localZipFileName).setLastModified(connectionAndMeta.lastModified);
|
||||||
|
|
||||||
if (!runHeadless) {
|
if (!runHeadless) {
|
||||||
frameHelper.getFrame().dispose();
|
frameHelper.getFrame().dispose();
|
||||||
|
@ -84,6 +88,12 @@ public class AutoupdateUtil {
|
||||||
component.repaint();
|
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 {
|
public static class ConnectionAndMeta {
|
||||||
private String zipFileName;
|
private String zipFileName;
|
||||||
private HttpURLConnection httpConnection;
|
private HttpURLConnection httpConnection;
|
||||||
|
|
|
@ -49,6 +49,6 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="body_local_install" depends="jar">
|
<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>
|
</target>
|
||||||
</project>
|
</project>
|
|
@ -25,6 +25,7 @@ import java.util.jar.Manifest;
|
||||||
* TsPlugin launcher creates an instance of this class via reflection.
|
* TsPlugin launcher creates an instance of this class via reflection.
|
||||||
*/
|
*/
|
||||||
public class PluginEntry implements TsPluginBody {
|
public class PluginEntry implements TsPluginBody {
|
||||||
|
public static final String BUILT_DATE = "Built-Date";
|
||||||
private final AuthTokenPanel tokenPanel = new AuthTokenPanel();
|
private final AuthTokenPanel tokenPanel = new AuthTokenPanel();
|
||||||
private final JComponent content = new JPanel();
|
private final JComponent content = new JPanel();
|
||||||
|
|
||||||
|
@ -148,10 +149,16 @@ public class PluginEntry implements TsPluginBody {
|
||||||
Manifest manifest = new Manifest(stream);
|
Manifest manifest = new Manifest(stream);
|
||||||
|
|
||||||
Attributes attributes = manifest.getMainAttributes();
|
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;
|
return result == null ? "Unknown version" : result;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
return "Unknown version";
|
return "Unknown version";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
|
import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
|
||||||
|
|
||||||
|
@ -26,8 +27,11 @@ public class Updater {
|
||||||
content.add(new JLabel("" + VERSION));
|
content.add(new JLabel("" + VERSION));
|
||||||
|
|
||||||
String version = null;
|
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();
|
version = getVersion();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JButton download = new JButton("Download latest");
|
JButton download = new JButton("Download latest");
|
||||||
|
@ -47,6 +51,30 @@ public class Updater {
|
||||||
content.add(run);
|
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() {
|
download.addActionListener(new AbstractAction() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -78,7 +106,7 @@ public class Updater {
|
||||||
try {
|
try {
|
||||||
AutoupdateUtil.ConnectionAndMeta connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(PLUGIN_BODY_JAR).invoke();
|
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);
|
TITLE);
|
||||||
|
|
||||||
startPlugin();
|
startPlugin();
|
||||||
|
@ -109,6 +137,9 @@ public class Updater {
|
||||||
content.removeAll();
|
content.removeAll();
|
||||||
content.add(instance.getContent());
|
content.add(instance.getContent());
|
||||||
AutoupdateUtil.trueLayout(content.getParent());
|
AutoupdateUtil.trueLayout(content.getParent());
|
||||||
|
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(content);
|
||||||
|
topFrame.pack();
|
||||||
|
AutoupdateUtil.trueLayout(topFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getContent() {
|
public JPanel getContent() {
|
||||||
|
|
Loading…
Reference in New Issue