diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index 62d7f3774..e868b9a2e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -664,24 +664,6 @@ public class ABC { return null; } - public static String addTabs(String s, int tabs) { - String[] parts = s.split("\r\n"); - if (!s.contains("\r\n")) { - parts = s.split("\n"); - } - StringBuilder ret = new StringBuilder(); - for (int i = 0; i < parts.length; i++) { - for (int t = 0; t < tabs; t++) { - ret.append(HilightedTextWriter.INDENT_STRING); - } - ret.append(parts[i]); - if (i < parts.length - 1) { - ret.append("\r\n"); - } - } - return ret.toString(); - } - public boolean isStaticTraitId(int classIndex, int traitId) { if (traitId < class_info[classIndex].static_traits.traits.length) { return true; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 37807380f..1f29c3605 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -188,7 +188,7 @@ public class ScriptPack implements TreeElementItem { String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + ".as"; File file = new File(fileName); - try (FileTextWriter writer = new FileTextWriter(new FileOutputStream(file))) { + try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(),new FileOutputStream(file))) { try { toSource(writer, abcList, abc.script_info[scriptIndex].traits.traits, exportMode, parallel); } catch (InterruptedException ex) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 802bc269c..d448eaee5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -2247,7 +2247,7 @@ public class AVM2Code implements Serializable { invalidateCache(); try { List outputMap = new ArrayList<>(); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); toASMSource(constants, trait, info, body, outputMap, ExportMode.PCODE, writer); String src = writer.toString(); @@ -2289,7 +2289,7 @@ public class AVM2Code implements Serializable { public void removeIgnored(ConstantPool constants, Trait trait, MethodInfo info, MethodBody body) throws InterruptedException { try { List outputMap = new ArrayList<>(); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); toASMSource(constants, trait, info, body, outputMap, ExportMode.PCODE, writer); String src = writer.toString(); AVM2Code acode = ASM3Parser.parse(new StringReader(src), constants, trait, body, info); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java index 3ba08b9f5..7108f84f5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.model.UnparsedAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; @@ -40,7 +41,7 @@ public class NewClassIns extends InstructionDefinition { @Override public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, MethodBody body, ABC abc, HashMap localRegNames, List fullyQualifiedNames, String path, HashMap localRegsAssignmentIps, int ip, HashMap> refs, AVM2Code code) throws InterruptedException { int clsIndex = ins.operands[0]; - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); stack.pop().toString(writer, LocalData.create(constants, localRegNames, fullyQualifiedNames)); String baseType = writer.toString(); stack.push(new UnparsedAVM2Item(ins, "new " + abc.constants.getMultiname(abc.instance_info[clsIndex].name_index).getName(constants, fullyQualifiedNames) + ".class extends " + baseType)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java index c63eb5952..8d46e72f2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetSuperAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; @@ -54,7 +55,7 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns { public String getObject(Stack stack, ABC abc, AVM2Instruction ins, List output, MethodBody body, HashMap localRegNames, List fullyQualifiedNames) throws InterruptedException { int multinameIndex = ins.operands[0]; String multiname = resolveMultinameNoPop(1, stack, abc.constants, multinameIndex, ins, fullyQualifiedNames); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); stack.get(1 + resolvedCount(abc.constants, multinameIndex)).toString(writer, LocalData.create(abc.constants, localRegNames, fullyQualifiedNames)); String obj = writer.toString(); return obj + ".super." + multiname; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java index d150f6b28..aadde6a63 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; @@ -49,7 +50,7 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { } ((TraitSlotConst) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); writer.appendNoHilight(super.toString(abcTags, abc) + " "); if (parentTraitIndex > -1) { if (isStatic) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java index 252162f52..2a0c7f73a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.usages; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; @@ -57,7 +58,7 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage { ((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); } - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); writer.appendNoHilight(super.toString(abcTags, abc)); writer.appendNoHilight(" "); if (isInitializer) { diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 495738b2b..e1936196a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -1213,7 +1213,7 @@ public class Action implements GraphSourceItem { } String s = null; try { - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); Action.actionsToString(new ArrayList(), address, ret, null, version, ExportMode.PCODE, writer, swfPos, path); s = writer.toString(); ret = ASMParser.parse(address, swfPos, true, s, SWF.DEFAULT_VERSION, false); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java index b07966630..362202f77 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java @@ -97,13 +97,11 @@ public class FunctionActionItem extends ActionItem { } writer.append(pname); } - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")").startBlock(); Graph.graphToString(actions, writer, localData); - writer.unindent(); - return writer.append("}"); + + return writer.endBlock(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ClassActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ClassActionItem.java index 012e6ecb1..1ec94e4a9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ClassActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ClassActionItem.java @@ -161,9 +161,7 @@ public class ClassActionItem extends ActionItem implements Block { Action.getWithoutGlobal(t).toString(writer, localData); } } - writer.newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.startBlock(); if (constructor != null) { constructor.toString(writer, localData).newLine(); @@ -197,8 +195,8 @@ public class ClassActionItem extends ActionItem implements Block { f.toString(writer, localData).newLine(); } - writer.unindent(); - return writer.append("}").newLine(); + + return writer.endBlock(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java index f69e07a7d..bbe07ed5c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java @@ -88,14 +88,11 @@ public class ForInActionItem extends LoopActionItem implements Block { stripQuotes(variableName, localData, writer); writer.append(" in "); enumVariable.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")").startBlock(); for (GraphTargetItem ti : commands) { ti.toStringSemicoloned(writer, localData).newLine(); } - writer.unindent(); - writer.append("}"); + writer.endBlock(); if (writer instanceof NulWriter) { LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id); labelUsed = loopOjb.used; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java index 68e3f7176..028cd7452 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java @@ -49,12 +49,9 @@ public class IfFrameLoadedActionItem extends ActionItem implements Block { public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { writer.append("ifFrameLoaded("); frame.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); - Graph.graphToString(actions, writer, localData); - writer.unindent(); - return writer.append("}"); + writer.append(")").startBlock(); + Graph.graphToString(actions, writer, localData); + return writer.endBlock(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/InterfaceActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/InterfaceActionItem.java index 72ee8cc5b..ad828d453 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/InterfaceActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/InterfaceActionItem.java @@ -59,8 +59,7 @@ public class InterfaceActionItem extends ActionItem { Action.getWithoutGlobal(ti).toStringNoQuotes(writer, localData); } writer.newLine(); - writer.append("{").newLine(); - return writer.append("}").newLine(); + return writer.append("{").startBlock(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 5476507fa..906574c57 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.action.model.TemporaryRegister; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -297,7 +298,7 @@ public class ActionPush extends Action { @Override public String toString() { - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); toString(writer); return writer.toString(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index ac782e079..085efd963 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.configuration; import com.jpexs.decompiler.flash.ApplicationInfo; +import com.jpexs.decompiler.flash.helpers.CodeFormatting; import com.jpexs.helpers.Helper; import com.jpexs.helpers.utf8.Utf8InputStreamReader; import com.jpexs.helpers.utf8.Utf8OutputStreamWriter; @@ -48,492 +49,515 @@ import javax.swing.JOptionPane; public class Configuration { - private static final String CONFIG_NAME = "config.bin"; - private static final String REPLACEMENTS_NAME = "replacements.cfg"; - private static final File unspecifiedFile = new File("unspecified"); - private static File directory = unspecifiedFile; + private static final String CONFIG_NAME = "config.bin"; + private static final String REPLACEMENTS_NAME = "replacements.cfg"; + private static final File unspecifiedFile = new File("unspecified"); + private static File directory = unspecifiedFile; - /** - * List of replacements - */ - private static List replacements = new ArrayList<>(); + /** + * List of replacements + */ + private static List replacements = new ArrayList<>(); - public static final Level logLevel; + public static final Level logLevel; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem openMultipleFiles = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem decompile = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem parallelSpeedUp = null; - @ConfigurationDefaultInt(20) - public static final ConfigurationItem parallelThreadCount = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem autoDeobfuscate = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem cacheOnDisk = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem internalFlashViewer = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem gotoMainClassOnStartup = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem autoRenameIdentifiers = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem deobfuscateUsePrevTagOnly = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem offeredAssociation = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem removeNops = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem showHexOnlyButton = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem decimalAddress = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem showAllAddresses = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem useFrameCache = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem useRibbonInterface = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem openFolderAfterFlaExport = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem useDetailedLogging = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem openMultipleFiles = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem decompile = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem parallelSpeedUp = null; + @ConfigurationDefaultInt(20) + public static final ConfigurationItem parallelThreadCount = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem autoDeobfuscate = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem cacheOnDisk = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem internalFlashViewer = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem gotoMainClassOnStartup = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem autoRenameIdentifiers = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem deobfuscateUsePrevTagOnly = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem offeredAssociation = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem removeNops = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem showHexOnlyButton = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem decimalAddress = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem showAllAddresses = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem useFrameCache = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem useRibbonInterface = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem openFolderAfterFlaExport = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem useDetailedLogging = null; - /** - * Debug mode = throwing an error when comparing original file and - * recompiled - */ - @ConfigurationDefaultBoolean(false) - @ConfigurationDescription("Debug mode = throwing an error when comparing original file and recompiled") - public static final ConfigurationItem debugMode = null; - /** - * Turn off reading unsafe tags (tags which can cause problems with - * recompiling) - */ - @ConfigurationDefaultBoolean(false) - @ConfigurationDescription("Turn off reading unsafe tags (tags which can cause problems with recompiling)") - public static final ConfigurationItem disableDangerous = null; - /** - * Turn off resolving constants in ActionScript 2 - */ - @ConfigurationDefaultBoolean(true) - @ConfigurationDescription("Turn off resolving constants in ActionScript 2") - public static final ConfigurationItem resolveConstants = null; - /** - * Limit of code subs (for obfuscated code) - */ - @ConfigurationDefaultInt(500) - @ConfigurationDescription("Limit of code subs (for obfuscated code)") - public static final ConfigurationItem sublimiter = null; - /** - * Total export timeout in seconds - */ - @ConfigurationDefaultInt(30 * 60) - @ConfigurationDescription("Total export timeout in seconds") - public static final ConfigurationItem exportTimeout = null; - /** - * Decompilation timeout in seconds for a single file - */ - @ConfigurationDefaultInt(5 * 60) - @ConfigurationDescription("Decompilation timeout in seconds for a single file") - public static final ConfigurationItem decompilationTimeoutFile = null; - /** - * Using parameter names in decompiling may cause problems because official - * programs like Flash CS 5.5 inserts wrong parameter names indices - */ - @ConfigurationDefaultBoolean(false) - @ConfigurationDescription("Using parameter names in decompiling may cause problems because official programs like Flash CS 5.5 inserts wrong parameter names indices") - public static final ConfigurationItem paramNamesEnable = null; + /** + * Debug mode = throwing an error when comparing original file and recompiled + */ + @ConfigurationDefaultBoolean(false) + @ConfigurationDescription("Debug mode = throwing an error when comparing original file and recompiled") + public static final ConfigurationItem debugMode = null; + /** + * Turn off reading unsafe tags (tags which can cause problems with + * recompiling) + */ + @ConfigurationDefaultBoolean(false) + @ConfigurationDescription("Turn off reading unsafe tags (tags which can cause problems with recompiling)") + public static final ConfigurationItem disableDangerous = null; + /** + * Turn off resolving constants in ActionScript 2 + */ + @ConfigurationDefaultBoolean(true) + @ConfigurationDescription("Turn off resolving constants in ActionScript 2") + public static final ConfigurationItem resolveConstants = null; + /** + * Limit of code subs (for obfuscated code) + */ + @ConfigurationDefaultInt(500) + @ConfigurationDescription("Limit of code subs (for obfuscated code)") + public static final ConfigurationItem sublimiter = null; + /** + * Total export timeout in seconds + */ + @ConfigurationDefaultInt(30 * 60) + @ConfigurationDescription("Total export timeout in seconds") + public static final ConfigurationItem exportTimeout = null; + /** + * Decompilation timeout in seconds for a single file + */ + @ConfigurationDefaultInt(5 * 60) + @ConfigurationDescription("Decompilation timeout in seconds for a single file") + public static final ConfigurationItem decompilationTimeoutFile = null; + /** + * Using parameter names in decompiling may cause problems because official + * programs like Flash CS 5.5 inserts wrong parameter names indices + */ + @ConfigurationDefaultBoolean(false) + @ConfigurationDescription("Using parameter names in decompiling may cause problems because official programs like Flash CS 5.5 inserts wrong parameter names indices") + public static final ConfigurationItem paramNamesEnable = null; - @ConfigurationDefaultBoolean(true) - public static final ConfigurationItem displayFileName = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem debugCopy = null; - @ConfigurationDefaultBoolean(false) - public static final ConfigurationItem dumpTags = null; + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem displayFileName = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem debugCopy = null; + @ConfigurationDefaultBoolean(false) + public static final ConfigurationItem dumpTags = null; - @ConfigurationDefaultInt(60) - public static final ConfigurationItem decompilationTimeoutSingleMethod = null; - @ConfigurationDefaultInt(1) - public static final ConfigurationItem lastRenameType = null; + @ConfigurationDefaultInt(60) + public static final ConfigurationItem decompilationTimeoutSingleMethod = null; + @ConfigurationDefaultInt(1) + public static final ConfigurationItem lastRenameType = null; - @ConfigurationDefaultString(".") - public static final ConfigurationItem lastSaveDir = null; - @ConfigurationDefaultString(".") - public static final ConfigurationItem lastOpenDir = null; - @ConfigurationDefaultString(".") - public static final ConfigurationItem lastExportDir = null; - @ConfigurationDefaultString("en") - public static final ConfigurationItem locale = null; - @ConfigurationDefaultString("_loc%d_") - public static final ConfigurationItem registerNameFormat = null; - @ConfigurationDefaultInt(8) - public static final ConfigurationItem maxRecentFileCount = null; - public static final ConfigurationItem recentFiles = null; - public static final ConfigurationItem fontPairing = null; + @ConfigurationDefaultString(".") + public static final ConfigurationItem lastSaveDir = null; + @ConfigurationDefaultString(".") + public static final ConfigurationItem lastOpenDir = null; + @ConfigurationDefaultString(".") + public static final ConfigurationItem lastExportDir = null; + @ConfigurationDefaultString("en") + public static final ConfigurationItem locale = null; + @ConfigurationDefaultString("_loc%d_") + public static final ConfigurationItem registerNameFormat = null; + @ConfigurationDefaultInt(8) + public static final ConfigurationItem maxRecentFileCount = null; + public static final ConfigurationItem recentFiles = null; + public static final ConfigurationItem fontPairing = null; - public static final ConfigurationItem lastUpdatesCheckDate = null; + public static final ConfigurationItem lastUpdatesCheckDate = null; - @ConfigurationDefaultInt(1000) - @ConfigurationName("gui.window.width") - public static final ConfigurationItem guiWindowWidth = null; - @ConfigurationDefaultInt(700) - @ConfigurationName("gui.window.height") - public static final ConfigurationItem guiWindowHeight = null; - @ConfigurationDefaultBoolean(false) - @ConfigurationName("gui.window.maximized.horizontal") - public static final ConfigurationItem guiWindowMaximizedHorizontal = null; - @ConfigurationDefaultBoolean(false) - @ConfigurationName("gui.window.maximized.vertical") - public static final ConfigurationItem guiWindowMaximizedVertical = null; - @ConfigurationName("gui.avm2.splitPane.dividerLocation") - public static final ConfigurationItem guiAvm2SplitPaneDividerLocation = null; - @ConfigurationName("guiActionSplitPaneDividerLocation") - public static final ConfigurationItem guiActionSplitPaneDividerLocation = null; - @ConfigurationName("guiPreviewSplitPaneDividerLocation") - public static final ConfigurationItem guiPreviewSplitPaneDividerLocation = null; - @ConfigurationName("gui.splitPane1.dividerLocation") - public static final ConfigurationItem guiSplitPane1DividerLocation = null; - @ConfigurationName("gui.splitPane2.dividerLocation") - public static final ConfigurationItem guiSplitPane2DividerLocation = null; - @ConfigurationDefaultInt(3) - public static final ConfigurationItem saveAsExeScaleMode = null; - @ConfigurationDefaultInt(1024 * 100/*100KB*/) - public static final ConfigurationItem syntaxHighlightLimit = null; - public static final ConfigurationItem guiFontPreviewSampleText = null; - @ConfigurationName("gui.fontPreviewWindow.width") - public static final ConfigurationItem guiFontPreviewWidth = null; - @ConfigurationName("gui.fontPreviewWindow.height") - public static final ConfigurationItem guiFontPreviewHeight = null; - @ConfigurationName("gui.fontPreviewWindow.posX") - public static final ConfigurationItem guiFontPreviewPosX = null; - @ConfigurationName("gui.fontPreviewWindow.posY") - public static final ConfigurationItem guiFontPreviewPosY = null; + @ConfigurationDefaultInt(1000) + @ConfigurationName("gui.window.width") + public static final ConfigurationItem guiWindowWidth = null; + @ConfigurationDefaultInt(700) + @ConfigurationName("gui.window.height") + public static final ConfigurationItem guiWindowHeight = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationName("gui.window.maximized.horizontal") + public static final ConfigurationItem guiWindowMaximizedHorizontal = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationName("gui.window.maximized.vertical") + public static final ConfigurationItem guiWindowMaximizedVertical = null; + @ConfigurationName("gui.avm2.splitPane.dividerLocation") + public static final ConfigurationItem guiAvm2SplitPaneDividerLocation = null; + @ConfigurationName("guiActionSplitPaneDividerLocation") + public static final ConfigurationItem guiActionSplitPaneDividerLocation = null; + @ConfigurationName("guiPreviewSplitPaneDividerLocation") + public static final ConfigurationItem guiPreviewSplitPaneDividerLocation = null; + @ConfigurationName("gui.splitPane1.dividerLocation") + public static final ConfigurationItem guiSplitPane1DividerLocation = null; + @ConfigurationName("gui.splitPane2.dividerLocation") + public static final ConfigurationItem guiSplitPane2DividerLocation = null; + @ConfigurationDefaultInt(3) + public static final ConfigurationItem saveAsExeScaleMode = null; + @ConfigurationDefaultInt(1024 * 100/*100KB*/) + public static final ConfigurationItem syntaxHighlightLimit = null; + public static final ConfigurationItem guiFontPreviewSampleText = null; + @ConfigurationName("gui.fontPreviewWindow.width") + public static final ConfigurationItem guiFontPreviewWidth = null; + @ConfigurationName("gui.fontPreviewWindow.height") + public static final ConfigurationItem guiFontPreviewHeight = null; + @ConfigurationName("gui.fontPreviewWindow.posX") + public static final ConfigurationItem guiFontPreviewPosX = null; + @ConfigurationName("gui.fontPreviewWindow.posY") + public static final ConfigurationItem guiFontPreviewPosY = null; - private enum OSId { + @ConfigurationDefaultInt(3) + @ConfigurationName("formatting.indent.size") + @ConfigurationDescription("Number or spaces(or tabs) for one indentation") + public static final ConfigurationItem indentSize = null; - WINDOWS, OSX, UNIX - } + @ConfigurationDefaultBoolean(false) + @ConfigurationName("formatting.indent.useTabs") + @ConfigurationDescription("Use tabs instead of spaces for indentation") + public static final ConfigurationItem indentUseTabs = null; - private static OSId getOSId() { - PrivilegedAction doGetOSName = new PrivilegedAction() { - @Override - public String run() { - return System.getProperty("os.name"); + @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem beginBlockOnNewLine = null; + + private enum OSId { + + WINDOWS, OSX, UNIX + } + + private static OSId getOSId() { + PrivilegedAction doGetOSName = new PrivilegedAction() { + @Override + public String run() { + return System.getProperty("os.name"); + } + }; + OSId id = OSId.UNIX; + String osName = AccessController.doPrivileged(doGetOSName); + if (osName != null) { + if (osName.toLowerCase().startsWith("mac os x")) { + id = OSId.OSX; + } else if (osName.contains("Windows")) { + id = OSId.WINDOWS; + } + } + return id; + } + + public static String getFFDecHome() throws IOException { + if (directory == unspecifiedFile) { + directory = null; + String userHome = null; + try { + userHome = System.getProperty("user.home"); + } catch (SecurityException ignore) { + } + if (userHome != null) { + String applicationId = ApplicationInfo.SHORT_APPLICATION_NAME; + OSId osId = getOSId(); + if (osId == OSId.WINDOWS) { + File appDataDir = null; + try { + String appDataEV = System.getenv("APPDATA"); + if ((appDataEV != null) && (appDataEV.length() > 0)) { + appDataDir = new File(appDataEV); + } + } catch (SecurityException ignore) { + } + String vendorId = ApplicationInfo.VENDOR; + if ((appDataDir != null) && appDataDir.isDirectory()) { + // ${APPDATA}\{vendorId}\${applicationId} + String path = vendorId + "\\" + applicationId + "\\"; + directory = new File(appDataDir, path); + } else { + // ${userHome}\Application Data\${vendorId}\${applicationId} + String path = "Application Data\\" + vendorId + "\\" + applicationId + "\\"; + directory = new File(userHome, path); + } + } else if (osId == OSId.OSX) { + // ${userHome}/Library/Application Support/${applicationId} + String path = "Library/Application Support/" + applicationId + "/"; + directory = new File(userHome, path); + } else { + // ${userHome}/.${applicationId}/ + String path = "." + applicationId + "/"; + directory = new File(userHome, path); } - }; - OSId id = OSId.UNIX; - String osName = AccessController.doPrivileged(doGetOSName); - if (osName != null) { - if (osName.toLowerCase().startsWith("mac os x")) { - id = OSId.OSX; - } else if (osName.contains("Windows")) { - id = OSId.WINDOWS; + } + } + if (!directory.exists()) { + if (!directory.mkdirs()) { + if (!directory.exists()) { + throw new IOException("cannot create directory " + directory); } - } - return id; - } + } + } + String ret = directory.getAbsolutePath(); + if (!ret.endsWith(File.separator)) { + ret += File.separator; + } + return ret; + } - public static String getFFDecHome() throws IOException { - if (directory == unspecifiedFile) { - directory = null; - String userHome = null; - try { - userHome = System.getProperty("user.home"); - } catch (SecurityException ignore) { + public static List getRecentFiles() { + String files = recentFiles.get(); + if (files == null || files.isEmpty()) { + return new ArrayList<>(); + } + return Arrays.asList(files.split("::")); + } + + public static void addRecentFile(String path) { + List recentFilesArray = new ArrayList<>(getRecentFiles()); + int idx = recentFilesArray.indexOf(path); + if (idx != -1) { + recentFilesArray.remove(idx); + } + recentFilesArray.add(path); + while (recentFilesArray.size() >= maxRecentFileCount.get()) { + recentFilesArray.remove(0); + } + recentFiles.set(Helper.joinStrings(recentFilesArray, "::")); + } + + public static void removeRecentFile(String path) { + List recentFilesArray = new ArrayList<>(getRecentFiles()); + int idx = recentFilesArray.indexOf(path); + if (idx != -1) { + recentFilesArray.remove(idx); + } + recentFiles.set(Helper.joinStrings(recentFilesArray, "::")); + } + + public static Map getFontPairs() { + String fonts = fontPairing.get(); + if (fonts == null) { + return new HashMap<>(); + } + + Map result = new HashMap<>(); + for (String pair : fonts.split("::")) { + String[] splittedPair = pair.split("="); + result.put(splittedPair[0], splittedPair[1]); + } + return result; + } + + public static void addFontPair(String fileName, int fontId, String fontName, String systemFontName) { + String key = fileName + "_" + fontId + "_" + fontName; + Map fontPairs = getFontPairs(); + fontPairs.put(key, systemFontName); + fontPairs.put(fontName, systemFontName); + StringBuilder sb = new StringBuilder(); + int i = 0; + for (Entry pair : fontPairs.entrySet()) { + if (i != 0) { + sb.append("::"); + } + sb.append(pair.getKey()).append("=").append(pair.getValue()); + i++; + } + fontPairing.set(sb.toString()); + } + + /** + * Saves replacements to file for future use + */ + private static void saveReplacements(String replacementsFile) { + if (replacements.isEmpty()) { + File rf = new File(replacementsFile); + if (rf.exists()) { + if (!rf.delete()) { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Cannot delete replacements file"); } - if (userHome != null) { - String applicationId = ApplicationInfo.SHORT_APPLICATION_NAME; - OSId osId = getOSId(); - if (osId == OSId.WINDOWS) { - File appDataDir = null; - try { - String appDataEV = System.getenv("APPDATA"); - if ((appDataEV != null) && (appDataEV.length() > 0)) { - appDataDir = new File(appDataEV); - } - } catch (SecurityException ignore) { - } - String vendorId = ApplicationInfo.VENDOR; - if ((appDataDir != null) && appDataDir.isDirectory()) { - // ${APPDATA}\{vendorId}\${applicationId} - String path = vendorId + "\\" + applicationId + "\\"; - directory = new File(appDataDir, path); - } else { - // ${userHome}\Application Data\${vendorId}\${applicationId} - String path = "Application Data\\" + vendorId + "\\" + applicationId + "\\"; - directory = new File(userHome, path); - } - } else if (osId == OSId.OSX) { - // ${userHome}/Library/Application Support/${applicationId} - String path = "Library/Application Support/" + applicationId + "/"; - directory = new File(userHome, path); - } else { - // ${userHome}/.${applicationId}/ - String path = "." + applicationId + "/"; - directory = new File(userHome, path); - } + } + } else { + try (PrintWriter pw = new PrintWriter(new Utf8OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(replacementsFile))))) { + for (Replacement r : replacements) { + pw.println(r.urlPattern); + pw.println(r.targetFile); } - } - if (!directory.exists()) { - if (!directory.mkdirs()) { - if (!directory.exists()) { - throw new IOException("cannot create directory " + directory); - } + } catch (IOException ex) { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Exception during saving replacements", ex); + } + } + } + + /** + * Load replacements from file + */ + private static void loadReplacements(String replacementsFile) { + if (!(new File(replacementsFile)).exists()) { + return; + } + replacements = new ArrayList<>(); + try (BufferedReader br = new BufferedReader(new Utf8InputStreamReader(new FileInputStream(replacementsFile)))) { + String s; + while ((s = br.readLine()) != null) { + Replacement r = new Replacement(s, br.readLine()); + replacements.add(r); + } + } catch (IOException e) { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Error during load replacements", e); + } + } + + private static String getReplacementsFile() throws IOException { + return getFFDecHome() + REPLACEMENTS_NAME; + } + + private static String getConfigFile() throws IOException { + return getFFDecHome() + CONFIG_NAME; + } + + private static HashMap loadFromFile(String file, String replacementsFile) { + HashMap config = new HashMap<>(); + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { + + @SuppressWarnings("unchecked") + HashMap cfg = (HashMap) ois.readObject(); + config = cfg; + } catch (FileNotFoundException ex) { + } catch (ClassNotFoundException cnf) { + } catch (IOException ex) { + } + if (replacementsFile != null) { + loadReplacements(replacementsFile); + } + if (config.containsKey("paralelSpeedUp")) { + config.put("parallelSpeedUp", config.get("paralelSpeedUp")); + config.remove("paralelSpeedUp"); + } + return config; + } + + private static void saveToFile(String file, String replacementsFile) { + HashMap config = new HashMap<>(); + for (Entry entry : getConfigurationFields().entrySet()) { + try { + String name = entry.getKey(); + Field field = entry.getValue(); + ConfigurationItem item = (ConfigurationItem) field.get(null); + if (item.hasValue) { + config.put(name, item.get()); } - } - String ret = directory.getAbsolutePath(); - if (!ret.endsWith(File.separator)) { - ret += File.separator; - } - return ret; - } - - public static List getRecentFiles() { - String files = recentFiles.get(); - if (files == null || files.isEmpty()) { - return new ArrayList<>(); - } - return Arrays.asList(files.split("::")); - } - - public static void addRecentFile(String path) { - List recentFilesArray = new ArrayList<>(getRecentFiles()); - int idx = recentFilesArray.indexOf(path); - if (idx != -1) { - recentFilesArray.remove(idx); - } - recentFilesArray.add(path); - while (recentFilesArray.size() >= maxRecentFileCount.get()) { - recentFilesArray.remove(0); - } - recentFiles.set(Helper.joinStrings(recentFilesArray, "::")); - } - - public static void removeRecentFile(String path) { - List recentFilesArray = new ArrayList<>(getRecentFiles()); - int idx = recentFilesArray.indexOf(path); - if (idx != -1) { - recentFilesArray.remove(idx); - } - recentFiles.set(Helper.joinStrings(recentFilesArray, "::")); - } - - public static Map getFontPairs() { - String fonts = fontPairing.get(); - if (fonts == null) { - return new HashMap<>(); - } - - Map result = new HashMap<>(); - for (String pair : fonts.split("::")) { - String[] splittedPair = pair.split("="); - result.put(splittedPair[0], splittedPair[1]); - } - return result; - } - - public static void addFontPair(String fileName, int fontId, String fontName, String systemFontName) { - String key = fileName + "_" + fontId + "_" + fontName; - Map fontPairs = getFontPairs(); - fontPairs.put(key, systemFontName); - fontPairs.put(fontName, systemFontName); - StringBuilder sb = new StringBuilder(); - int i = 0; - for (Entry pair : fontPairs.entrySet()) { - if (i != 0) { - sb.append("::"); - } - sb.append(pair.getKey()).append("=").append(pair.getValue()); - i++; - } - fontPairing.set(sb.toString()); - } - - /** - * Saves replacements to file for future use - */ - private static void saveReplacements(String replacementsFile) { - if (replacements.isEmpty()) { - File rf = new File(replacementsFile); - if (rf.exists()) { - if (!rf.delete()) { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Cannot delete replacements file"); - } - } - } else { - try (PrintWriter pw = new PrintWriter(new Utf8OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(replacementsFile))))) { - for (Replacement r : replacements) { - pw.println(r.urlPattern); - pw.println(r.targetFile); - } - } catch (IOException ex) { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Exception during saving replacements", ex); - } - } - } - - /** - * Load replacements from file - */ - private static void loadReplacements(String replacementsFile) { - if (!(new File(replacementsFile)).exists()) { - return; - } - replacements = new ArrayList<>(); - try (BufferedReader br = new BufferedReader(new Utf8InputStreamReader(new FileInputStream(replacementsFile)))) { - String s; - while ((s = br.readLine()) != null) { - Replacement r = new Replacement(s, br.readLine()); - replacements.add(r); - } - } catch (IOException e) { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Error during load replacements", e); - } - } - - private static String getReplacementsFile() throws IOException { - return getFFDecHome() + REPLACEMENTS_NAME; - } - - private static String getConfigFile() throws IOException { - return getFFDecHome() + CONFIG_NAME; - } - - private static HashMap loadFromFile(String file, String replacementsFile) { - HashMap config = new HashMap<>(); - try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { - - @SuppressWarnings("unchecked") - HashMap cfg = (HashMap) ois.readObject(); - config = cfg; - } catch (FileNotFoundException ex) { - } catch (ClassNotFoundException cnf) { - } catch (IOException ex) { - } - if (replacementsFile != null) { - loadReplacements(replacementsFile); - } - if (config.containsKey("paralelSpeedUp")) { - config.put("parallelSpeedUp", config.get("paralelSpeedUp")); - config.remove("paralelSpeedUp"); - } - return config; - } - - private static void saveToFile(String file, String replacementsFile) { - HashMap config = new HashMap<>(); - for (Entry entry : getConfigurationFields().entrySet()) { - try { - String name = entry.getKey(); - Field field = entry.getValue(); - ConfigurationItem item = (ConfigurationItem) field.get(null); - if (item.hasValue) { - config.put(name, item.get()); - } - } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } - try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { - oos.writeObject(config); - } catch (IOException ex) { - JOptionPane.showMessageDialog(null, "Cannot save configuration.", "Error", JOptionPane.ERROR_MESSAGE); - Logger.getLogger(Configuration.class.getName()).severe("Configuration directory is read only."); - } - if (replacementsFile != null) { - saveReplacements(replacementsFile); - } - } - - public static List getReplacements() { - return replacements; - } - - public static void saveConfig() { - try { - saveToFile(getConfigFile(), getReplacementsFile()); - } catch (IOException ex) { + } catch (IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } + } + } + try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { + oos.writeObject(config); + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, "Cannot save configuration.", "Error", JOptionPane.ERROR_MESSAGE); + Logger.getLogger(Configuration.class.getName()).severe("Configuration directory is read only."); + } + if (replacementsFile != null) { + saveReplacements(replacementsFile); + } + } - static { - setConfigurationFields(); - if (useDetailedLogging.get() || debugMode.get()) { - logLevel = Level.CONFIG; - } else { - logLevel = Level.WARNING; - } - } + public static List getReplacements() { + return replacements; + } - @SuppressWarnings("unchecked") - public static void setConfigurationFields() { - try { - HashMap config = loadFromFile(getConfigFile(), getReplacementsFile()); - for (Entry entry : getConfigurationFields().entrySet()) { - String name = entry.getKey(); - Field field = entry.getValue(); - // remove final modifier from field - Field modifiersField = field.getClass().getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + public static void saveConfig() { + try { + saveToFile(getConfigFile(), getReplacementsFile()); + } catch (IOException ex) { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); + } + } - Object defaultValue = getDefaultValue(field); - Object value = null; - if (config.containsKey(name)) { - value = config.get(name); - } + static { + setConfigurationFields(); + if (useDetailedLogging.get() || debugMode.get()) { + logLevel = Level.CONFIG; + } else { + logLevel = Level.WARNING; + } + } - if (value != null) { - field.set(null, new ConfigurationItem(name, defaultValue, value)); - } else { - field.set(null, new ConfigurationItem(name, defaultValue)); - } + @SuppressWarnings("unchecked") + public static void setConfigurationFields() { + try { + HashMap config = loadFromFile(getConfigFile(), getReplacementsFile()); + for (Entry entry : getConfigurationFields().entrySet()) { + String name = entry.getKey(); + Field field = entry.getValue(); + // remove final modifier from field + Field modifiersField = field.getClass().getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + + Object defaultValue = getDefaultValue(field); + Object value = null; + if (config.containsKey(name)) { + value = config.get(name); } - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ex) { - // Reflection exceptions. This should never happen - throw new Error(ex.getMessage()); - } catch (IOException ex) { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } - public static Object getDefaultValue(Field field) { - Object defaultValue = null; - ConfigurationDefaultBoolean aBool = field.getAnnotation(ConfigurationDefaultBoolean.class); - if (aBool != null) { - defaultValue = aBool.value(); - } - ConfigurationDefaultInt aInt = field.getAnnotation(ConfigurationDefaultInt.class); - if (aInt != null) { - defaultValue = aInt.value(); - } - ConfigurationDefaultString aString = field.getAnnotation(ConfigurationDefaultString.class); - if (aString != null) { - defaultValue = aString.value(); - } - return defaultValue; - } - - public static String getDescription(Field field) { - ConfigurationDescription a = field.getAnnotation(ConfigurationDescription.class); - if (a != null) { - return a.value(); - } - return null; - } - - public static Map getConfigurationFields() { - Field[] fields = Configuration.class.getFields(); - Map result = new HashMap<>(); - for (Field field : fields) { - if (ConfigurationItem.class.isAssignableFrom(field.getType())) { - ConfigurationName annotation = field.getAnnotation(ConfigurationName.class); - String name = annotation == null ? field.getName() : annotation.value(); - result.put(name, field); + if (value != null) { + field.set(null, new ConfigurationItem(name, defaultValue, value)); + } else { + field.set(null, new ConfigurationItem(name, defaultValue)); } - } - return result; - } + } + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ex) { + // Reflection exceptions. This should never happen + throw new Error(ex.getMessage()); + } catch (IOException ex) { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static Object getDefaultValue(Field field) { + Object defaultValue = null; + ConfigurationDefaultBoolean aBool = field.getAnnotation(ConfigurationDefaultBoolean.class); + if (aBool != null) { + defaultValue = aBool.value(); + } + ConfigurationDefaultInt aInt = field.getAnnotation(ConfigurationDefaultInt.class); + if (aInt != null) { + defaultValue = aInt.value(); + } + ConfigurationDefaultString aString = field.getAnnotation(ConfigurationDefaultString.class); + if (aString != null) { + defaultValue = aString.value(); + } + return defaultValue; + } + + public static String getDescription(Field field) { + ConfigurationDescription a = field.getAnnotation(ConfigurationDescription.class); + if (a != null) { + return a.value(); + } + return null; + } + + public static Map getConfigurationFields() { + Field[] fields = Configuration.class.getFields(); + Map result = new HashMap<>(); + for (Field field : fields) { + if (ConfigurationItem.class.isAssignableFrom(field.getType())) { + ConfigurationName annotation = field.getAnnotation(ConfigurationName.class); + String name = annotation == null ? field.getName() : annotation.value(); + result.put(name, field); + } + } + return result; + } + + public static CodeFormatting getCodeFormatting() { + CodeFormatting ret = new CodeFormatting(); + String indentString = ""; + for (int i = 0; i < indentSize.get(); i++) { + indentString += indentUseTabs.get() ? "\t" : " "; + } + ret.indentString = indentString; + ret.beginBlockOnNewLine = beginBlockOnNewLine.get(); + return ret; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 0b426b8cf..daea6dc9a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.MissingSymbolHandler; import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.GraphFrame; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.helpers.HilightedText; @@ -66,7 +67,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } private HilightedText getHilightedText(ExportMode exportMode) { - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); abc.bodies[bodyIndex].code.toASMSource(abc.constants, trait, abc.method_info[abc.bodies[bodyIndex].method_info], abc.bodies[bodyIndex], exportMode, writer); return new HilightedText(writer); } @@ -92,7 +93,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } else { setContentType("text/plain"); if (textHexOnly == null) { - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); Helper.byteArrayToHexWithHeader(writer, abc.bodies[bodyIndex].code.getBytes()); textHexOnly = new HilightedText(writer); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 34ea9582d..b9ec38f04 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -446,7 +446,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } if (!cache.contains(scriptLeaf)) { boolean parallel = Configuration.parallelSpeedUp.get(); - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); scriptLeaf.toSource(writer, abcList, script.traits.traits, ExportMode.SOURCE, parallel); hilightedCode = new HilightedText(writer); cache.put(scriptLeaf, new CachedDecompilation(hilightedCode)); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java index 6fecb4ba2..1657b4461 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.ASM3Parser; import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; @@ -92,7 +93,7 @@ public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail { public void load(TraitSlotConst trait, ABC abc, boolean isStatic) { this.abc = abc; this.trait = trait; - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); writer.appendNoHilight("trait "); writer.hilightSpecial(abc.constants.multinameToString(trait.name_index), "traitname"); writer.appendNoHilight(" "); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java index 08da71451..8c262f7b1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; @@ -89,12 +90,12 @@ public class TraitsListItem { try { if ((type != Type.INITIALIZER) && isStatic) { abc.class_info[classIndex].static_traits.traits[index].convertHeader(null, "", abcTags, abc, true, ExportMode.SOURCE, scriptIndex, classIndex, new NulWriter(), new ArrayList(), false); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); abc.class_info[classIndex].static_traits.traits[index].toStringHeader(null, "", abcTags, abc, true, ExportMode.SOURCE, scriptIndex, classIndex, writer, new ArrayList(), false); s = writer.toString(); } else if ((type != Type.INITIALIZER) && (!isStatic)) { abc.instance_info[classIndex].instance_traits.traits[index].convertHeader(null, "", abcTags, abc, false, ExportMode.SOURCE, scriptIndex, classIndex, new NulWriter(), new ArrayList(), false); - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); abc.instance_info[classIndex].instance_traits.traits[index].toStringHeader(null, "", abcTags, abc, false, ExportMode.SOURCE, scriptIndex, classIndex, writer, new ArrayList(), false); s = writer.toString(); } else if (!isStatic) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 3e013acc7..f5367d024 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -189,7 +189,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene if (actions == null) { actions = src.getActions(SWF.DEFAULT_VERSION); } - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); Action.actionsToSource(src, actions, SWF.DEFAULT_VERSION, src.toString()/*FIXME?*/, writer); List hilights = writer.instructionHilights; String srcNoHex = writer.toString(); @@ -309,7 +309,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene ASMSource asm = (ASMSource) src; DisassemblyListener listener = getDisassemblyListener(); asm.addDisassemblyListener(listener); - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); try { asm.getASMSource(SWF.DEFAULT_VERSION, exportMode, writer, lastCode); } catch (InterruptedException ex) { @@ -334,7 +334,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene } } else { if (srcHexOnly == null) { - HilightedTextWriter writer = new HilightedTextWriter(true); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),true); Helper.byteArrayToHexWithHeader(writer, src.getActionBytes()); srcHexOnly = new HilightedText(writer); } diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/CodeFormatting.java b/trunk/src/com/jpexs/decompiler/flash/helpers/CodeFormatting.java new file mode 100644 index 000000000..7629821d5 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/CodeFormatting.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2014 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 . + */ + +package com.jpexs.decompiler.flash.helpers; + +/** + * + * @author JPEXS + */ +public class CodeFormatting { + public String newLineChars = "\r\n"; + public String indentString = " "; + public boolean beginBlockOnNewLine = true; +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java b/trunk/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java index 86058e434..1d031a63c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java @@ -36,7 +36,8 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable { private int indent; private int writtenBytes; - public FileTextWriter(FileOutputStream fos) { + public FileTextWriter(CodeFormatting formatting,FileOutputStream fos) { + super(formatting); this.writer = new BufferedWriter(new Utf8OutputStreamWriter(fos)); } @@ -90,7 +91,7 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable { @Override public FileTextWriter newLine() { - writeToFile(NEW_LINE); + writeToFile(formatting.newLineChars); newLine = true; return this; } @@ -120,7 +121,7 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable { private void appendIndent() { for (int i = 0; i < indent; i++) { - writeToFile(INDENT_STRING); + writeToFile(formatting.indentString); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java b/trunk/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java index 6006d164e..154432c78 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java @@ -25,13 +25,17 @@ import com.jpexs.decompiler.graph.GraphSourceItem; */ public class GraphTextWriter { - public static final String INDENT_STRING = " "; - public static final String NEW_LINE = "\r\n"; protected long startTime; protected long suspendTime; + protected CodeFormatting formatting; - public GraphTextWriter() { - startTime = System.currentTimeMillis(); + public CodeFormatting getFormatting() { + return formatting; + } + + public GraphTextWriter(CodeFormatting formatting) { + startTime = System.currentTimeMillis(); + this.formatting = formatting; } public boolean getIsHighlighted() { @@ -160,4 +164,25 @@ public class GraphTextWriter { public String toString() { return ""; } + + public GraphTextWriter startBlock(String opening) { + if(formatting.beginBlockOnNewLine){ + newLine(); + }else{ + append(" "); + } + return append(opening).newLine().indent(); + } + + public GraphTextWriter startBlock() { + return startBlock("{"); + } + + public GraphTextWriter endBlock(String closing) { + return unindent().append(closing); + } + + public GraphTextWriter endBlock() { + return endBlock("}"); + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/HilightedTextWriter.java b/trunk/src/com/jpexs/decompiler/flash/helpers/HilightedTextWriter.java index e6e958b84..070c90034 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/HilightedTextWriter.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/HilightedTextWriter.java @@ -48,11 +48,13 @@ public class HilightedTextWriter extends GraphTextWriter { public List instructionHilights = new ArrayList<>(); public List specialHilights = new ArrayList<>(); - public HilightedTextWriter(boolean hilight) { + public HilightedTextWriter(CodeFormatting formatting,boolean hilight) { + super(formatting); this.hilight = hilight; } - public HilightedTextWriter(boolean hilight, int indent) { + public HilightedTextWriter(CodeFormatting formatting,boolean hilight, int indent) { + super(formatting); this.hilight = hilight; this.indent = indent; } @@ -214,7 +216,7 @@ public class HilightedTextWriter extends GraphTextWriter { @Override public HilightedTextWriter newLine() { - appendToSb(NEW_LINE); + appendToSb(formatting.newLineChars); newLine = true; newLineCount++; return this; @@ -305,7 +307,7 @@ public class HilightedTextWriter extends GraphTextWriter { private void appendIndent() { for (int i = 0; i < indent; i++) { - appendNoHilight(INDENT_STRING); + appendNoHilight(formatting.indentString); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/NulWriter.java b/trunk/src/com/jpexs/decompiler/flash/helpers/NulWriter.java index 3b6e04849..f78a1b528 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/NulWriter.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/NulWriter.java @@ -30,6 +30,7 @@ public class NulWriter extends GraphTextWriter { private boolean stringAdded = false; public NulWriter() { + super(new CodeFormatting()); } public void startLoop(long loopId, int loopType) { diff --git a/trunk/src/com/jpexs/decompiler/flash/treenodes/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/treenodes/TagNode.java index b6eed660e..43e523b16 100644 --- a/trunk/src/com/jpexs/decompiler/flash/treenodes/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/treenodes/TagNode.java @@ -138,7 +138,7 @@ public class TagNode extends ContainerNode { File file = new File(f); ASMSource asm = ((ASMSource) node.item); - try (FileTextWriter writer = new FileTextWriter(new FileOutputStream(f))) { + try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(),new FileOutputStream(f))) { if (exportMode == ExportMode.HEX) { asm.getActionSourcePrefix(writer); asm.getActionBytesAsHex(writer); diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index cd3ca0f6f..4f9bdc094 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.RunnableIOEx; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.CSMTextSettingsTag; import com.jpexs.decompiler.flash.tags.DefineButton2Tag; @@ -1156,7 +1157,7 @@ public class XFLConverter { } private static String convertActionScript(ASMSource as) { - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); try { Action.actionsToSource(as, as.getActions(SWF.DEFAULT_VERSION), SWF.DEFAULT_VERSION, as.toString(), writer); } catch (InterruptedException ex) { diff --git a/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 979cc4b8d..852227471 100644 --- a/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.graph.model.BinaryOp; @@ -116,7 +117,7 @@ public abstract class GraphTargetItem implements Serializable { public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException; public String toString(LocalData localData) throws InterruptedException { - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); toString(writer, localData); return writer.toString(); } diff --git a/trunk/src/com/jpexs/decompiler/graph/model/BlockItem.java b/trunk/src/com/jpexs/decompiler/graph/model/BlockItem.java index 9a3c625c0..f3485fcd9 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/BlockItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/BlockItem.java @@ -39,12 +39,9 @@ public class BlockItem extends GraphTargetItem { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.append("{").newLine(); - writer.indent(); + writer.startBlock(); Graph.graphToString(commands, writer, localData); - writer.newLine(); - writer.unindent(); - return writer.append("}"); + return writer.endBlock(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/graph/model/DoWhileItem.java b/trunk/src/com/jpexs/decompiler/graph/model/DoWhileItem.java index 1f8e28d50..a72b52397 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/DoWhileItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/DoWhileItem.java @@ -62,16 +62,15 @@ public class DoWhileItem extends LoopItem implements Block { if (labelUsed) { writer.append("loop" + loop.id + ":").newLine(); } - writer.append("do").newLine(); - writer.append("{").newLine(); + writer.append("do"); + writer.startBlock(); writer.indent(); for (GraphTargetItem ti : commands) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}").newLine(); + writer.endBlock(); writer.append("while("); for (int i = 0; i < expression.size(); i++) { diff --git a/trunk/src/com/jpexs/decompiler/graph/model/ForItem.java b/trunk/src/com/jpexs/decompiler/graph/model/ForItem.java index f4f4456ef..0d1a8c099 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/ForItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/ForItem.java @@ -96,16 +96,13 @@ public class ForItem extends LoopItem implements Block { writer.stripSemicolon(); p++; } - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")").startBlock(); for (GraphTargetItem ti : commands) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}"); + writer.endBlock(); if (writer instanceof NulWriter) { LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id); labelUsed = loopOjb.used; diff --git a/trunk/src/com/jpexs/decompiler/graph/model/IfItem.java b/trunk/src/com/jpexs/decompiler/graph/model/IfItem.java index 67b895846..fa741e650 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/IfItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/IfItem.java @@ -82,28 +82,26 @@ public class IfItem extends GraphTargetItem implements Block { } writer.append("if("); expr.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")").startBlock(); for (GraphTargetItem ti : ifBranch) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}"); + writer.endBlock(); if (elseBranch.size() > 0) { - writer.newLine(); - writer.append("else").newLine(); - writer.append("{").newLine(); - writer.indent(); + if(writer.getFormatting().beginBlockOnNewLine){ + writer.newLine(); + }else{ + writer.append(" "); + } + writer.append("else").startBlock(); for (GraphTargetItem ti : elseBranch) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}"); + writer.endBlock(); } return writer; } diff --git a/trunk/src/com/jpexs/decompiler/graph/model/SwitchItem.java b/trunk/src/com/jpexs/decompiler/graph/model/SwitchItem.java index dadd27c36..69bcf8341 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/SwitchItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/SwitchItem.java @@ -71,9 +71,7 @@ public class SwitchItem extends LoopItem implements Block { } writer.append("switch("); switchedObject.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")").startBlock(); for (int i = 0; i < caseCommands.size(); i++) { for (int k = 0; k < valuesMapping.size(); k++) { if (valuesMapping.get(k) == i) { @@ -103,8 +101,7 @@ public class SwitchItem extends LoopItem implements Block { writer.unindent(); } } - writer.unindent(); - writer.append("}").newLine(); + writer.endBlock(); if (writer instanceof NulWriter) { LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id); labelUsed = loopOjb.used; diff --git a/trunk/src/com/jpexs/decompiler/graph/model/UniversalLoopItem.java b/trunk/src/com/jpexs/decompiler/graph/model/UniversalLoopItem.java index e8042ff0a..5471163da 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/UniversalLoopItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/UniversalLoopItem.java @@ -52,16 +52,13 @@ public class UniversalLoopItem extends LoopItem implements Block { if (labelUsed) { writer.append("loop" + loop.id + ":").newLine(); } - writer.append("while(true)").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append("while(true)").startBlock(); for (GraphTargetItem ti : commands) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}").newLine(); + writer.endBlock(); if (writer instanceof NulWriter) { LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id); labelUsed = loopOjb.used; diff --git a/trunk/src/com/jpexs/decompiler/graph/model/WhileItem.java b/trunk/src/com/jpexs/decompiler/graph/model/WhileItem.java index 62d01c7f2..bf276f5f0 100644 --- a/trunk/src/com/jpexs/decompiler/graph/model/WhileItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/model/WhileItem.java @@ -67,16 +67,14 @@ public class WhileItem extends LoopItem implements Block { } expression.get(i).toString(writer, localData); } - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); + writer.append(")"); + writer.startBlock(); for (GraphTargetItem ti : commands) { if (!ti.isEmpty()) { ti.toStringSemicoloned(writer, localData).newLine(); } } - writer.unindent(); - writer.append("}"); + writer.endBlock(); if (writer instanceof NulWriter) { LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id); labelUsed = loopOjb.used; diff --git a/trunk/src/com/jpexs/helpers/Helper.java b/trunk/src/com/jpexs/helpers/Helper.java index 9908f5c07..40a5ddb61 100644 --- a/trunk/src/com/jpexs/helpers/Helper.java +++ b/trunk/src/com/jpexs/helpers/Helper.java @@ -220,7 +220,7 @@ public class Helper { Scanner scanner = new Scanner(text); String indentStr = ""; for (int i = 0; i < level; i++) { - indentStr += HilightedTextWriter.INDENT_STRING; + indentStr += Configuration.getCodeFormatting().indentString; } int indentLength = indentStr.length(); for (int i = 0; i < prefixLineCount; i++) { @@ -229,7 +229,7 @@ public class Helper { while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.startsWith(indentStr)) { - sb.append(line.substring(indentLength)).append(HilightedTextWriter.NEW_LINE); + sb.append(line.substring(indentLength)).append(Configuration.getCodeFormatting().newLineChars); } else { return sb.toString(); } @@ -706,7 +706,7 @@ public class Helper { } public static String byteArrayToHex(byte[] data, int bytesPerRow) { - HilightedTextWriter writer = new HilightedTextWriter(false); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false); byteArrayToHex(writer, data, bytesPerRow, 8, true, true); return writer.toString(); }