Enhancement Issue #46:

- Added ability to convert image from 160kb to 192kb
 - Added ability to convert image from 192kb to 160kb
 - Cleaned up the ECUEditorMenuBar class.
Note: Conversion uses method described by throttlehappy (http://romraider.com/forum/viewtopic.php?p=70875#p70875).
This commit is contained in:
Scotthew 2013-12-29 01:25:56 -08:00
parent ff650a0e3e
commit 012728b656
3 changed files with 260 additions and 110 deletions

View File

@ -115,6 +115,12 @@ public class Settings implements Serializable {
/* Rom Settings */ /* Rom Settings */
public static final int CHECK_TOTAL = 0x5AA5A55A; public static final int CHECK_TOTAL = 0x5AA5A55A;
public static final int SIXTEENBIT_START_ADDRESS = 0x20000;
public static final int SIXTEENBIT_END_ADDRESS = 0x28000;
public static final int SIXTEENBIT_SMALL_SIZE = 0x28000;
public static final int SIXTEENBIT_LARGE_SIZE = 0x30000;
public static final int SIXTEENBIT_SEGMENT_SIZE = SIXTEENBIT_SMALL_SIZE - SIXTEENBIT_START_ADDRESS; // 0x8000
public static final int SIXTEENBIT_SEGMENT_VALUE = 0x00;
/* Scale Settings */ /* Scale Settings */
public static final int LINEAR = 1; public static final int LINEAR = 1;

View File

@ -71,12 +71,16 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
private final JMenu definitionMenu = new JMenu("ECU Definitions"); private final JMenu definitionMenu = new JMenu("ECU Definitions");
private final JMenuItem defManager = new JMenuItem("ECU Definition Manager..."); private final JMenuItem defManager = new JMenuItem("ECU Definition Manager...");
// private JMenuItem editDefinition = new JMenuItem("Edit ECU Definitions..."); private final JMenuItem editDefinition = new JMenuItem("Edit ECU Definitions...");
private final JMenuItem updateDefinition = new JMenuItem("Get ECU Definitions..."); private final JMenuItem updateDefinition = new JMenuItem("Get ECU Definitions...");
private final JMenu editMenu = new JMenu("Edit"); private final JMenu editMenu = new JMenu("Edit");
private final JMenuItem settings = new JMenuItem(PRODUCT_NAME + " Settings..."); private final JMenuItem settings = new JMenuItem(PRODUCT_NAME + " Settings...");
private final JMenuItem compareImages = new JMenuItem("Compare Images..."); private final JMenuItem compareImages = new JMenuItem("Compare Images...");
private final JMenu convertRom = new JMenu("Convert Image");
private final JMenuItem convertIncrease = new JMenuItem("160KB --> 192KB...");
private final JMenuItem convertDecrease = new JMenuItem("192KB --> 160KB...");
private final ButtonGroup convertGroup = new ButtonGroup();
private final JMenu viewMenu = new JMenu("View"); private final JMenu viewMenu = new JMenu("View");
private final JMenuItem romProperties = new JMenuItem("ECU Image Properties"); private final JMenuItem romProperties = new JMenuItem("ECU Image Properties");
@ -101,84 +105,122 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
// file menu items // file menu items
add(fileMenu); add(fileMenu);
fileMenu.setMnemonic('F'); fileMenu.setMnemonic('F');
openImage.setMnemonic('O');
openImage.setMnemonic('I');
saveImage.setMnemonic('S');
saveAsRepository.setMnemonic('D');
refreshImage.setMnemonic('R');
closeImage.setMnemonic('C');
//closeAll.setMnemonic('A');
exit.setMnemonic('X');
fileMenu.add(openImage); fileMenu.add(openImage);
//fileMenu.add(openImages);
fileMenu.add(saveImage);
fileMenu.add(saveAsRepository);
fileMenu.add(refreshImage);
fileMenu.add(new JSeparator());
fileMenu.add(closeImage);
//fileMenu.add(closeAll);
fileMenu.add(new JSeparator());
fileMenu.add(exit);
openImage.addActionListener(this); openImage.addActionListener(this);
openImage.setMnemonic('O');
//fileMenu.add(openImages);
//openImages.addActionListener(this); //openImages.addActionListener(this);
//openImages.setMnemonic('I');
fileMenu.add(saveImage);
saveImage.addActionListener(this); saveImage.addActionListener(this);
saveImage.setMnemonic('S');
fileMenu.add(saveAsRepository);
saveAsRepository.setMnemonic('D');
saveAsRepository.addActionListener(this); saveAsRepository.addActionListener(this);
fileMenu.add(refreshImage);
refreshImage.addActionListener(this); refreshImage.addActionListener(this);
refreshImage.setMnemonic('R');
fileMenu.add(new JSeparator());
fileMenu.add(closeImage);
closeImage.addActionListener(this); closeImage.addActionListener(this);
closeImage.setMnemonic('C');
//fileMenu.add(closeAll);
//closeAll.addActionListener(this); //closeAll.addActionListener(this);
//closeAll.setMnemonic('A');
fileMenu.add(new JSeparator());
fileMenu.add(exit);
exit.addActionListener(this); exit.addActionListener(this);
exit.setMnemonic('X');
// edit menu items // edit menu items
add(editMenu); add(editMenu);
editMenu.setMnemonic('E'); editMenu.setMnemonic('E');
editMenu.add(settings); editMenu.add(settings);
settings.addActionListener(this); settings.addActionListener(this);
settings.setMnemonic('S');
editMenu.add(compareImages); editMenu.add(compareImages);
compareImages.addActionListener(this); compareImages.addActionListener(this);
compareImages.setMnemonic('C');
editMenu.add(convertRom);
convertRom.setMnemonic('O');
convertRom.add(convertIncrease);
convertIncrease.addActionListener(this);
convertIncrease.setMnemonic('I');
convertRom.add(convertDecrease);
convertDecrease.addActionListener(this);
convertDecrease.setMnemonic('D');
convertGroup.add(convertIncrease);
convertGroup.add(convertDecrease);
// ecu def menu items // ecu def menu items
add(definitionMenu); add(definitionMenu);
definitionMenu.setMnemonic('D'); definitionMenu.setMnemonic('D');
defManager.setMnemonic('D');
// editDefinition.setMnemonic('E');
updateDefinition.setMnemonic('U');
settings.setMnemonic('S');
compareImages.setMnemonic('C');
definitionMenu.add(defManager); definitionMenu.add(defManager);
// definitionMenu.add(editDefinition);
definitionMenu.add(updateDefinition);
defManager.addActionListener(this); defManager.addActionListener(this);
// editDefinition.addActionListener(this); defManager.setMnemonic('D');
definitionMenu.add(updateDefinition);
updateDefinition.addActionListener(this); updateDefinition.addActionListener(this);
updateDefinition.setMnemonic('U');
//definitionMenu.add(editDefinition);
//editDefinition.setMnemonic('E');
//editDefinition.addActionListener(this);
// view menu items // view menu items
add(viewMenu); add(viewMenu);
viewMenu.setMnemonic('V'); viewMenu.setMnemonic('V');
romProperties.setMnemonic('P');
levelMenu.setMnemonic('U');
level1.setMnemonic('1');
level2.setMnemonic('2');
level3.setMnemonic('3');
level4.setMnemonic('4');
level5.setMnemonic('5');
viewMenu.add(romProperties); viewMenu.add(romProperties);
viewMenu.add(levelMenu);
levelMenu.add(level1);
levelMenu.add(level2);
levelMenu.add(level3);
levelMenu.add(level4);
levelMenu.add(level5);
romProperties.addActionListener(this); romProperties.addActionListener(this);
romProperties.setMnemonic('P');
viewMenu.add(levelMenu);
levelMenu.setMnemonic('U');
levelMenu.add(level1);
level1.addActionListener(this); level1.addActionListener(this);
level1.setMnemonic('1');
levelMenu.add(level2);
level2.addActionListener(this); level2.addActionListener(this);
level2.setMnemonic('2');
levelMenu.add(level3);
level3.addActionListener(this); level3.addActionListener(this);
level3.setMnemonic('3');
levelMenu.add(level4);
level4.addActionListener(this); level4.addActionListener(this);
level4.setMnemonic('4');
levelMenu.add(level5);
level5.addActionListener(this); level5.addActionListener(this);
level5.setMnemonic('5');
levelGroup.add(level1); levelGroup.add(level1);
levelGroup.add(level2); levelGroup.add(level2);
levelGroup.add(level3); levelGroup.add(level3);
levelGroup.add(level4); levelGroup.add(level4);
levelGroup.add(level5); levelGroup.add(level5);
// select correct userlevel button // select correct userlevel button
if (getSettings().getUserLevel() == 1) { if (getSettings().getUserLevel() == 1) {
level1.setSelected(true); level1.setSelected(true);
@ -192,29 +234,30 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
level5.setSelected(true); level5.setSelected(true);
} }
// logger menu stuff // logger menu items
add(loggerMenu); add(loggerMenu);
loggerMenu.setMnemonic('L'); loggerMenu.setMnemonic('L');
openLogger.setMnemonic('O');
loggerMenu.add(openLogger); loggerMenu.add(openLogger);
openLogger.addActionListener(this); openLogger.addActionListener(this);
openLogger.setMnemonic('O');
// ramtune menu stuff // ramtune menu items
add(ramTuneMenu); add(ramTuneMenu);
ramTuneMenu.setMnemonic('R'); ramTuneMenu.setMnemonic('R');
launchRamTuneTestApp.setMnemonic('L');
ramTuneMenu.add(launchRamTuneTestApp); ramTuneMenu.add(launchRamTuneTestApp);
launchRamTuneTestApp.addActionListener(this); launchRamTuneTestApp.addActionListener(this);
launchRamTuneTestApp.setMnemonic('L');
// help menu stuff // help menu items
add(helpMenu); add(helpMenu);
helpMenu.setMnemonic('H'); helpMenu.setMnemonic('H');
about.setMnemonic('A');
helpMenu.add(about); helpMenu.add(about);
about.addActionListener(this); about.addActionListener(this);
about.setMnemonic('A');
// disable unused buttons! 0.3.1
// editDefinition.setEnabled(false);
updateMenu(); updateMenu();
} }
@ -229,6 +272,7 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
saveImage.setText("Save As..."); saveImage.setText("Save As...");
saveAsRepository.setText("Save As Repository..."); saveAsRepository.setText("Save As Repository...");
compareImages.setEnabled(false); compareImages.setEnabled(false);
convertRom.setEnabled(false);
} else { } else {
saveImage.setEnabled(true); saveImage.setEnabled(true);
saveAsRepository.setEnabled(true); saveAsRepository.setEnabled(true);
@ -238,10 +282,34 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
saveImage.setText("Save " + file + " As..."); saveImage.setText("Save " + file + " As...");
saveAsRepository.setText("Save "+ file +" As Repository..."); saveAsRepository.setText("Save "+ file +" As Repository...");
compareImages.setEnabled(true); compareImages.setEnabled(true);
convertRom.setEnabled(true);
} }
refreshImage.setText("Refresh " + file); refreshImage.setText("Refresh " + file);
closeImage.setText("Close " + file); closeImage.setText("Close " + file);
romProperties.setText(file + "Properties"); romProperties.setText(file + "Properties");
int lastSelectedRomSize = 0;
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
if(null != lastSelectedRom) {
lastSelectedRomSize = lastSelectedRom.getRealFileSize();
}
if(Settings.SIXTEENBIT_SMALL_SIZE == lastSelectedRomSize) {
compareImages.setEnabled(true);
convertIncrease.setEnabled(true);
convertDecrease.setEnabled(false);
} else if (Settings.SIXTEENBIT_LARGE_SIZE == lastSelectedRomSize) {
compareImages.setEnabled(true);
convertIncrease.setEnabled(false);
convertDecrease.setEnabled(true);
} else {
compareImages.setEnabled(false);
convertIncrease.setEnabled(false);
convertDecrease.setEnabled(false);
}
openImages.setEnabled(false);
editDefinition.setEnabled(false);
revalidate(); revalidate();
} }
@ -266,14 +334,14 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
} else if (e.getSource() == saveImage) { } else if (e.getSource() == saveImage) {
try { try {
this.saveImage(parent.getLastSelectedRom()); this.saveImage();
} catch (Exception ex) { } catch (Exception ex) {
showMessageDialog(parent, showMessageDialog(parent,
new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
} }
} else if (e.getSource() == saveAsRepository) { } else if (e.getSource() == saveAsRepository) {
try { try {
this.saveAsRepository(parent.getLastSelectedRom(), getSettings().getLastRepositoryDir()); this.saveAsRepository();
} catch(Exception ex) { } catch(Exception ex) {
showMessageDialog(parent, showMessageDialog(parent,
new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
@ -295,7 +363,6 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
} else if (e.getSource() == refreshImage) { } else if (e.getSource() == refreshImage) {
try { try {
refreshImage(); refreshImage();
} catch (Exception ex) { } catch (Exception ex) {
showMessageDialog(parent, new DebugPanel(ex, showMessageDialog(parent, new DebugPanel(ex,
getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
@ -311,6 +378,24 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
form.setLocationRelativeTo(parent); form.setLocationRelativeTo(parent);
form.setVisible(true); form.setVisible(true);
} else if (e.getSource() == convertIncrease) {
try {
increaseRomSize();
refreshImage();
} catch (Exception ex) {
showMessageDialog(parent,
new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
}
} else if (e.getSource() == convertDecrease) {
try {
decreaseRomSize();
refreshImage();
} catch (Exception ex) {
showMessageDialog(parent,
new DebugPanel(ex, getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
}
} else if (e.getSource() == defManager) { } else if (e.getSource() == defManager) {
DefinitionManager form = new DefinitionManager(); DefinitionManager form = new DefinitionManager();
form.setLocationRelativeTo(parent); form.setLocationRelativeTo(parent);
@ -384,24 +469,38 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
} }
} }
public void saveImage(Rom input) throws Exception { public void saveImage() throws Exception {
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
if (lastSelectedRom != null) {
File selectedFile = getImageOutputFile();
if(null != selectedFile){
byte[] output = lastSelectedRom.saveFile();
this.writeImage(output, selectedFile);
}
}
}
private File getImageOutputFile() throws Exception {
ECUEditor parent = ECUEditorManager.getECUEditor(); ECUEditor parent = ECUEditorManager.getECUEditor();
if (parent.getLastSelectedRom() != null) {
JFileChooser fc = new JFileChooser(SettingsManager.getSettings().getLastImageDir()); JFileChooser fc = new JFileChooser(SettingsManager.getSettings().getLastImageDir());
fc.setFileFilter(new ECUImageFilter()); fc.setFileFilter(new ECUImageFilter());
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) { if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
boolean save = true;
File selectedFile = fc.getSelectedFile(); File selectedFile = fc.getSelectedFile();
if (selectedFile.exists()) { if (selectedFile.exists()) {
int option = showConfirmDialog(parent, selectedFile.getName() + " already exists! Overwrite?"); int option = showConfirmDialog(parent, selectedFile.getName() + " already exists! Overwrite?");
// option: 0 = Cancel, 1 = No // option: 0 = Cancel, 1 = No
if (option == CANCEL_OPTION || option == 1) { if (option == CANCEL_OPTION || option == 1) {
save = false; return null;
} }
} }
if (save) { return selectedFile;
byte[] output = parent.getLastSelectedRom().saveFile(); }
return null;
}
private void writeImage(byte[] output, File selectedFile) throws Exception {
ECUEditor parent = ECUEditorManager.getECUEditor();
FileOutputStream fos = new FileOutputStream(selectedFile); FileOutputStream fos = new FileOutputStream(selectedFile);
try { try {
fos.write(output); fos.write(output);
@ -412,33 +511,37 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
parent.setLastSelectedRom(parent.getLastSelectedRom()); parent.setLastSelectedRom(parent.getLastSelectedRom());
SettingsManager.getSettings().setLastImageDir(selectedFile.getParentFile()); SettingsManager.getSettings().setLastImageDir(selectedFile.getParentFile());
} }
}
}
}
private void saveAsRepository(Rom image, File lastRepositoryDir) throws Exception { private File getRepositoryOutputDir() {
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(lastRepositoryDir); fc.setCurrentDirectory(getSettings().getLastRepositoryDir());
fc.setDialogTitle("Select Repository Directory"); fc.setDialogTitle("Select Repository Directory");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// disable the "All files" option // disable the "All files" option
fc.setAcceptAllFileFilterUsed(false); fc.setAcceptAllFileFilterUsed(false);
String separator = System.getProperty("file.separator");
if (fc.showSaveDialog(ECUEditorManager.getECUEditor()) == JFileChooser.APPROVE_OPTION) { if (fc.showSaveDialog(ECUEditorManager.getECUEditor()) == JFileChooser.APPROVE_OPTION) {
boolean save = true;
File selectedDir = fc.getSelectedFile(); File selectedDir = fc.getSelectedFile();
if (selectedDir.exists()) { if (selectedDir.exists()) {
int option = showConfirmDialog(ECUEditorManager.getECUEditor(), selectedDir.getName() + " already exists! Overwrite?"); int option = showConfirmDialog(ECUEditorManager.getECUEditor(), selectedDir.getName() + " already exists! Overwrite?");
// option: 0 = Cancel, 1 = No // option: 0 = Cancel, 1 = No
if (option == CANCEL_OPTION || option == 1) { if (option == CANCEL_OPTION || option == 1) {
save = false; return null;
} }
} }
if(save) { return selectedDir;
for(TableTreeNode treeNode : image.getTableNodes()) }
return null;
}
private void saveAsRepository() throws Exception {
File selectedDir = getRepositoryOutputDir();
String separator = System.getProperty("file.separator");
if(null != selectedDir) {
for(TableTreeNode treeNode : ECUEditorManager.getECUEditor().getLastSelectedRom().getTableNodes())
{ {
Table table = treeNode.getTable(); Table table = treeNode.getTable();
String category = table.getCategory(); String category = table.getCategory();
@ -470,6 +573,47 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
getSettings().setLastRepositoryDir(selectedDir); getSettings().setLastRepositoryDir(selectedDir);
} }
} }
private void increaseRomSize() throws Exception{
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
if (lastSelectedRom != null) {
File selectedFile = getImageOutputFile();
if(null != selectedFile){
if(lastSelectedRom.getRealFileSize() != Settings.SIXTEENBIT_SMALL_SIZE)
{
showMessageDialog(ECUEditorManager.getECUEditor(), "Error converting image. Image size is invalid.");
} else {
byte[] output = lastSelectedRom.saveFile();
byte[] incOutput = new byte[Settings.SIXTEENBIT_LARGE_SIZE];
System.arraycopy(output, 0, incOutput, 0, Settings.SIXTEENBIT_START_ADDRESS);
System.arraycopy(output, Settings.SIXTEENBIT_START_ADDRESS, incOutput, Settings.SIXTEENBIT_END_ADDRESS, Settings.SIXTEENBIT_SEGMENT_SIZE);
for(int i = Settings.SIXTEENBIT_START_ADDRESS; i < Settings.SIXTEENBIT_END_ADDRESS; i++) {
// Fill space.
incOutput[i] = Settings.SIXTEENBIT_SEGMENT_VALUE;
}
this.writeImage(incOutput, selectedFile);
}
}
}
}
private void decreaseRomSize() throws Exception {
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
if (lastSelectedRom != null) {
File selectedFile = getImageOutputFile();
if(null != selectedFile){
if(lastSelectedRom.getRealFileSize() != Settings.SIXTEENBIT_LARGE_SIZE)
{
showMessageDialog(ECUEditorManager.getECUEditor(), "Error converting image. Image size is invalid.");
} else {
byte[] output =lastSelectedRom.saveFile();
byte[] decOutput = new byte[Settings.SIXTEENBIT_SMALL_SIZE];
System.arraycopy(output, 0, decOutput, 0, Settings.SIXTEENBIT_START_ADDRESS);
System.arraycopy(output, Settings.SIXTEENBIT_END_ADDRESS, decOutput, Settings.SIXTEENBIT_START_ADDRESS, Settings.SIXTEENBIT_SEGMENT_SIZE);
this.writeImage(decOutput, selectedFile);
}
}
}
} }
private String getLastSelectedRomFileName() { private String getLastSelectedRomFileName() {

View File

@ -129,7 +129,7 @@ public class ECUEditorToolBar extends JToolBar implements ActionListener {
} }
} else if (e.getSource() == saveImage) { } else if (e.getSource() == saveImage) {
try { try {
((ECUEditorMenuBar) getEditor().getJMenuBar()).saveImage(getEditor().getLastSelectedRom()); ((ECUEditorMenuBar) getEditor().getJMenuBar()).saveImage();
getEditor().refreshUI(); getEditor().refreshUI();
} catch (Exception ex) { } catch (Exception ex) {
JOptionPane.showMessageDialog(getEditor(), new DebugPanel(ex, JOptionPane.showMessageDialog(getEditor(), new DebugPanel(ex,