diff --git a/i18n/com/romraider/swing/DefinitionManager.properties b/i18n/com/romraider/swing/DefinitionManager.properties index c8bd6116..f01f5cc9 100644 --- a/i18n/com/romraider/swing/DefinitionManager.properties +++ b/i18n/com/romraider/swing/DefinitionManager.properties @@ -8,3 +8,5 @@ SAVE = Save CANCEL = Cancel APPLY = Apply UNDO = Undo +CONVERSIONTITLE = Conversion Layer Warning + diff --git a/i18n/com/romraider/xml/ConversionLayer/BmwCodingConversionLayer.properties b/i18n/com/romraider/xml/ConversionLayer/BmwCodingConversionLayer.properties new file mode 100644 index 00000000..2cc541a3 --- /dev/null +++ b/i18n/com/romraider/xml/ConversionLayer/BmwCodingConversionLayer.properties @@ -0,0 +1,5 @@ +MISSINGFILE = Failed to find +ERRORFILE = Failed to open +ERRORFILESTART = Failed to find start of file for +NCSHINT = Are you loading this CXX file from the original SP-Daten structure? +LOADINGWARNING = Warning: The identification procedure for NCS Expert files is auto-generated. This is not always reliable, especially on small files.\nIt is recommended that you select the binary first and load the correct Cxx file. You can then convert it to a RomRaider definition and add the identification manually. diff --git a/i18n/com/romraider/xml/ConversionLayer/XDFConversionLayer.properties b/i18n/com/romraider/xml/ConversionLayer/XDFConversionLayer.properties new file mode 100644 index 00000000..675439b4 --- /dev/null +++ b/i18n/com/romraider/xml/ConversionLayer/XDFConversionLayer.properties @@ -0,0 +1,6 @@ +NOXDFHEADER = XDF file does not have an XDFHEADER element! +NOXDFFORMAT = XDF file does not have an XDFFORMAT element! +ONLYXML = Sorry, only XML XDFs are currently supported! +LOADINGWARNING = Warning: XDF files do not have an identification component. This means this definition will always be chosen if no previous definition is found first.\nIt is recommended to load the binary first and manually select the definition. You can then export it as a RomRaider definition and add the identification component. + + diff --git a/src/main/java/com/romraider/editor/ecu/OpenImageWorker.java b/src/main/java/com/romraider/editor/ecu/OpenImageWorker.java index fa494de2..680c3512 100644 --- a/src/main/java/com/romraider/editor/ecu/OpenImageWorker.java +++ b/src/main/java/com/romraider/editor/ecu/OpenImageWorker.java @@ -54,6 +54,7 @@ import com.romraider.xml.ConversionLayer.ConversionLayerFactory; public class OpenImageWorker extends SwingWorker { private static final Logger LOGGER = Logger.getLogger(OpenImageWorker.class); private final File inputFile; + private Rom rom; private String finalStatus; public OpenImageWorker(File inputFile) { @@ -73,24 +74,22 @@ public class OpenImageWorker extends SwingWorker { ECUEditor.rb.getString("FINALIZING")); setProgress(90); - editor.addRom(rom); - editor.getStatusPanel().setStatus( ECUEditor.rb.getString("DONELOAD")); setProgress(95); - - editor.getStatusPanel().setStatus( - ECUEditor.rb.getString("CHECKSUM")); - - int validChecksums = rom.validateChecksum(); if(rom.getNumChecksumsManagers() == 0) { finalStatus = ECUEditor.rb.getString("STATUSREADY"); } else { + editor.getStatusPanel().setStatus( + ECUEditor.rb.getString("CHECKSUM")); + finalStatus = String.format(ECUEditor.rb.getString("CHECKSUMSTATE"), - validChecksums, rom.getNumChecksumsManagers()); - } + rom.validateChecksum(), rom.getNumChecksumsManagers()); + } + + this.rom = rom; } private Document createDocument(File f) throws Exception { @@ -114,7 +113,7 @@ public class OpenImageWorker extends SwingWorker { doc = l.convertToDocumentTree(f); if(doc == null) - throw new SAXParseException("Unknown file format!", null); + throw new SAXParseException(ECUEditor.rb.getString("UNREADABLEDEF"), null); } //Default case else { @@ -316,11 +315,21 @@ public class OpenImageWorker extends SwingWorker { @Override public void done() { - ECUEditor editor = ECUEditorManager.getECUEditor(); - editor.getStatusPanel().update(finalStatus, 0); - editor.refreshTableCompareMenus(); - editor.setCursor(null); - editor.refreshUI(); - System.gc(); + ECUEditor editor = ECUEditorManager.getECUEditor(); + + //Add the rom in the main thread + if(rom != null) { + editor.addRom(rom); + rom = null; + + editor.getStatusPanel().update(finalStatus, 0); + editor.refreshTableCompareMenus(); + editor.setCursor(null); + editor.refreshUI(); + System.gc(); + } + else { + editor.getStatusPanel().update(ECUEditor.rb.getString("STATUSREADY"), 0); + } } } \ No newline at end of file diff --git a/src/main/java/com/romraider/maps/Rom.java b/src/main/java/com/romraider/maps/Rom.java index 92379e74..acbf807a 100644 --- a/src/main/java/com/romraider/maps/Rom.java +++ b/src/main/java/com/romraider/maps/Rom.java @@ -434,8 +434,12 @@ public class Rom extends DefaultMutableTreeNode implements Serializable { for(TableTreeNode tableTreeNode : tableNodes.values()) { TableFrame frame = tableTreeNode.getFrame(); - TableUpdateHandler.getInstance().deregisterTable(tableTreeNode.getTable()); - tableTreeNode.getTable().clearData(); + TableUpdateHandler.getInstance().deregisterTable(tableTreeNode.getTable()); + + // Quite slow and doesn't seem to be necessary after testing, + // uncomment if you disagree + + //tableTreeNode.getTable().clearData(); if(frame != null) { diff --git a/src/main/java/com/romraider/swing/DefinitionFilter.java b/src/main/java/com/romraider/swing/DefinitionFilter.java index 7a02af9d..80e5c91b 100644 --- a/src/main/java/com/romraider/swing/DefinitionFilter.java +++ b/src/main/java/com/romraider/swing/DefinitionFilter.java @@ -41,13 +41,13 @@ public class DefinitionFilter extends FileFilter { new XDFConversionLayer().getRegexFileNameFilter() }; - private String[] filterDescr = {".xml", ".Cxx", ".xdf"}; + private String[] filterDescr = {".xml", ".Cxx (NCS Expert)", ".xdf (Tuner Pro)"}; private String startDescription; public DefinitionFilter() { startDescription = rb.getString("DESC"); } - + public boolean accept(File f) { if (f != null) { if (f.isDirectory()) { diff --git a/src/main/java/com/romraider/swing/DefinitionManager.java b/src/main/java/com/romraider/swing/DefinitionManager.java index 3744807e..bd91a701 100644 --- a/src/main/java/com/romraider/swing/DefinitionManager.java +++ b/src/main/java/com/romraider/swing/DefinitionManager.java @@ -32,6 +32,8 @@ import com.romraider.Settings; import com.romraider.editor.ecu.ECUEditorManager; import com.romraider.util.ResourceUtil; import com.romraider.util.SettingsManager; +import com.romraider.xml.ConversionLayer.ConversionLayer; +import com.romraider.xml.ConversionLayer.ConversionLayerFactory; public class DefinitionManager extends javax.swing.JFrame implements ActionListener { @@ -228,7 +230,20 @@ public class DefinitionManager extends javax.swing.JFrame implements ActionListe } } - if(!alreadyAdded) fileNames.add(f.getAbsolutePath()); + if(!alreadyAdded) { + //If its a file that needs to be converted sometimes a warning + //should be displayed to the user + if(ConversionLayerFactory.requiresConversionLayer(f)) { + ConversionLayer layer = ConversionLayerFactory.getConversionLayerForFile(f); + + if(layer.getDefinitionPickerInfo() != null) { + JOptionPane.showMessageDialog(null, layer.getDefinitionPickerInfo(), + rb.getString("CONVERSIONTITLE"), JOptionPane.WARNING_MESSAGE); + } + } + + fileNames.add(f.getAbsolutePath()); + } settings.setLastDefinitionDir(f.getParentFile()); } diff --git a/src/main/java/com/romraider/xml/ConversionLayer/BMWCodingConversionLayer.java b/src/main/java/com/romraider/xml/ConversionLayer/BMWCodingConversionLayer.java index b29740a3..02670ebd 100644 --- a/src/main/java/com/romraider/xml/ConversionLayer/BMWCodingConversionLayer.java +++ b/src/main/java/com/romraider/xml/ConversionLayer/BMWCodingConversionLayer.java @@ -33,6 +33,7 @@ import java.nio.ByteOrder; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.ResourceBundle; import java.util.Set; import javax.xml.parsers.DocumentBuilder; @@ -48,615 +49,623 @@ import com.romraider.Settings; import com.romraider.editor.ecu.ECUEditor; import com.romraider.editor.ecu.OpenImageWorker; import com.romraider.util.ByteUtil; +import com.romraider.util.ResourceUtil; import com.romraider.util.SettingsManager; import com.romraider.xml.ConversionLayer.ConversionLayer;; -public class BMWCodingConversionLayer extends ConversionLayer { +public class BMWCodingConversionLayer extends ConversionLayer { + protected static final ResourceBundle rb = new ResourceUtil().getBundle(BMWCodingConversionLayer.class.getName()); + private int splitAddress = 0; boolean guessChecksums = false; - - HashMap fswMap; - HashMap pswMap; - HashMap aswMap; - HashMap csvMap; - HashMap transMap; - - BMWConversionRomNodeManager[] romManagers; + + HashMap fswMap; + HashMap pswMap; + HashMap aswMap; + HashMap csvMap; + HashMap transMap; + + BMWConversionRomNodeManager[] romManagers; ByteBuffer dataBuffer; int dataIndex; - - String currentCategory = ""; - int currentFSW = 0; - Node currentTable = null; - - String memoryLayout = "uint8"; - String endian = "little"; - - int unusedCounter = 0; - - //Naming stays german, because the file is also german - static final int TYPE_DATEINAME = 0x0000; //Filename - static final int SGID_CODIERINDEX = 0x0001; //Codingindex - static final int SGID_HARDWARENUMMER = 0x0002; //Hardware number - static final int SGID_SWNUMMER = 0x0003; //Software number - static final int SPEICHERORG = 0x0004; //Memory layout - static final int ANLIEFERZUSTAND = 0x0005; //State of delivery when new (?) - static final int CODIERDATENBLOCK = 0x0006; //Coding data block (like a group) - static final int HERSTELLERDATENBLOCK = 0x0007; //Manufacturer data block (like a group) - static final int RESERVIERTDATENBLOCK = 0x0008; //Reserved data (like a group) - static final int UNBELEGT1 = 0x0009; //Unused (Not actually sometimes) - static final int UNBELEGT2 = 0x000A; //Unused (Not actually sometimes) - static final int KENNUNG_K = 0x000B; //? - static final int KENNUNG_D = 0x000C; //? - static final int KENNUNG_X = 0x000D; //? - static final int KENNUNG_ALL = 0x000E; //? - static final int PARZUWEISUNG_PSW2 = 0x000F; //Coding data preset information - static final int PARZUWEISUNG_PSW1 = 0x0010; //Coding data preset information - static final int PARZUWEISUNG_DIR = 0x0011; //? - static final int PARZUWEISUNG_FSW = 0x0012; //Coding data memory storage information - - //Gets called when ROM is opened directly + + String currentCategory = ""; + int currentFSW = 0; + Node currentTable = null; + + String memoryLayout = "uint8"; + String endian = "little"; + + int unusedCounter = 0; + + // Naming stays german, because the file is also german + static final int TYPE_DATEINAME = 0x0000; // Filename + static final int SGID_CODIERINDEX = 0x0001; // Codingindex + static final int SGID_HARDWARENUMMER = 0x0002; // Hardware number + static final int SGID_SWNUMMER = 0x0003; // Software number + static final int SPEICHERORG = 0x0004; // Memory layout + static final int ANLIEFERZUSTAND = 0x0005; // State of delivery when new (?) + static final int CODIERDATENBLOCK = 0x0006; // Coding data block (like a group) + static final int HERSTELLERDATENBLOCK = 0x0007; // Manufacturer data block (like a group) + static final int RESERVIERTDATENBLOCK = 0x0008; // Reserved data (like a group) + static final int UNBELEGT1 = 0x0009; // Unused (Not actually sometimes) + static final int UNBELEGT2 = 0x000A; // Unused (Not actually sometimes) + static final int KENNUNG_K = 0x000B; // ? + static final int KENNUNG_D = 0x000C; // ? + static final int KENNUNG_X = 0x000D; // ? + static final int KENNUNG_ALL = 0x000E; // ? + static final int PARZUWEISUNG_PSW2 = 0x000F; // Coding data preset information + static final int PARZUWEISUNG_PSW1 = 0x0010; // Coding data preset information + static final int PARZUWEISUNG_DIR = 0x0011; // ? + static final int PARZUWEISUNG_FSW = 0x0012; // Coding data memory storage information + + // Gets called when ROM is opened directly public BMWCodingConversionLayer() { - this(0, false); + this(0, false); } - - //Gets called from the toolbar with more options + + // Gets called from the toolbar with more options public BMWCodingConversionLayer(int splitAddress, boolean guessChecksums) { this.splitAddress = splitAddress; this.guessChecksums = guessChecksums; } - + @Override public String getRegexFileNameFilter() { - return "^.*\\.C\\d\\d$"; + return "^.*\\.C\\d\\d$"; } - - //Reads a string in an array until zero byte + + // Reads a string in an array until zero byte private static String readString(byte[] input, int offset) { StringBuilder s = new StringBuilder(); - - while((char)(input[offset])!=0) { - s.append((char)input[offset]); + + while ((char) (input[offset]) != 0) { + s.append((char) input[offset]); offset++; } - + return s.toString(); } - - //Reads the optional translation file from NCS Dummy - private HashMap readTranslationFile(File transF) { - HashMap map = new HashMap(); - - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(transF)); - String line; - while ((line = br.readLine()) != null) { - final String[] values = line.split(","); - if(values.length == 2) { - map.put(values[0], values[1]); - } - } + // Reads the optional translation file from NCS Dummy + private HashMap readTranslationFile(File transF) { + HashMap map = new HashMap(); + + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(transF)); + String line; + + while ((line = br.readLine()) != null) { + final String[] values = line.split(","); + if (values.length == 2) { + map.put(values[0], values[1]); + } + } + + } catch (final FileNotFoundException e) { + return null; + } catch (final IOException e) { + return null; + } finally { + try { + if (br != null) { + br.close(); + } + } catch (final IOException e) { + e.printStackTrace(); + } + } - } catch (final FileNotFoundException e) { - return null; - } catch (final IOException e) { - return null; - } - finally { - try { - if (br != null) { - br.close(); - } - } catch (final IOException e) { - e.printStackTrace(); - } - } - return map; } private static HashMap createMapFromNCSDict(File f) { - //Parse name dictionary - HashMap map= new HashMap(); + // Parse name dictionary + HashMap map = new HashMap(); byte[] fswInput; - + try { fswInput = ECUEditor.readFile(f); } catch (IOException e) { return null; } - + ByteBuffer fswBuffer = ByteBuffer.wrap(fswInput); fswBuffer = fswBuffer.order(ByteOrder.LITTLE_ENDIAN); - - for(int i = getStartOfFile(fswBuffer); i < fswInput.length;) { - int oldIndex = i; - - int length = fswBuffer.get(i); - int frameType = fswBuffer.getShort(i+1); - i+=3; - - switch(frameType) { - //Name - case 0x0000: - break; - //SWT Entry - case 0x0001: - int keyId = fswBuffer.getShort(i); - String name = readString(fswInput, i+2); - map.put(keyId, name); - break; - } - - i = oldIndex+length + 4; - } - - return map; + + for (int i = getStartOfFile(fswBuffer); i < fswInput.length;) { + int oldIndex = i; + + int length = fswBuffer.get(i); + int frameType = fswBuffer.getShort(i + 1); + i += 3; + + switch (frameType) { + // Name + case 0x0000: + break; + // SWT Entry + case 0x0001: + int keyId = fswBuffer.getShort(i); + String name = readString(fswInput, i + 2); + map.put(keyId, name); + break; + } + + i = oldIndex + length + 4; + } + + return map; } - + private static HashMap createMapFromCVT(File f, HashMap aswMap) { - //Parse name dictionary - HashMap map= new HashMap(); + // Parse name dictionary + HashMap map = new HashMap(); byte[] fswInput; - + try { fswInput = ECUEditor.readFile(f); } catch (IOException e) { return null; } - + ByteBuffer cvtBuffer = ByteBuffer.wrap(fswInput); cvtBuffer = cvtBuffer.order(ByteOrder.LITTLE_ENDIAN); - + /* - 0000 - DATEINAME - S - NAME - 0001 - GRUPPE - {S} - NAME - 0002 - INDIVID - {S} - NAME - 0003 - AUFTRAGSAUSDRUCK - A - AUFTRAGSAUSDRUCK - 0004 - FSW_PSW - WW - FSWINDEX,PSWINDEX - 0005 - FSW - W - FSWINDEX + * 0000 - DATEINAME - S - NAME 0001 - GRUPPE - {S} - NAME 0002 - INDIVID - {S} - + * NAME 0003 - AUFTRAGSAUSDRUCK - A - AUFTRAGSAUSDRUCK 0004 - FSW_PSW - WW - + * FSWINDEX,PSWINDEX 0005 - FSW - W - FSWINDEX */ - + String currentOption = ""; - for(int i = getStartOfFile(cvtBuffer); i < fswInput.length;) { - int oldIndex = i; - - int length = cvtBuffer.get(i); - int frameType = cvtBuffer.getShort(i+1); - i+=3; - - switch(frameType) { - //Name - case 0x0000: - break; - //Option/Auftrag - case 0x0003: - int lengthOption = cvtBuffer.get(i); - i++; - String optionCode = ""; - - for(int j = 0; j < lengthOption;) { - if(cvtBuffer.get(j + i) == 0x53) { - int keyId = cvtBuffer.getShort(j+i+1); - currentOption = aswMap.get(keyId); - optionCode = optionCode + currentOption; - j+=3; - } - else { - optionCode+=(char) cvtBuffer.get(j+i); - j++; - } - } - - currentOption = optionCode; - break; - - //Link FSW/PSW combination to option - case 0x0004: - int fsw = cvtBuffer.getShort(i); - int psw = cvtBuffer.getShort(i+2); - map.put(fsw << 16 | psw, currentOption); - break; - } - - i = oldIndex+length + 4; - } - - return map; + for (int i = getStartOfFile(cvtBuffer); i < fswInput.length;) { + int oldIndex = i; + + int length = cvtBuffer.get(i); + int frameType = cvtBuffer.getShort(i + 1); + i += 3; + + switch (frameType) { + // Name + case 0x0000: + break; + // Option/Auftrag + case 0x0003: + int lengthOption = cvtBuffer.get(i); + i++; + String optionCode = ""; + + for (int j = 0; j < lengthOption;) { + if (cvtBuffer.get(j + i) == 0x53) { + int keyId = cvtBuffer.getShort(j + i + 1); + currentOption = aswMap.get(keyId); + optionCode = optionCode + currentOption; + j += 3; + } else { + optionCode += (char) cvtBuffer.get(j + i); + j++; + } + } + + currentOption = optionCode; + break; + + // Link FSW/PSW combination to option + case 0x0004: + int fsw = cvtBuffer.getShort(i); + int psw = cvtBuffer.getShort(i + 2); + map.put(fsw << 16 | psw, currentOption); + break; + } + + i = oldIndex + length + 4; + } + + return map; } - - //Look for 0xFFFF in the file to skip the header + + // Look for 0xFFFF in the file to skip the header private static int getStartOfFile(ByteBuffer b) { - for(int i=0; i < b.capacity();i++) { - int value = b.getShort(i); - if(value == -1) { - return i+2; - } - } - - return -1; + for (int i = 0; i < b.capacity(); i++) { + int value = b.getShort(i); + if (value == -1) { + return i + 2; + } + } + + return -1; } - - public Document convertToDocumentTree(File f) throws SAXException { + + public Document convertToDocumentTree(File f) throws SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = null; - + DocumentBuilder builder = null; + try { builder = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } - - Document doc = builder.newDocument(); - - //Check first if naming conversion files are there + + Document doc = builder.newDocument(); + + // Check first if naming conversion files are there File[] listOfFiles = f.getParentFile().listFiles(); - File fswF = new File(""); + File fswF = new File(""); File pswF = new File(""); File aswF = new File(""); File csvF = new File(f.getParent(), f.getParentFile().getName() + "CVT.000"); - + for (int i = 0; i < listOfFiles.length; i++) { File fList = listOfFiles[i]; if (fList.isFile()) { - if (fList.getName().matches("(?i)SWTFSW\\d\\d\\.dat")) fswF = fList; - else if(fList.getName().matches("(?i)SWTPSW\\d\\d\\.dat")) pswF = fList; - else if(fList.getName().matches("(?i)SWTASW\\d\\d\\.dat")) aswF = fList; - } + if (fList.getName().matches("(?i)SWTFSW\\d\\d\\.dat")) + fswF = fList; + else if (fList.getName().matches("(?i)SWTPSW\\d\\d\\.dat")) + pswF = fList; + else if (fList.getName().matches("(?i)SWTASW\\d\\d\\.dat")) + aswF = fList; + } } - - //TODO: Add i18n - if(!fswF.exists()) { - throw new SAXException("Failed to find " + fswF); + + if (!fswF.exists()) { + throw new SAXException(rb.getString("MISSINGFILE") + "SWTFSW.dat. " + rb.getString("NCSHINT")); } - if(!pswF.exists()) { - throw new SAXException("Failed to find " + pswF); + if (!pswF.exists()) { + throw new SAXException(rb.getString("MISSINGFILE") + "SWTPSW.dat. " + rb.getString("NCSHINT")); } - if(!aswF.exists()) { - throw new SAXException("Failed to find " + aswF); + if (!aswF.exists()) { + throw new SAXException(rb.getString("MISSINGFILE") + "SWTASW.dat. " + rb.getString("NCSHINT")); } - if(!csvF.exists()) { - throw new SAXException("Failed to find " + csvF); + if (!csvF.exists()) { + throw new SAXException(rb.getString("MISSINGFILE") + "CVT.000. " + rb.getString("NCSHINT")); } - - fswMap= createMapFromNCSDict(fswF); - pswMap= createMapFromNCSDict(pswF); - aswMap= createMapFromNCSDict(aswF); - csvMap= createMapFromCVT(csvF, aswMap); - - //Optional translation file that has to be in the DATEN folder - //Created from NCSDummy developers - File transF = new File(f, "../../Translations.csv"); - if(transF.exists()) transMap = readTranslationFile(transF); - - byte[] input; - + + fswMap = createMapFromNCSDict(fswF); + pswMap = createMapFromNCSDict(pswF); + aswMap = createMapFromNCSDict(aswF); + csvMap = createMapFromCVT(csvF, aswMap); + + // Optional translation file that has to be in the DATEN folder + // Created from NCSDummy developers + File transF = new File(f, "../../Translations.csv"); + if (transF.exists()) + transMap = readTranslationFile(transF); + + byte[] input; + try { input = ECUEditor.readFile(f); } catch (IOException e) { - throw new SAXException("Failed to open file " + f); + throw new SAXException(rb.getString("ERRORFILE") + f); } - + dataBuffer = ByteBuffer.wrap(input); dataBuffer = dataBuffer.order(ByteOrder.LITTLE_ENDIAN); - - Node roms = doc.createElement("roms"); - doc.appendChild(roms); - - //Create one manager if no splitting - //Create two otherwise - if(splitAddress == 0) romManagers= new BMWConversionRomNodeManager[] {new BMWConversionRomNodeManager(0, doc, roms)}; - else - romManagers= new BMWConversionRomNodeManager[] { - new BMWConversionRomNodeManager(0, doc, roms), - new BMWConversionRomNodeManager(splitAddress, doc, roms)}; - - /* - * 0000 - DATEINAME - S - NAME - 0001 - SGID_CODIERINDEX - B(B) - WERT,WERT2 - 0002 - SGID_HARDWARENUMMER - S(S) - WERT,WERT2 - 0003 - SGID_SWNUMMER - S(S) - WERT,WERT2 - 0004 - SPEICHERORG - SS - STRUKTUR,TYP - 0005 - ANLIEFERZUSTAND - (B) - WERT - 0006 - CODIERDATENBLOCK - {L}LWS - BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG - 0007 - HERSTELLERDATENBLOCK - {L}LWS - BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG - 0008 - RESERVIERTDATENBLOCK - {L}LWS - BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG - 0009 - UNBELEGT1 - {L}LW{B}(B) - BLOCKNR,WORTADR,BYTEADR,INDEX,MASKE - 000A - UNBELEGT2 - (B) - WERT - 000B - KENNUNG_K - SS(S) - IDENT,WERT1,WERTN - 000C - KENNUNG_D - WW(WW) - HEXWERT1,HEXWERT2,HEXWERTN1,HEXWERTN2 - 000D - KENNUNG_X - WW(WW) - HEXWERT1,HEXWERT2,HEXWERTN1,HEXWERTN2 - 000E - KENNUNG_ALL - SW(W) - KENNUNG,HEXWERT1,HEXWERTN - 000F - PARZUWEISUNG_PSW2 - (B) - DATUM - 0010 - PARZUWEISUNG_PSW1 - W(B) - PSW,DATUM - 0011 - PARZUWEISUNG_DIR - {L}LWW{B}(B)(A)B - BLOCKNR,WORTADR,BYTEADR,FSW,INDEX,MASKE,OPERATION,EINHEIT - 0012 - PARZUWEISUNG_FSW - {L}LWW{B}(B){B}{B} - BLOCKNR,WORTADR,BYTEADR,FSW,INDEX,MASKE,EINHEIT,INDIVID - */ - - //Look for 0xFFFF in the file to skip the header - dataIndex = getStartOfFile(dataBuffer); - - if(dataIndex == 0) { - throw new SAXException("Failed to find start of file for " + f.toString()); - } - - while(dataIndex < input.length) { - int oldIndex = dataIndex; - - int length = 0xFFFF & dataBuffer.get(dataIndex); - int frameType = 0xFFFF & dataBuffer.getShort(dataIndex+1); - dataIndex+=2; - - switch(frameType) { - case SPEICHERORG: - parseMemoryOrg(); - break; - case TYPE_DATEINAME: - //String fileNameInFile = readString(input, i+1); - break; - //"Unused" Data, which often contains hidden data - case UNBELEGT1: - parseUnused(); - break; - //Not sure what to do with this - case UNBELEGT2: - break; - //Coding Block (=category) - //Fall-Through! - case CODIERDATENBLOCK: - case HERSTELLERDATENBLOCK: - case RESERVIERTDATENBLOCK: - parseGroup(); - break; - case PARZUWEISUNG_DIR: - parseFSWValues(false); - break; - case PARZUWEISUNG_FSW: - parseFSWValues(false); - break; + Node roms = doc.createElement("roms"); + doc.appendChild(roms); + + // Create one manager if no splitting + // Create two otherwise + if (splitAddress == 0) + romManagers = new BMWConversionRomNodeManager[] { new BMWConversionRomNodeManager(0, doc, roms) }; + else + romManagers = new BMWConversionRomNodeManager[] { new BMWConversionRomNodeManager(0, doc, roms), + new BMWConversionRomNodeManager(splitAddress, doc, roms) }; - case PARZUWEISUNG_PSW1: - parsePresetValues(true); - break; - case PARZUWEISUNG_PSW2: - parsePresetValues(false); - break; - } - - //No matter what the index points to, always go by length - //Skip frameType, checksum and go to next - dataIndex = oldIndex+length + 4; - } - - for(BMWConversionRomNodeManager man: romManagers){ - man.calculateRomID(f, "BMW"); - } - - return doc; - } - - private void parseMemoryOrg() { - String layout = readString(dataBuffer.array(), dataIndex+1); - /* - if(layout.equalsIgnoreCase("byte")) memoryLayout = "uint8"; - else if(layout.equalsIgnoreCase("wordmsb")) { - memoryLayout = "uint16"; - endian = "big"; + * 0000 - DATEINAME - S - NAME 0001 - SGID_CODIERINDEX - B(B) - WERT,WERT2 0002 + * - SGID_HARDWARENUMMER - S(S) - WERT,WERT2 0003 - SGID_SWNUMMER - S(S) - + * WERT,WERT2 0004 - SPEICHERORG - SS - STRUKTUR,TYP 0005 - ANLIEFERZUSTAND - + * (B) - WERT 0006 - CODIERDATENBLOCK - {L}LWS - + * BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG 0007 - HERSTELLERDATENBLOCK - {L}LWS - + * BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG 0008 - RESERVIERTDATENBLOCK - {L}LWS - + * BLOCKNR,WORTADR,BYTEADR,BEZEICHNUNG 0009 - UNBELEGT1 - {L}LW{B}(B) - + * BLOCKNR,WORTADR,BYTEADR,INDEX,MASKE 000A - UNBELEGT2 - (B) - WERT 000B - + * KENNUNG_K - SS(S) - IDENT,WERT1,WERTN 000C - KENNUNG_D - WW(WW) - + * HEXWERT1,HEXWERT2,HEXWERTN1,HEXWERTN2 000D - KENNUNG_X - WW(WW) - + * HEXWERT1,HEXWERT2,HEXWERTN1,HEXWERTN2 000E - KENNUNG_ALL - SW(W) - + * KENNUNG,HEXWERT1,HEXWERTN 000F - PARZUWEISUNG_PSW2 - (B) - DATUM 0010 - + * PARZUWEISUNG_PSW1 - W(B) - PSW,DATUM 0011 - PARZUWEISUNG_DIR - + * {L}LWW{B}(B)(A)B - BLOCKNR,WORTADR,BYTEADR,FSW,INDEX,MASKE,OPERATION,EINHEIT + * 0012 - PARZUWEISUNG_FSW - {L}LWW{B}(B){B}{B} - + * BLOCKNR,WORTADR,BYTEADR,FSW,INDEX,MASKE,EINHEIT,INDIVID + */ + + // Look for 0xFFFF in the file to skip the header + dataIndex = getStartOfFile(dataBuffer); + + if (dataIndex == 0) { + throw new SAXException(rb.getString("ERRORFILESTART") + f.toString()); } - else if(layout.equalsIgnoreCase("wordlsb")) { - memoryLayout = "uint16"; - endian = "little"; + + while (dataIndex < input.length) { + int oldIndex = dataIndex; + + int length = 0xFFFF & dataBuffer.get(dataIndex); + int frameType = 0xFFFF & dataBuffer.getShort(dataIndex + 1); + dataIndex += 2; + + switch (frameType) { + case SPEICHERORG: + parseMemoryOrg(); + break; + case TYPE_DATEINAME: + // String fileNameInFile = readString(input, i+1); + break; + // "Unused" Data, which often contains hidden data + case UNBELEGT1: + parseUnused(); + break; + // Not sure what to do with this + case UNBELEGT2: + break; + // Coding Block (=category) + // Fall-Through! + case CODIERDATENBLOCK: + case HERSTELLERDATENBLOCK: + case RESERVIERTDATENBLOCK: + parseGroup(); + break; + case PARZUWEISUNG_DIR: + parseFSWValues(false); + break; + case PARZUWEISUNG_FSW: + parseFSWValues(false); + break; + + case PARZUWEISUNG_PSW1: + parsePresetValues(true); + break; + case PARZUWEISUNG_PSW2: + parsePresetValues(false); + break; + } + + // No matter what the index points to, always go by length + // Skip frameType, checksum and go to next + dataIndex = oldIndex + length + 4; } - */ - dataIndex+= layout.length() + 2; - //String blockType = readString(input, i); //? What does it do? - //isBlock = blockType.equals("BLOCK"); + + for (BMWConversionRomNodeManager man : romManagers) { + man.calculateRomID(f, "BMW"); + } + + return doc; } - + + private void parseMemoryOrg() { + String layout = readString(dataBuffer.array(), dataIndex + 1); + + /* + * if(layout.equalsIgnoreCase("byte")) memoryLayout = "uint8"; else + * if(layout.equalsIgnoreCase("wordmsb")) { memoryLayout = "uint16"; endian = + * "big"; } else if(layout.equalsIgnoreCase("wordlsb")) { memoryLayout = + * "uint16"; endian = "little"; } + */ + dataIndex += layout.length() + 2; + // String blockType = readString(input, i); //? What does it do? + // isBlock = blockType.equals("BLOCK"); + } + private void parseUnused() { short blockU = dataBuffer.getShort(dataIndex); - dataIndex+=2; - - if(blockU!=0) { - //int blockNumber = dataBuffer.getInt(i); //Whats it for? - dataIndex+=4; + dataIndex += 2; + + if (blockU != 0) { + // int blockNumber = dataBuffer.getInt(i); //Whats it for? + dataIndex += 4; } - + int storageAddressU = dataBuffer.getInt(dataIndex); - int byteCountU = dataBuffer.getShort(dataIndex+4); - - byte indexU = dataBuffer.get(dataIndex+6); - dataIndex +=indexU; - - int maskLengthU = 0xFFFF & dataBuffer.getShort(dataIndex+7); + int byteCountU = dataBuffer.getShort(dataIndex + 4); + + byte indexU = dataBuffer.get(dataIndex + 6); + dataIndex += indexU; + + int maskLengthU = 0xFFFF & dataBuffer.getShort(dataIndex + 7); byte[] maskU = new byte[maskLengthU]; - - for(int j=0;j listFileTree(File dir) { - Set fileTree = new HashSet(); - if(dir==null||dir.listFiles()==null){ - return fileTree; - } - for (File entry : dir.listFiles()) { - if (entry.isFile()) fileTree.add(entry); - else fileTree.addAll(listFileTree(entry)); - } - return fileTree; + Set fileTree = new HashSet(); + if (dir == null || dir.listFiles() == null) { + return fileTree; + } + for (File entry : dir.listFiles()) { + if (entry.isFile()) + fileTree.add(entry); + else + fileTree.addAll(listFileTree(entry)); + } + return fileTree; } - - //Test Code + + // Test Code public static void main(String args[]) { - initDebugLogging(); - initLookAndFeel(); - ECUEditor editor = getECUEditor(); - editor.initializeEditorUI(); - editor.checkDefinitions(); - - //Make sure we dont override any settings + initDebugLogging(); + initLookAndFeel(); + ECUEditor editor = getECUEditor(); + editor.initializeEditorUI(); + editor.checkDefinitions(); + + // Make sure we dont override any settings SettingsManager.setTesting(true); - Settings settings = SettingsManager.getSettings(); - + Settings settings = SettingsManager.getSettings(); + settings.getEcuDefinitionFiles().clear(); - //settings.getEcuDefinitionFiles().add(new File("C:\\NCSEXPER\\DATEN\\E46\\KMB_E46.C08")); - //settings.getEcuDefinitionFiles().add(new File("C:\\NCSEXPER\\DATEN\\E46\\IHK_E46.C17")); - //settings.getEcuDefinitionFiles().add(new File("C:\\NCSEXPER\\DATEN\\E46\\GM5.C04")); - + // settings.getEcuDefinitionFiles().add(new + // File("C:\\NCSEXPER\\DATEN\\E46\\KMB_E46.C08")); + // settings.getEcuDefinitionFiles().add(new + // File("C:\\NCSEXPER\\DATEN\\E46\\IHK_E46.C17")); + // settings.getEcuDefinitionFiles().add(new + // File("C:\\NCSEXPER\\DATEN\\E46\\GM5.C04")); File folder = new File("C:\\NCSEXPER\\DATEN\\"); - Collection listOfFiles = listFileTree(folder); + Collection listOfFiles = listFileTree(folder); ConversionLayer l = new BMWCodingConversionLayer(); - - for(File f: listOfFiles) { + + for (File f : listOfFiles) { if (l.isFileSupported(f)) { settings.getEcuDefinitionFiles().add(f); } } - - //settings.getEcuDefinitionFiles().add(new File("C:\\NCSEXPER\\DATEN\\E36\\KMB_E36.C25")); - OpenImageWorker w = new OpenImageWorker(new File("E:\\google_drive\\ECU_Tuning\\maps\\Tacho\\Tacho Grau\\C25_352k_248_oil_6Cyl.hex")); - //OpenImageWorker w = new OpenImageWorker(new File("E:\\Downloads\\ZKE_eep.bin")); - //OpenImageWorker w = new OpenImageWorker(new File("E:\\Downloads\\A-C_eep.bin")); - //OpenImageWorker w = new OpenImageWorker(new File("E:\\Downloads\\MFL_0000-1000.bin")); - //OpenImageWorker w = new OpenImageWorker(new File("E:\\Downloads\\IKE_eep.bin")); + + // settings.getEcuDefinitionFiles().add(new + // File("C:\\NCSEXPER\\DATEN\\E36\\KMB_E36.C25")); + OpenImageWorker w = new OpenImageWorker( + new File("E:\\google_drive\\ECU_Tuning\\maps\\Tacho\\Tacho Grau\\C25_352k_248_oil_6Cyl.hex")); + // OpenImageWorker w = new OpenImageWorker(new + // File("E:\\Downloads\\ZKE_eep.bin")); + // OpenImageWorker w = new OpenImageWorker(new + // File("E:\\Downloads\\A-C_eep.bin")); + // OpenImageWorker w = new OpenImageWorker(new + // File("E:\\Downloads\\MFL_0000-1000.bin")); + // OpenImageWorker w = new OpenImageWorker(new + // File("E:\\Downloads\\IKE_eep.bin")); w.execute(); } -} + @Override + public String getDefinitionPickerInfo() { + return rb.getString("LOADINGWARNING"); + } +} diff --git a/src/main/java/com/romraider/xml/ConversionLayer/ConversionLayer.java b/src/main/java/com/romraider/xml/ConversionLayer/ConversionLayer.java index be19c4bf..200ffb55 100644 --- a/src/main/java/com/romraider/xml/ConversionLayer/ConversionLayer.java +++ b/src/main/java/com/romraider/xml/ConversionLayer/ConversionLayer.java @@ -33,6 +33,8 @@ public abstract class ConversionLayer { public final static String xmlRegexFileNameFilter = "^.*\\.(xml|XML)$"; + public abstract String getDefinitionPickerInfo(); + public abstract String getRegexFileNameFilter(); /* diff --git a/src/main/java/com/romraider/xml/ConversionLayer/XDFConversionLayer.java b/src/main/java/com/romraider/xml/ConversionLayer/XDFConversionLayer.java index 8ce4cfed..776f97e2 100644 --- a/src/main/java/com/romraider/xml/ConversionLayer/XDFConversionLayer.java +++ b/src/main/java/com/romraider/xml/ConversionLayer/XDFConversionLayer.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.ResourceBundle; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -46,9 +47,12 @@ import com.romraider.Settings; import com.romraider.editor.ecu.ECUEditor; import com.romraider.editor.ecu.OpenImageWorker; import com.romraider.util.HexUtil; +import com.romraider.util.ResourceUtil; import com.romraider.util.SettingsManager;; public class XDFConversionLayer extends ConversionLayer { + protected static final ResourceBundle rb = new ResourceUtil().getBundle( + XDFConversionLayer.class.getName()); private static final Logger LOGGER = Logger.getLogger(XDFConversionLayer.class); private HashMap categoryMap = new HashMap(); @@ -65,6 +69,11 @@ public class XDFConversionLayer extends ConversionLayer { // Defaults String defaultDataType; + @Override + public String getDefinitionPickerInfo() { + return rb.getString("LOADINGWARNING"); + } + @Override public String getRegexFileNameFilter() { return "^.*xdf"; @@ -84,8 +93,7 @@ public class XDFConversionLayer extends ConversionLayer { if (firstLine.equalsIgnoreCase("XDF")) { br.close(); - // TODO: Add i18n - throw new SAXException("Sorry, only XML XDFs are currently supported!"); + throw new SAXException(rb.getString("ONLYXML")); } else { br.close(); } @@ -495,8 +503,7 @@ public class XDFConversionLayer extends ConversionLayer { } if (baseNode == xdfDoc) { - //TODO: Add i18n - throw new SAXException("XDF file does not have an XDFFORMAT element!"); + throw new SAXException(rb.getString("NOXDFFORMAT")); } nodeCount = baseNode.getChildNodes().getLength(); @@ -522,8 +529,7 @@ public class XDFConversionLayer extends ConversionLayer { } if (header == null) { - //TODO:Add i18n - throw new SAXException("XDF file does not have an XDFHEADER element!"); + throw new SAXException(rb.getString("NOXDFHEADER")); } // Go through all tables and create RR tables