diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java index 5d5386284..fb2c5232d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -86,7 +87,7 @@ public abstract class AVM2Item extends GraphTargetItem { if (reg == 0) { return "this"; } - return "_loc" + reg + "_"; + return String.format(Configuration.registerNameFormat.get(), reg); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java index 308592ac5..68eaf56fb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.swf4; +import com.jpexs.decompiler.flash.configuration.Configuration; import java.io.Serializable; public class RegisterNumber implements Serializable { @@ -63,7 +64,7 @@ public class RegisterNumber implements Serializable { public String translate() { if (name == null || name.trim().isEmpty()) { - return "_loc" + number + "_"; + return String.format(Configuration.registerNameFormat.get(), number); } return name; } diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index f70eea67d..4262e99a0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -93,6 +93,7 @@ public class Configuration { put("lastOpenDir", "."); put("offeredAssociation", false); put("locale", "en"); + put("registerNameFormat", "_loc%d_"); put("lastUpdatesCheckDate", null); put("gui.window.width", 1000); put("gui.window.height", 700); @@ -114,13 +115,13 @@ public class Configuration { public static final ConfigurationItem removeNops = null; public static final ConfigurationItem decompilationTimeoutSingleMethod = null; - public static final ConfigurationItem xxx = null; public static final ConfigurationItem lastRenameType = null; public static final ConfigurationItem lastSaveDir = null; public static final ConfigurationItem lastOpenDir = null; public static final ConfigurationItem lastExportDir = null; public static final ConfigurationItem locale = null; + public static final ConfigurationItem registerNameFormat = null; public static final ConfigurationItem lastUpdatesCheckDate = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.form b/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.form index f040e67b3..44f553e37 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.form +++ b/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.form @@ -1,6 +1,6 @@ -
+ @@ -24,13 +24,90 @@ - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> + <Connection component="configurationTable" name="cellEditor" type="property"/> + </Editor> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JButton" name="btnOk"> + <Properties> + <Property name="text" type="java.lang.String" value="OK"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOkActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="btnCancel"> + <Properties> + <Property name="text" type="java.lang.String" value="Cancel"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/> + </Events> + </Component> + </SubComponents> </Form> diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java index 52375b335..bf536451a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java @@ -16,6 +16,16 @@ */ package com.jpexs.decompiler.flash.gui; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.configuration.ConfigurationItem; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.Map.Entry; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + /** * * @author JPEXS @@ -30,6 +40,21 @@ public class AdvancedSettingsDialog extends AppDialog { View.centerScreen(this); View.setWindowIcon(this); pack(); + + configurationTable.setCellEditor(configurationTable.getDefaultEditor(null)); + + Map<String, Field> fields = Configuration.getConfigurationFields(); + for (Entry<String, Field> entry : fields.entrySet()) { + String name = entry.getKey(); + Field field = entry.getValue(); + DefaultTableModel model = (DefaultTableModel) configurationTable.getModel(); + try { + ConfigurationItem item = (ConfigurationItem) field.get(null); + model.addRow(new Object[]{name, item.get()}); + } catch (IllegalArgumentException | IllegalAccessException ex) { + Logger.getLogger(AdvancedSettingsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + } } /** @@ -41,23 +66,115 @@ public class AdvancedSettingsDialog extends AppDialog { // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { + jScrollPane1 = new javax.swing.JScrollPane(); + configurationTable = new com.jpexs.decompiler.flash.gui.EachRowRendererEditor(); + btnOk = new javax.swing.JButton(); + btnCancel = new javax.swing.JButton(); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setResizable(false); + configurationTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Name", "Value" + } + ) { + Class[] types = new Class [] { + java.lang.String.class, java.lang.Object.class + }; + boolean[] canEdit = new boolean [] { + false, true + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + jScrollPane1.setViewportView(configurationTable); + configurationTable.getColumnModel().getColumn(1).setCellEditor(configurationTable.getCellEditor()); + + btnOk.setText("OK"); + btnOk.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnOkActionPerformed(evt); + } + }); + + btnCancel.setText("Cancel"); + btnCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnCancelActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 400, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(btnCancel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnOk))) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnOk) + .addComponent(btnCancel)) + .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents + @SuppressWarnings("unchecked") + private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed + TableModel model = configurationTable.getModel(); + int count = model.getRowCount(); + for (int i = 0; i < count; i++) { + String name = (String) model.getValueAt(i, 0); + Object value = model.getValueAt(i, 1); + Map<String, Field> fields = Configuration.getConfigurationFields(); + Field field = fields.get(name); + ConfigurationItem item = null; + try { + item = (ConfigurationItem) field.get(null); + } catch (IllegalArgumentException | IllegalAccessException ex) { + Logger.getLogger(AdvancedSettingsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + if (item.get() != null && !item.get().equals(value)) { + item.set(value); + } + } + Configuration.saveConfig(); + setVisible(false); + }//GEN-LAST:event_btnOkActionPerformed + + private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed + setVisible(false); + }//GEN-LAST:event_btnCancelActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnCancel; + private javax.swing.JButton btnOk; + private com.jpexs.decompiler.flash.gui.EachRowRendererEditor configurationTable; + private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/EachRowRendererEditor.java b/trunk/src/com/jpexs/decompiler/flash/gui/EachRowRendererEditor.java new file mode 100644 index 000000000..ddf6d728f --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/EachRowRendererEditor.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.jpexs.decompiler.flash.gui; + +import javax.swing.JTable; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; + +/** + * + * @author JPEXS + */ +public class EachRowRendererEditor extends JTable { + + private static final long serialVersionUID = 1L; + private Class editingClass; + + @Override + public TableCellRenderer getCellRenderer(int row, int column) { + editingClass = null; + int modelColumn = convertColumnIndexToModel(column); + if (modelColumn == 1) { + Object value = getModel().getValueAt(row, modelColumn); + Class rowClass = value == null ? String.class : value.getClass(); + return getDefaultRenderer(rowClass); + } else { + return super.getCellRenderer(row, column); + } + } + + @Override + public TableCellEditor getCellEditor(int row, int column) { + editingClass = null; + int modelColumn = convertColumnIndexToModel(column); + if (modelColumn == 1) { + Object value = getModel().getValueAt(row, modelColumn); + editingClass = value == null ? String.class : value.getClass(); + return getDefaultEditor(editingClass); + } else { + return super.getCellEditor(row, column); + } + } + + // This method is also invoked by the editor when the value in the editor + // component is saved in the TableModel. The class was saved when the + // editor was invoked so the proper class can be created. + + @Override + public Class getColumnClass(int column) { + return editingClass != null ? editingClass : super.getColumnClass(column); + } +} diff --git a/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java b/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java index 3b58ff7c9..97f3d5982 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -24,8 +24,6 @@ import com.jpexs.decompiler.flash.tags.ShowFrameTag; import com.jpexs.decompiler.flash.tags.Tag; import java.io.FileInputStream; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import static org.testng.Assert.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -39,6 +37,8 @@ public class ActionScript2Test extends ActionStript2TestBase { @BeforeClass public void init() throws IOException { Configuration.autoDeobfuscate.set(false); + Configuration.decompile.set(true); + Configuration.registerNameFormat.set("_loc%d_"); swf = new SWF(new FileInputStream("testdata/as2/as2.swf"), false); } diff --git a/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java b/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java index 5dcba8034..bc7f9b625 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java +++ b/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java @@ -40,6 +40,8 @@ public class ActionScript3Test { assertTrue(clsIndex > -1); this.abc = tag.getABC(); Configuration.autoDeobfuscate.set(false); + Configuration.decompile.set(true); + Configuration.registerNameFormat.set("_loc%d_"); } private void decompileMethod(String methodName, String expectedResult, boolean isStatic) {