|
@@ -32,13 +32,23 @@ public class FirmwareAutoDumper
|
|
|
public static PrintStream dummydownloadfake = null;
|
|
|
public static HashMap<String,FirmwareVersion> supprCache = new HashMap<>();
|
|
|
|
|
|
+ private static final String[] hackfixsuffixes = new String[]
|
|
|
+ {"-rc","rc","-build","build"};
|
|
|
+
|
|
|
+ private static final String[][] indexes = new String[][]
|
|
|
+ {{
|
|
|
+ "main","http://firmware.sena.com/senabluetoothmanager/Firmware"},{
|
|
|
+ "harley","http://firmware.sena.com/senabluetoothmanager/harleyFirmware"},{
|
|
|
+ "cradlemain","http://firmware.sena.com/senabluetoothmanager/WiFiCradle/bt_img/Firmware"},{
|
|
|
+ "cradleharley","http://firmware.sena.com/senabluetoothmanager/WiFiCradle/bt_img/harleyFirmware"}};
|
|
|
+
|
|
|
+
|
|
|
public static void pullFirmwares(File statefile, File outfolder, boolean deepmode)
|
|
|
{
|
|
|
outfolder_base=outfolder;
|
|
|
- try{
|
|
|
- if(DUMMY_MODE)
|
|
|
- {
|
|
|
- dummydownloadfake = new PrintStream(new FileOutputStream(new File(outfolder,"dummy.log")));
|
|
|
+ try {
|
|
|
+ if (DUMMY_MODE) {
|
|
|
+ dummydownloadfake = new PrintStream(new FileOutputStream(new File(outfolder, "dummy.log")));
|
|
|
}
|
|
|
|
|
|
Representer representer = new Representer();
|
|
@@ -48,8 +58,7 @@ public class FirmwareAutoDumper
|
|
|
|
|
|
Yaml y = new Yaml(representer, new DumperOptions());
|
|
|
|
|
|
- if(statefile.exists())
|
|
|
- {
|
|
|
+ if (statefile.exists()) {
|
|
|
try {
|
|
|
Constructor constructor = new Constructor();
|
|
|
constructor.addTypeDescription(new TypeDescription(Firmware.class, "!FW"));
|
|
@@ -60,78 +69,72 @@ public class FirmwareAutoDumper
|
|
|
} catch (FileNotFoundException e) {
|
|
|
l.catching(e);
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
state = new Statefile();
|
|
|
state.setFirmwares(new LinkedHashMap<>());
|
|
|
}
|
|
|
|
|
|
- File outfolder_tmp = new File(outfolder,"tmp");
|
|
|
- if(!DUMMY_MODE)
|
|
|
- {
|
|
|
- new File(outfolder_tmp,"Firmware").delete();
|
|
|
- }
|
|
|
- File downloadFolderBase = new File(outfolder_base,"downloadstage");
|
|
|
- downloadFolderBase.mkdirs();
|
|
|
- File fw = new File(outfolder_tmp,"Firmware");
|
|
|
- outfolder_tmp.mkdirs();
|
|
|
- if(!fw.exists()) // should only happen in dummy mode or if something zarfed out while dev
|
|
|
+ File outfolder_tmp = new File(outfolder, "tmp");
|
|
|
+
|
|
|
+
|
|
|
+ for(String[] index:indexes)
|
|
|
{
|
|
|
- Utils.runTool(outfolder_tmp,
|
|
|
- "wget",
|
|
|
- "http://firmware.sena.com/senabluetoothmanager/Firmware"
|
|
|
+ if (!DUMMY_MODE) {
|
|
|
+ new File(outfolder_tmp, "Firmware").delete();
|
|
|
+ }
|
|
|
+ File downloadFolderBase = new File(outfolder_base, "downloadstage");
|
|
|
+ downloadFolderBase.mkdirs();
|
|
|
+ File fw = new File(outfolder_tmp, "Firmware");
|
|
|
+ outfolder_tmp.mkdirs();
|
|
|
+ if (!fw.exists()) // should only happen in dummy mode or if something zarfed out while dev
|
|
|
+ {
|
|
|
+ Utils.runTool(outfolder_tmp,
|
|
|
+ "wget",
|
|
|
+ index[1],
|
|
|
+ "-O",
|
|
|
+ "Firmware"
|
|
|
);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- BufferedReader br = new BufferedReader(new FileReader(fw));
|
|
|
- final HashMap<String,String> basenamelookup = new LinkedHashMap<>();
|
|
|
- // filename --> real basename
|
|
|
- br.lines().forEach((line)->
|
|
|
+ BufferedReader br = new BufferedReader(new FileReader(fw));
|
|
|
+ final HashMap<String, String> basenamelookup = new LinkedHashMap<>();
|
|
|
+ // filename --> real basename
|
|
|
+ br.lines().forEach((line) ->
|
|
|
{
|
|
|
String[] linesplitted = line.split(":");
|
|
|
|
|
|
String FWFileName;
|
|
|
String FWBAsename = "ZÖINKS!";
|
|
|
- if(linesplitted.length==4)
|
|
|
- {
|
|
|
- FWBAsename = linesplitted[0]+"-"+linesplitted[2];
|
|
|
+ if (linesplitted.length == 4) {
|
|
|
+ FWBAsename = linesplitted[0] + "-" + linesplitted[2];
|
|
|
FWFileName = linesplitted[3];
|
|
|
- }
|
|
|
- else if(linesplitted.length==3)
|
|
|
- {
|
|
|
- FWBAsename = linesplitted[0]+"-NOLNG";
|
|
|
+ } else if (linesplitted.length == 3) {
|
|
|
+ FWBAsename = linesplitted[0] + "-NOLNG";
|
|
|
FWFileName = linesplitted[2];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return;
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- if(basenamelookup.containsKey(FWFileName))
|
|
|
- {
|
|
|
+ if (basenamelookup.containsKey(FWFileName)) {
|
|
|
return; //languageless file, no need to handle multiple times.
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- basenamelookup.put(FWFileName,FWBAsename);
|
|
|
+ } else {
|
|
|
+ basenamelookup.put(FWFileName, FWBAsename);
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(!state.getFirmwares().containsKey(FWBAsename))
|
|
|
- {
|
|
|
+ if (!state.getFirmwares().containsKey(FWBAsename)) {
|
|
|
Firmware tmp = new Firmware();
|
|
|
tmp.setDeviceId(FWBAsename);
|
|
|
tmp.setInitialDLDone(false);
|
|
|
tmp.setVersions(new LinkedHashMap<>());
|
|
|
- state.getFirmwares().put(FWBAsename,tmp);
|
|
|
+ state.getFirmwares().put(FWBAsename, tmp);
|
|
|
}
|
|
|
|
|
|
Firmware f = state.getFirmwares().get(FWBAsename);
|
|
|
|
|
|
try {
|
|
|
- l.info("Processing line:"+line+"\n Basename:"+FWBAsename);
|
|
|
- int[] fwnumber = splitVersionAndPullFW(FWFileName,f.getVersions(),deepmode);
|
|
|
+ l.info("Processing line:" + line + "\n Basename:" + FWBAsename + "of index "+index[0]);
|
|
|
+ int[] fwnumber = splitVersionAndPullFW(FWFileName, f.getVersions(), deepmode,index[0]);
|
|
|
f.setMajor(fwnumber[0]);
|
|
|
f.setMinor(fwnumber[1]);
|
|
|
f.setPatch(fwnumber[2]);
|
|
@@ -139,18 +142,20 @@ public class FirmwareAutoDumper
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
- br.close();
|
|
|
- y.dump(state,new FileWriter(statefile));
|
|
|
- if(!DUMMY_MODE)
|
|
|
- {
|
|
|
- new File(outfolder_tmp,"Firmware").delete();
|
|
|
- pushToMatrix();
|
|
|
+ br.close();
|
|
|
+ y.dump(state, new FileWriter(statefile));
|
|
|
+ if (!DUMMY_MODE) {
|
|
|
+ new File(outfolder_tmp, "Firmware").delete();
|
|
|
+ pushToMatrix();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
if(DUMMY_MODE)
|
|
|
{
|
|
|
dummydownloadfake.close();
|
|
|
}
|
|
|
-
|
|
|
y.dump(state,new FileWriter(statefile));
|
|
|
}
|
|
|
catch (IOException ex)
|
|
@@ -259,17 +264,19 @@ public class FirmwareAutoDumper
|
|
|
|
|
|
if(!v2.isFiller())
|
|
|
{
|
|
|
- String version = v2.getMajor()+"."+v2.getMinor()+"."+v2.getPatch();
|
|
|
+ String lastSuffix = v2.isRc_hackfix()?v2.getHackfix():".";
|
|
|
+ String version = v2.getMajor()+"."+v2.getMinor()+lastSuffix+v2.getPatch();
|
|
|
+ String index = v2.getFirmwareLocation();
|
|
|
Date ts = v2.getServerCreationDate();
|
|
|
TimeZone tz = TimeZone.getTimeZone("UTC");
|
|
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); // Quoted "Z" to indicate UTC, no timezone offset
|
|
|
df.setTimeZone(tz);
|
|
|
String date = df.format(ts);
|
|
|
- String msg = "Detected new Version: "+version+" for "+k+" uploaded at: "+date;
|
|
|
+ String msg = "Detected new Version: "+version+" for "+k+" uploaded at: "+date+ "on index "+index;
|
|
|
|
|
|
if(v2.isHidden())
|
|
|
{
|
|
|
- msg = "Guessed new hidden Version: "+version+" for "+k+" uploaded at: "+date;
|
|
|
+ msg = "Guessed new hidden Version: "+version+" for "+k+" uploaded at: "+date+ "on index "+index;
|
|
|
}
|
|
|
if((!v2.isHidden()&&v2.getNotificationState()==MatrixState.SENT_PRELIM)||v2.getNotificationState()==MatrixState.TODO)
|
|
|
{
|
|
@@ -291,7 +298,7 @@ public class FirmwareAutoDumper
|
|
|
|
|
|
|
|
|
|
|
|
- private static int[] splitVersionAndPullFW(String filename,HashMap<String,FirmwareVersion> knownVersions, boolean deepmode) throws IOException {
|
|
|
+ private static int[] splitVersionAndPullFW(String filename,HashMap<String,FirmwareVersion> knownVersions, boolean deepmode,String indexUsed) throws IOException {
|
|
|
String[] magic = filename.split("-v");
|
|
|
boolean fuckingoddity = false;
|
|
|
boolean hackfix50R_SR = false;
|
|
@@ -306,7 +313,20 @@ public class FirmwareAutoDumper
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
String version = magic[1];
|
|
|
+ boolean rchackfix = false;
|
|
|
+ String hackfixsuffix = ".";
|
|
|
+ for(String suffixcheck:hackfixsuffixes)
|
|
|
+ {
|
|
|
+ if(version.contains(suffixcheck))
|
|
|
+ {
|
|
|
+ rchackfix=true;
|
|
|
+ version = version.replace(suffixcheck,".");
|
|
|
+ hackfixsuffix = suffixcheck;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String[] vsplit = version.split("\\.");
|
|
|
|
|
|
String suffix = "";
|
|
@@ -346,7 +366,7 @@ public class FirmwareAutoDumper
|
|
|
}
|
|
|
//suffix = suffix+".img";
|
|
|
|
|
|
- scanDownwards(major,minor,patch,prefix,suffix,knownVersions);
|
|
|
+ scanDownwards(major,minor,patch,prefix,suffix,knownVersions,rchackfix,hackfixsuffix,indexUsed);
|
|
|
|
|
|
//scanning upwards for "poking" for undocumented stuff
|
|
|
if(deepmode)
|
|
@@ -354,14 +374,14 @@ public class FirmwareAutoDumper
|
|
|
//String synthesizedFileName = prefix+(major)+"."+minor+"."+(patch)+suffix;
|
|
|
String synthesizedFileName = prefix+(major+1)+"."+0+"."+(0)+suffix;
|
|
|
String synthesizedFileNameShort = prefix+(major+1)+"."+0+suffix;
|
|
|
- peekNext(synthesizedFileName,synthesizedFileNameShort,major+1,0,0,knownVersions);
|
|
|
+ peekNext(synthesizedFileName,synthesizedFileNameShort,major+1,0,0,knownVersions,indexUsed);
|
|
|
|
|
|
synthesizedFileName = prefix+(major)+"."+(minor+1)+"."+(0)+suffix;
|
|
|
synthesizedFileNameShort = prefix+(major)+"."+(minor+1)+suffix;
|
|
|
- peekNext(synthesizedFileName,synthesizedFileNameShort,major,minor+1,0,knownVersions);
|
|
|
+ peekNext(synthesizedFileName,synthesizedFileNameShort,major,minor+1,0,knownVersions,indexUsed);
|
|
|
|
|
|
synthesizedFileName = prefix+(major)+"."+minor+"."+(patch+1)+suffix;
|
|
|
- peekNext(synthesizedFileName,null,major,minor,patch+1,knownVersions);
|
|
|
+ peekNext(synthesizedFileName,null,major,minor,patch+1,knownVersions,indexUsed);
|
|
|
}
|
|
|
|
|
|
return new int[]{major,minor,patch};
|
|
@@ -373,14 +393,19 @@ public class FirmwareAutoDumper
|
|
|
int patch,
|
|
|
String prefix,
|
|
|
String suffix,
|
|
|
- HashMap<String,FirmwareVersion> knownVersions) throws IOException {
|
|
|
+ HashMap<String,FirmwareVersion> knownVersions,
|
|
|
+ boolean rchackfix,
|
|
|
+ String hackfixsuffix,
|
|
|
+ String indexUsed
|
|
|
+ ) throws IOException {
|
|
|
l.info(major+"--"+minor+"--"+patch);
|
|
|
List<FirmwareVersion> temp = new ArrayList<>();
|
|
|
l.info(prefix+"."+major+"."+minor+"."+patch+"."+suffix);
|
|
|
|
|
|
while(major>=1&&minor>=0&&patch>=0) //older versions won't be bruteforced, check for existence in the index prevents a redownload.
|
|
|
{
|
|
|
- String synthesizedFileName = prefix+(major)+"."+minor+"."+(patch)+suffix;
|
|
|
+ String lastSuffix = rchackfix?hackfixsuffix:".";
|
|
|
+ String synthesizedFileName = prefix+(major)+"."+minor+lastSuffix+(patch)+suffix;
|
|
|
|
|
|
if(knownVersions.containsKey(synthesizedFileName)) //skipping redownload and setting it as "not hidden" if it was a hidden version
|
|
|
{
|
|
@@ -388,21 +413,28 @@ public class FirmwareAutoDumper
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- FirmwareVersion f = getFirmware(major,minor,patch,false,synthesizedFileName);
|
|
|
+ FirmwareVersion f = getFirmware(major,minor,patch,false,synthesizedFileName,rchackfix,hackfixsuffix,indexUsed);
|
|
|
knownVersions.put(synthesizedFileName,f);
|
|
|
}
|
|
|
if(patch==0)
|
|
|
{
|
|
|
- synthesizedFileName = prefix+(major)+"."+minor+suffix;
|
|
|
+ if(!rchackfix)
|
|
|
+ {
|
|
|
+ synthesizedFileName = prefix+(major)+"."+minor+suffix;
|
|
|
+ }
|
|
|
if(knownVersions.containsKey(synthesizedFileName)) //skipping redownload and setting it as "not hidden" if it was a hidden version
|
|
|
{
|
|
|
knownVersions.get(synthesizedFileName).setHidden(false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- FirmwareVersion f2 = getFirmware(major,minor,patch,false,synthesizedFileName);
|
|
|
+ FirmwareVersion f2 = getFirmware(major,minor,patch,false,synthesizedFileName,rchackfix,hackfixsuffix,indexUsed);
|
|
|
knownVersions.put(synthesizedFileName,f2);
|
|
|
}
|
|
|
+ if(rchackfix)
|
|
|
+ {
|
|
|
+ break; //rc-versions need different fudgery...
|
|
|
+ }
|
|
|
}
|
|
|
patch--;
|
|
|
if(patch<0)
|
|
@@ -419,13 +451,16 @@ public class FirmwareAutoDumper
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static FirmwareVersion getFirmware(int major, int minor, int patch, boolean hidden, String fwname) throws IOException {
|
|
|
+ private static FirmwareVersion getFirmware(int major, int minor, int patch, boolean hidden, String fwname,boolean rchackfix,String hackfixsuffix,String indexUsed) throws IOException {
|
|
|
FirmwareVersion f = new FirmwareVersion();
|
|
|
f.setFilename(fwname);
|
|
|
f.setHidden(hidden);
|
|
|
f.setMajor(major);
|
|
|
f.setMinor(minor);
|
|
|
f.setPatch(patch);
|
|
|
+ f.setRc_hackfix(rchackfix);
|
|
|
+ f.setFirmwareLocation(indexUsed);
|
|
|
+ f.setHackfix(hackfixsuffix);
|
|
|
File downloadFolderBase = new File(outfolder_base,"downloadstage");
|
|
|
if(supprCache.containsKey(fwname)) //leaves a "fake entry" when 2 different deviceIDs would lead to the same filename
|
|
|
{
|
|
@@ -437,12 +472,22 @@ public class FirmwareAutoDumper
|
|
|
}
|
|
|
supprCache.put(fwname,f); // banning a filename from rescan/redownload
|
|
|
//if(true) return f;
|
|
|
+ boolean originalLocationSuccessful = false;
|
|
|
if(!DUMMY_MODE)
|
|
|
{
|
|
|
Utils.runTool(downloadFolderBase,
|
|
|
"wget",
|
|
|
"http://firmware.sena.com/senabluetoothmanager/"+fwname
|
|
|
);
|
|
|
+ originalLocationSuccessful = new File(downloadFolderBase,fwname).exists();
|
|
|
+ if(!originalLocationSuccessful)
|
|
|
+ {
|
|
|
+ // new alternative location for additional images used by the WiFi cradle. Checking there if something does not exist at original
|
|
|
+ Utils.runTool(downloadFolderBase,
|
|
|
+ "wget",
|
|
|
+ "http://firmware.sena.com/senabluetoothmanager/WiFiCradle/bt_img/"+fwname
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -453,6 +498,7 @@ public class FirmwareAutoDumper
|
|
|
File dst = new File(outfolder_base,fwname);
|
|
|
if(dlf.exists())
|
|
|
{
|
|
|
+ f.setAlternativeLocation(!originalLocationSuccessful);
|
|
|
f.setFiller(false);
|
|
|
f.setServerCreationDate(new Date(dlf.lastModified()));
|
|
|
if(!dst.exists())
|
|
@@ -468,18 +514,26 @@ public class FirmwareAutoDumper
|
|
|
return f;
|
|
|
}
|
|
|
|
|
|
- private static void peekNext(String synthesizedFileName, String synthesizedFileNameShort, int major, int minor, int patch, HashMap<String,FirmwareVersion> knownVersions) throws IOException {
|
|
|
+ private static void peekNext(
|
|
|
+ String synthesizedFileName,
|
|
|
+ String synthesizedFileNameShort,
|
|
|
+ int major,
|
|
|
+ int minor,
|
|
|
+ int patch,
|
|
|
+ HashMap<String,FirmwareVersion> knownVersions,
|
|
|
+ String indexUsed
|
|
|
+ ) throws IOException {
|
|
|
l.info("peekstate:");
|
|
|
l.info(knownVersions.containsKey(synthesizedFileName));
|
|
|
l.info(knownVersions.containsKey(synthesizedFileNameShort));
|
|
|
if(!(knownVersions.containsKey(synthesizedFileName)||knownVersions.containsKey(synthesizedFileNameShort))) // only re-poking if nothing was there yet.
|
|
|
{
|
|
|
- FirmwareVersion nextMajor = getFirmware(major,minor,patch,true,synthesizedFileName);
|
|
|
+ FirmwareVersion nextMajor = getFirmware(major,minor,patch,true,synthesizedFileName,false,".",indexUsed);
|
|
|
if(nextMajor.isFiller())
|
|
|
{
|
|
|
if(synthesizedFileNameShort != null)
|
|
|
{
|
|
|
- nextMajor = getFirmware(major,minor,patch,true,synthesizedFileNameShort);
|
|
|
+ nextMajor = getFirmware(major,minor,patch,true,synthesizedFileNameShort,false,".",indexUsed);
|
|
|
synthesizedFileName = synthesizedFileNameShort;
|
|
|
}
|
|
|
}
|