rusEFI console to compare current bundle against auto-DFU bundle #3266

progress
This commit is contained in:
rusefillc 2021-09-25 22:29:01 -04:00
parent 406107830b
commit a9afae7977
3 changed files with 77 additions and 13 deletions

View File

@ -0,0 +1,14 @@
package com.rusefi;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SignatureHelperTest {
@Test
public void parseSignature() {
RusEfiSignature s = SignatureHelper.parse("rusEFI 2021.09.22.all.3378169541");
assertEquals("all", s.getBundle());
}
}

View File

@ -0,0 +1,38 @@
package com.rusefi;
public class RusEfiSignature {
private final String year;
private final String month;
private final String day;
private final String bundle;
private final String hash;
public RusEfiSignature(String year, String month, String day, String bundle, String hash) {
this.year = year;
this.month = month;
this.day = day;
this.bundle = bundle;
this.hash = hash;
}
public String getYear() {
return year;
}
public String getMonth() {
return month;
}
public String getDay() {
return day;
}
public String getBundle() {
return bundle;
}
public String getHash() {
return hash;
}
}

View File

@ -18,21 +18,16 @@ public class SignatureHelper {
private static final char SLASH = '/';
public static Pair<String, String> getUrl(String signature) {
if (signature == null || !signature.startsWith(PREFIX))
return null;
signature = signature.substring(PREFIX.length()).trim();
String[] elements = signature.split("\\.");
if (elements.length != 5)
RusEfiSignature s = parse(signature);
if (s == null)
return null;
String year = elements[0];
String month = elements[1];
String day = elements[2];
String bundle = elements[3];
String hash = elements[4];
String fileName = hash + ".ini";
return new Pair("https://rusefi.com/online/ini/rusefi/" + year + SLASH + month + SLASH + day + SLASH + bundle + SLASH + fileName, fileName);
String fileName = s.getHash() + ".ini";
return new Pair("https://rusefi.com/online/ini/rusefi/" + s.getYear() + SLASH +
s.getMonth() + SLASH +
s.getDay() + SLASH +
s.getBundle() + SLASH +
fileName, fileName);
}
public static String downloadIfNotAvailable(Pair<String, String> p) {
@ -56,4 +51,21 @@ public class SignatureHelper {
return null;
}
}
public static RusEfiSignature parse(String signature) {
if (signature == null || !signature.startsWith(PREFIX))
return null;
signature = signature.substring(PREFIX.length()).trim();
String[] elements = signature.split("\\.");
if (elements.length != 5)
return null;
String year = elements[0];
String month = elements[1];
String day = elements[2];
String bundle = elements[3];
String hash = elements[4];
return new RusEfiSignature(year, month, day, bundle, hash);
}
}