Added i18n strings, added warning popups for conversion layers, moved tabletree creation into main thread

This commit is contained in:
Robin 2022-01-23 18:34:20 +01:00
parent d657378445
commit e0822c9e0a
10 changed files with 565 additions and 507 deletions

View File

@ -8,3 +8,5 @@ SAVE = Save
CANCEL = Cancel
APPLY = Apply
UNDO = Undo
CONVERSIONTITLE = Conversion Layer Warning

View File

@ -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.

View File

@ -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.

View File

@ -54,6 +54,7 @@ import com.romraider.xml.ConversionLayer.ConversionLayerFactory;
public class OpenImageWorker extends SwingWorker<Void, Void> {
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<Void, Void> {
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<Void, Void> {
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 {
@ -317,10 +316,20 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
@Override
public void done() {
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);
}
}
}

View File

@ -435,7 +435,11 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
TableFrame frame = tableTreeNode.getFrame();
TableUpdateHandler.getInstance().deregisterTable(tableTreeNode.getTable());
tableTreeNode.getTable().clearData();
// Quite slow and doesn't seem to be necessary after testing,
// uncomment if you disagree
//tableTreeNode.getTable().clearData();
if(frame != null) {

View File

@ -41,7 +41,7 @@ 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() {

View File

@ -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());
}

View File

@ -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,10 +49,13 @@ 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 {
protected static final ResourceBundle rb = new ResourceUtil().getBundle(BMWCodingConversionLayer.class.getName());
private int splitAddress = 0;
boolean guessChecksums = false;
@ -143,8 +147,7 @@ public class BMWCodingConversionLayer extends ConversionLayer {
return null;
} catch (final IOException e) {
return null;
}
finally {
} finally {
try {
if (br != null) {
br.close();
@ -211,12 +214,9 @@ public class BMWCodingConversionLayer extends ConversionLayer {
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 = "";
@ -243,8 +243,7 @@ public class BMWCodingConversionLayer extends ConversionLayer {
currentOption = aswMap.get(keyId);
optionCode = optionCode + currentOption;
j += 3;
}
else {
} else {
optionCode += (char) cvtBuffer.get(j + i);
j++;
}
@ -302,24 +301,26 @@ public class BMWCodingConversionLayer extends ConversionLayer {
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);
throw new SAXException(rb.getString("MISSINGFILE") + "SWTFSW.dat. " + rb.getString("NCSHINT"));
}
if (!pswF.exists()) {
throw new SAXException("Failed to find " + pswF);
throw new SAXException(rb.getString("MISSINGFILE") + "SWTPSW.dat. " + rb.getString("NCSHINT"));
}
if (!aswF.exists()) {
throw new SAXException("Failed to find " + aswF);
throw new SAXException(rb.getString("MISSINGFILE") + "SWTASW.dat. " + rb.getString("NCSHINT"));
}
if (!csvF.exists()) {
throw new SAXException("Failed to find " + csvF);
throw new SAXException(rb.getString("MISSINGFILE") + "CVT.000. " + rb.getString("NCSHINT"));
}
fswMap = createMapFromNCSDict(fswF);
@ -330,14 +331,15 @@ public class BMWCodingConversionLayer extends ConversionLayer {
// 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);
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);
@ -348,42 +350,38 @@ public class BMWCodingConversionLayer extends ConversionLayer {
// Create one manager if no splitting
// Create two otherwise
if(splitAddress == 0) romManagers= new BMWConversionRomNodeManager[] {new BMWConversionRomNodeManager(0, doc, roms)};
if (splitAddress == 0)
romManagers = new BMWConversionRomNodeManager[] { new BMWConversionRomNodeManager(0, doc, roms) };
else
romManagers= new BMWConversionRomNodeManager[] {
new BMWConversionRomNodeManager(0, doc, roms),
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
* 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());
throw new SAXException(rb.getString("ERRORFILESTART") + f.toString());
}
while (dataIndex < input.length) {
int oldIndex = dataIndex;
@ -443,15 +441,10 @@ public class BMWCodingConversionLayer extends ConversionLayer {
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";
}
* 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?
@ -482,13 +475,13 @@ public class BMWCodingConversionLayer extends ConversionLayer {
dataIndex = dataIndex + 9 + maskLengthU;
// Create actual node in rom
for (BMWConversionRomNodeManager man : romManagers) {
Element table = man.createTable("UNUSED_" + unusedCounter,
currentCategory, memoryLayout, endian,storageAddressU, byteCountU, maskU);
Element table = man.createTable("UNUSED_" + unusedCounter, currentCategory, memoryLayout, endian,
storageAddressU, byteCountU, maskU);
if(table != null) currentTable = table;
if (table != null)
currentTable = table;
}
unusedCounter++;
@ -558,10 +551,11 @@ public class BMWCodingConversionLayer extends ConversionLayer {
// Create actual node in rom
for (BMWConversionRomNodeManager man : romManagers) {
Element table = man.createTable(nameFSWD,
currentCategory, memoryLayout, endian,storageAddressD, byteCountD, maskD);
Element table = man.createTable(nameFSWD, currentCategory, memoryLayout, endian, storageAddressD,
byteCountD, maskD);
if(table != null) currentTable = table;
if (table != null)
currentTable = table;
}
}
@ -598,7 +592,8 @@ public class BMWCodingConversionLayer extends ConversionLayer {
// Add option combinations
int key = currentFSW << 16 | functionKeywordPSW;
if(csvMap.containsKey(key))namePSW += " | " + csvMap.get(key);
if (csvMap.containsKey(key))
namePSW += " | " + csvMap.get(key);
}
for (BMWConversionRomNodeManager man : romManagers) {
@ -614,8 +609,10 @@ public class BMWCodingConversionLayer extends ConversionLayer {
return fileTree;
}
for (File entry : dir.listFiles()) {
if (entry.isFile()) fileTree.add(entry);
else fileTree.addAll(listFileTree(entry));
if (entry.isFile())
fileTree.add(entry);
else
fileTree.addAll(listFileTree(entry));
}
return fileTree;
}
@ -633,10 +630,12 @@ public class BMWCodingConversionLayer extends ConversionLayer {
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<File> listOfFiles = listFileTree(folder);
@ -649,14 +648,24 @@ public class BMWCodingConversionLayer extends ConversionLayer {
}
}
//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");
}
}

View File

@ -33,6 +33,8 @@ public abstract class ConversionLayer {
public final static String xmlRegexFileNameFilter = "^.*\\.(xml|XML)$";
public abstract String getDefinitionPickerInfo();
public abstract String getRegexFileNameFilter();
/*

View File

@ -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<Integer, String> categoryMap = new HashMap<Integer, String>();
@ -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