mirror of https://github.com/rusefi/RomRaider.git
Outputting partial updated definitions
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@369 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
a4dc9282cc
commit
86e0fc214f
|
@ -17,6 +17,7 @@ public class Rom implements Serializable {
|
||||||
private Vector<Table> tables = new Vector<Table>();
|
private Vector<Table> tables = new Vector<Table>();
|
||||||
private ECUEditor container;
|
private ECUEditor container;
|
||||||
private byte[] binData;
|
private byte[] binData;
|
||||||
|
private String parent = "";
|
||||||
|
|
||||||
public Rom() {
|
public Rom() {
|
||||||
}
|
}
|
||||||
|
@ -159,4 +160,12 @@ public class Rom implements Serializable {
|
||||||
this.fullFileName = fullFileName;
|
this.fullFileName = fullFileName;
|
||||||
this.setFileName(fullFileName.getName());
|
this.setFileName(fullFileName.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(String parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,125 @@
|
||||||
package enginuity.newmaps.definition.translate;
|
package enginuity.newmaps.definition.translate;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
|
||||||
|
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
|
||||||
import enginuity.maps.Rom;
|
import enginuity.maps.Rom;
|
||||||
|
import enginuity.maps.RomID;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import javax.imageio.metadata.IIOMetadataNode;
|
||||||
|
|
||||||
public class DefinitionBuilder {
|
public class DefinitionBuilder {
|
||||||
|
|
||||||
Vector<Rom> roms;
|
Vector<Rom> roms;
|
||||||
|
|
||||||
public DefinitionBuilder(Vector<Rom> roms) {
|
public DefinitionBuilder(Vector<Rom> roms, File folder) {
|
||||||
this.roms = roms;
|
this.roms = roms;
|
||||||
|
OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
|
||||||
|
of.setIndent(1);
|
||||||
|
of.setIndenting(true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Iterate through ROMs for processing
|
||||||
|
//
|
||||||
|
Iterator it = roms.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Rom rom = (Rom)it.next();
|
||||||
|
IIOMetadataNode node = buildRom(rom);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Output to file
|
||||||
|
//
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(new File(folder.getAbsolutePath() + "/" + rom.getRomIDString() + ".xml"));
|
||||||
|
XMLSerializer serializer = new XMLSerializer(fos, of);
|
||||||
|
serializer.serialize(node);
|
||||||
|
fos.flush();
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IIOMetadataNode buildRom(Rom rom) {
|
||||||
|
IIOMetadataNode node = new IIOMetadataNode("rom");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set all attributes
|
||||||
|
//
|
||||||
|
|
||||||
|
// Start by getting base rom if it exists
|
||||||
|
Rom parentRom = new Rom();
|
||||||
|
boolean child = false;
|
||||||
|
try {
|
||||||
|
parentRom = get(rom.getParent());
|
||||||
|
child = true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// Rom wasn't found, not a child
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Building " + rom.getRomID().getXmlid() + " ...");
|
||||||
|
|
||||||
|
|
||||||
|
// Set all RomID data (now in Rom tag)
|
||||||
|
node.setAttribute("name", rom.getRomID().getXmlid());
|
||||||
|
|
||||||
|
if (rom.getParent().length() > 0 && (!child || !rom.getParent().equalsIgnoreCase(parentRom.getParent())))
|
||||||
|
node.setAttribute("base", rom.getParent());
|
||||||
|
|
||||||
|
if (buildDescription(rom.getRomID()).length() > 0 && (!child || !buildDescription(rom.getRomID()).equalsIgnoreCase(buildDescription(parentRom.getRomID()))))
|
||||||
|
node.setAttribute("description", buildDescription(rom.getRomID()));
|
||||||
|
|
||||||
|
if (rom.getRomID().getInternalIdAddress() > 0 && (!child || rom.getRomID().getInternalIdAddress() != parentRom.getRomID().getInternalIdAddress()))
|
||||||
|
node.setAttribute("idaddress", rom.getRomID().getInternalIdAddress()+"");
|
||||||
|
|
||||||
|
if (rom.getRomID().getInternalIdString().length() > 0 && (!child || !rom.getRomID().getInternalIdString().equalsIgnoreCase(parentRom.getRomID().getInternalIdString())))
|
||||||
|
node.setAttribute("idstring", rom.getRomID().getInternalIdString());
|
||||||
|
|
||||||
|
if (rom.getRomID().getMemModel().length() > 0 && (!child || !rom.getRomID().getMemModel().equalsIgnoreCase(parentRom.getRomID().getMemModel())))
|
||||||
|
node.setAttribute("memmodel", rom.getRomID().getMemModel());
|
||||||
|
|
||||||
|
if (rom.getRomID().getFlashMethod().length() > 0 && (!child || !rom.getRomID().getFlashMethod().equalsIgnoreCase(parentRom.getRomID().getFlashMethod())))
|
||||||
|
node.setAttribute("flashmethod", rom.getRomID().getFlashMethod());
|
||||||
|
|
||||||
|
if (rom.getRomID().getCaseId().length() > 0 && (!child || !rom.getRomID().getCaseId().equalsIgnoreCase(parentRom.getRomID().getCaseId())))
|
||||||
|
node.setAttribute("caseid", rom.getRomID().getCaseId());
|
||||||
|
|
||||||
|
if (rom.getRomID().isObsolete() && (!child || rom.getRomID().isObsolete() != parentRom.getRomID().isObsolete()))
|
||||||
|
node.setAttribute("obsolete", rom.getRomID().isObsolete()+"");
|
||||||
|
|
||||||
|
return node;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String buildDescription(RomID id) {
|
||||||
|
StringBuffer output = new StringBuffer();
|
||||||
|
|
||||||
|
if (id.getYear().length() > 0) output.append(id.getYear() + " ");
|
||||||
|
if (id.getMarket().length() > 0) output.append(id.getMarket() + " ");
|
||||||
|
if (id.getMake().length() > 0) output.append(id.getMake() + " ");
|
||||||
|
if (id.getModel().length() > 0) output.append(id.getModel() + " ");
|
||||||
|
if (id.getSubModel().length() > 0) output.append(id.getSubModel() + " ");
|
||||||
|
|
||||||
|
return new String(output).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector<Rom> getRoms() {
|
||||||
|
return roms;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rom get(String name) throws Exception {
|
||||||
|
Iterator it = roms.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Rom rom = (Rom)it.next();
|
||||||
|
if (rom.getRomIDString().equalsIgnoreCase(name)) {
|
||||||
|
return rom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,7 @@ public final class FirstGenDefinitionHandler {
|
||||||
if (!unmarshallAttribute(rootNode, "base", "none").equalsIgnoreCase("none")) {
|
if (!unmarshallAttribute(rootNode, "base", "none").equalsIgnoreCase("none")) {
|
||||||
rom = get(unmarshallAttribute(rootNode, "base", "none"));
|
rom = get(unmarshallAttribute(rootNode, "base", "none"));
|
||||||
rom.getRomID().setObsolete(false);
|
rom.getRomID().setObsolete(false);
|
||||||
|
rom.setParent(unmarshallAttribute(rootNode, "base", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,30 +9,45 @@ import org.w3c.dom.Document;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
public class FirstGenTranslator {
|
public class FirstGenTranslator {
|
||||||
|
|
||||||
public FirstGenTranslator() {
|
public FirstGenTranslator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
FirstGenDefinitionHandler handler = new FirstGenDefinitionHandler();
|
FirstGenDefinitionHandler handler = new FirstGenDefinitionHandler();
|
||||||
File file = new File("ecu_defs.xml");
|
File inputFile = new File("ecu_defs.xml");
|
||||||
|
File outputFolder = new File("/newdefs/");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
// Parse existing definitions
|
// Parse existing definitions
|
||||||
//
|
//
|
||||||
|
System.out.println("*******************************\n" +
|
||||||
|
"* Parsing old definitions ... *\n" +
|
||||||
|
"*******************************");
|
||||||
DOMParser parser = new DOMParser();
|
DOMParser parser = new DOMParser();
|
||||||
InputSource src = new InputSource(new FileInputStream(file));
|
InputSource src = new InputSource(new FileInputStream(inputFile));
|
||||||
parser.parse(src);
|
parser.parse(src);
|
||||||
Document doc = parser.getDocument();
|
Document doc = parser.getDocument();
|
||||||
|
|
||||||
|
System.out.println("\n***************************************\n" +
|
||||||
|
"* Building old definition objects ... *\n" +
|
||||||
|
"***************************************");
|
||||||
// Create old ROMs
|
// Create old ROMs
|
||||||
Vector<Rom> roms = handler.unmarshallXMLDefinition(doc.getDocumentElement());
|
Vector<Rom> roms = handler.unmarshallXMLDefinition(doc.getDocumentElement());
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create new document
|
// Create new document
|
||||||
//
|
//
|
||||||
DefinitionBuilder builder = new DefinitionBuilder(roms);
|
System.out.println("\n*****************************\n" +
|
||||||
|
"* Generating XML output ... *\n" +
|
||||||
|
"*****************************");
|
||||||
|
DefinitionBuilder builder = new DefinitionBuilder(roms, outputFolder);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n*************\n" +
|
||||||
|
"* Finished! *\n" +
|
||||||
|
"*************");
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue