mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-12 09:41:56 +00:00
Configurable code formatting (Indentation + brace position)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -2247,7 +2247,7 @@ public class AVM2Code implements Serializable {
|
||||
invalidateCache();
|
||||
try {
|
||||
List<Integer> 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<Integer> 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);
|
||||
|
||||
@@ -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<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, MethodBody body, ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> 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));
|
||||
|
||||
@@ -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<AVM2Item> stack, ABC abc, AVM2Instruction ins, List<AVM2Item> output, MethodBody body, HashMap<Integer, String> localRegNames, List<String> 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;
|
||||
|
||||
@@ -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<String>(), false);
|
||||
|
||||
HilightedTextWriter writer = new HilightedTextWriter(false);
|
||||
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false);
|
||||
writer.appendNoHilight(super.toString(abcTags, abc) + " ");
|
||||
if (parentTraitIndex > -1) {
|
||||
if (isStatic) {
|
||||
|
||||
@@ -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<String>(), false);
|
||||
}
|
||||
|
||||
HilightedTextWriter writer = new HilightedTextWriter(false);
|
||||
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false);
|
||||
writer.appendNoHilight(super.toString(abcTags, abc));
|
||||
writer.appendNoHilight(" ");
|
||||
if (isInitializer) {
|
||||
|
||||
@@ -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<DisassemblyListener>(), address, ret, null, version, ExportMode.PCODE, writer, swfPos, path);
|
||||
s = writer.toString();
|
||||
ret = ASMParser.parse(address, swfPos, true, s, SWF.DEFAULT_VERSION, false);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<Replacement> replacements = new ArrayList<>();
|
||||
/**
|
||||
* List of replacements
|
||||
*/
|
||||
private static List<Replacement> replacements = new ArrayList<>();
|
||||
|
||||
public static final Level logLevel;
|
||||
public static final Level logLevel;
|
||||
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> openMultipleFiles = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> decompile = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> parallelSpeedUp = null;
|
||||
@ConfigurationDefaultInt(20)
|
||||
public static final ConfigurationItem<Integer> parallelThreadCount = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> autoDeobfuscate = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> cacheOnDisk = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> internalFlashViewer = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> gotoMainClassOnStartup = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> autoRenameIdentifiers = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> deobfuscateUsePrevTagOnly = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> offeredAssociation = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> removeNops = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> showHexOnlyButton = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> decimalAddress = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> showAllAddresses = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> useFrameCache = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> useRibbonInterface = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> openFolderAfterFlaExport = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> useDetailedLogging = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> openMultipleFiles = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> decompile = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> parallelSpeedUp = null;
|
||||
@ConfigurationDefaultInt(20)
|
||||
public static final ConfigurationItem<Integer> parallelThreadCount = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> autoDeobfuscate = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> cacheOnDisk = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> internalFlashViewer = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> gotoMainClassOnStartup = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> autoRenameIdentifiers = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> deobfuscateUsePrevTagOnly = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> offeredAssociation = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> removeNops = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> showHexOnlyButton = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> decimalAddress = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> showAllAddresses = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> useFrameCache = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> useRibbonInterface = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> openFolderAfterFlaExport = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> 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<Boolean> 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<Boolean> disableDangerous = null;
|
||||
/**
|
||||
* Turn off resolving constants in ActionScript 2
|
||||
*/
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
@ConfigurationDescription("Turn off resolving constants in ActionScript 2")
|
||||
public static final ConfigurationItem<Boolean> resolveConstants = null;
|
||||
/**
|
||||
* Limit of code subs (for obfuscated code)
|
||||
*/
|
||||
@ConfigurationDefaultInt(500)
|
||||
@ConfigurationDescription("Limit of code subs (for obfuscated code)")
|
||||
public static final ConfigurationItem<Integer> sublimiter = null;
|
||||
/**
|
||||
* Total export timeout in seconds
|
||||
*/
|
||||
@ConfigurationDefaultInt(30 * 60)
|
||||
@ConfigurationDescription("Total export timeout in seconds")
|
||||
public static final ConfigurationItem<Integer> 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<Integer> 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<Boolean> 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<Boolean> 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<Boolean> disableDangerous = null;
|
||||
/**
|
||||
* Turn off resolving constants in ActionScript 2
|
||||
*/
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
@ConfigurationDescription("Turn off resolving constants in ActionScript 2")
|
||||
public static final ConfigurationItem<Boolean> resolveConstants = null;
|
||||
/**
|
||||
* Limit of code subs (for obfuscated code)
|
||||
*/
|
||||
@ConfigurationDefaultInt(500)
|
||||
@ConfigurationDescription("Limit of code subs (for obfuscated code)")
|
||||
public static final ConfigurationItem<Integer> sublimiter = null;
|
||||
/**
|
||||
* Total export timeout in seconds
|
||||
*/
|
||||
@ConfigurationDefaultInt(30 * 60)
|
||||
@ConfigurationDescription("Total export timeout in seconds")
|
||||
public static final ConfigurationItem<Integer> 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<Integer> 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<Boolean> paramNamesEnable = null;
|
||||
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> displayFileName = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> debugCopy = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> dumpTags = null;
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> displayFileName = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> debugCopy = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
public static final ConfigurationItem<Boolean> dumpTags = null;
|
||||
|
||||
@ConfigurationDefaultInt(60)
|
||||
public static final ConfigurationItem<Integer> decompilationTimeoutSingleMethod = null;
|
||||
@ConfigurationDefaultInt(1)
|
||||
public static final ConfigurationItem<Integer> lastRenameType = null;
|
||||
@ConfigurationDefaultInt(60)
|
||||
public static final ConfigurationItem<Integer> decompilationTimeoutSingleMethod = null;
|
||||
@ConfigurationDefaultInt(1)
|
||||
public static final ConfigurationItem<Integer> lastRenameType = null;
|
||||
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastSaveDir = null;
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastOpenDir = null;
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastExportDir = null;
|
||||
@ConfigurationDefaultString("en")
|
||||
public static final ConfigurationItem<String> locale = null;
|
||||
@ConfigurationDefaultString("_loc%d_")
|
||||
public static final ConfigurationItem<String> registerNameFormat = null;
|
||||
@ConfigurationDefaultInt(8)
|
||||
public static final ConfigurationItem<Integer> maxRecentFileCount = null;
|
||||
public static final ConfigurationItem<String> recentFiles = null;
|
||||
public static final ConfigurationItem<String> fontPairing = null;
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastSaveDir = null;
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastOpenDir = null;
|
||||
@ConfigurationDefaultString(".")
|
||||
public static final ConfigurationItem<String> lastExportDir = null;
|
||||
@ConfigurationDefaultString("en")
|
||||
public static final ConfigurationItem<String> locale = null;
|
||||
@ConfigurationDefaultString("_loc%d_")
|
||||
public static final ConfigurationItem<String> registerNameFormat = null;
|
||||
@ConfigurationDefaultInt(8)
|
||||
public static final ConfigurationItem<Integer> maxRecentFileCount = null;
|
||||
public static final ConfigurationItem<String> recentFiles = null;
|
||||
public static final ConfigurationItem<String> fontPairing = null;
|
||||
|
||||
public static final ConfigurationItem<Calendar> lastUpdatesCheckDate = null;
|
||||
public static final ConfigurationItem<Calendar> lastUpdatesCheckDate = null;
|
||||
|
||||
@ConfigurationDefaultInt(1000)
|
||||
@ConfigurationName("gui.window.width")
|
||||
public static final ConfigurationItem<Integer> guiWindowWidth = null;
|
||||
@ConfigurationDefaultInt(700)
|
||||
@ConfigurationName("gui.window.height")
|
||||
public static final ConfigurationItem<Integer> guiWindowHeight = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationName("gui.window.maximized.horizontal")
|
||||
public static final ConfigurationItem<Boolean> guiWindowMaximizedHorizontal = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationName("gui.window.maximized.vertical")
|
||||
public static final ConfigurationItem<Boolean> guiWindowMaximizedVertical = null;
|
||||
@ConfigurationName("gui.avm2.splitPane.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiAvm2SplitPaneDividerLocation = null;
|
||||
@ConfigurationName("guiActionSplitPaneDividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiActionSplitPaneDividerLocation = null;
|
||||
@ConfigurationName("guiPreviewSplitPaneDividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiPreviewSplitPaneDividerLocation = null;
|
||||
@ConfigurationName("gui.splitPane1.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiSplitPane1DividerLocation = null;
|
||||
@ConfigurationName("gui.splitPane2.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiSplitPane2DividerLocation = null;
|
||||
@ConfigurationDefaultInt(3)
|
||||
public static final ConfigurationItem<Integer> saveAsExeScaleMode = null;
|
||||
@ConfigurationDefaultInt(1024 * 100/*100KB*/)
|
||||
public static final ConfigurationItem<Integer> syntaxHighlightLimit = null;
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewSampleText = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.width")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewWidth = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.height")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewHeight = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.posX")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewPosX = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.posY")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewPosY = null;
|
||||
@ConfigurationDefaultInt(1000)
|
||||
@ConfigurationName("gui.window.width")
|
||||
public static final ConfigurationItem<Integer> guiWindowWidth = null;
|
||||
@ConfigurationDefaultInt(700)
|
||||
@ConfigurationName("gui.window.height")
|
||||
public static final ConfigurationItem<Integer> guiWindowHeight = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationName("gui.window.maximized.horizontal")
|
||||
public static final ConfigurationItem<Boolean> guiWindowMaximizedHorizontal = null;
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationName("gui.window.maximized.vertical")
|
||||
public static final ConfigurationItem<Boolean> guiWindowMaximizedVertical = null;
|
||||
@ConfigurationName("gui.avm2.splitPane.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiAvm2SplitPaneDividerLocation = null;
|
||||
@ConfigurationName("guiActionSplitPaneDividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiActionSplitPaneDividerLocation = null;
|
||||
@ConfigurationName("guiPreviewSplitPaneDividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiPreviewSplitPaneDividerLocation = null;
|
||||
@ConfigurationName("gui.splitPane1.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiSplitPane1DividerLocation = null;
|
||||
@ConfigurationName("gui.splitPane2.dividerLocation")
|
||||
public static final ConfigurationItem<Integer> guiSplitPane2DividerLocation = null;
|
||||
@ConfigurationDefaultInt(3)
|
||||
public static final ConfigurationItem<Integer> saveAsExeScaleMode = null;
|
||||
@ConfigurationDefaultInt(1024 * 100/*100KB*/)
|
||||
public static final ConfigurationItem<Integer> syntaxHighlightLimit = null;
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewSampleText = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.width")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewWidth = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.height")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewHeight = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.posX")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewPosX = null;
|
||||
@ConfigurationName("gui.fontPreviewWindow.posY")
|
||||
public static final ConfigurationItem<Integer> guiFontPreviewPosY = null;
|
||||
|
||||
private enum OSId {
|
||||
@ConfigurationDefaultInt(3)
|
||||
@ConfigurationName("formatting.indent.size")
|
||||
@ConfigurationDescription("Number or spaces(or tabs) for one indentation")
|
||||
public static final ConfigurationItem<Integer> indentSize = null;
|
||||
|
||||
WINDOWS, OSX, UNIX
|
||||
}
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationName("formatting.indent.useTabs")
|
||||
@ConfigurationDescription("Use tabs instead of spaces for indentation")
|
||||
public static final ConfigurationItem<Boolean> indentUseTabs = null;
|
||||
|
||||
private static OSId getOSId() {
|
||||
PrivilegedAction<String> doGetOSName = new PrivilegedAction<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty("os.name");
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> beginBlockOnNewLine = null;
|
||||
|
||||
private enum OSId {
|
||||
|
||||
WINDOWS, OSX, UNIX
|
||||
}
|
||||
|
||||
private static OSId getOSId() {
|
||||
PrivilegedAction<String> doGetOSName = new PrivilegedAction<String>() {
|
||||
@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<String> 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<String> 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<String> recentFilesArray = new ArrayList<>(getRecentFiles());
|
||||
int idx = recentFilesArray.indexOf(path);
|
||||
if (idx != -1) {
|
||||
recentFilesArray.remove(idx);
|
||||
}
|
||||
recentFiles.set(Helper.joinStrings(recentFilesArray, "::"));
|
||||
}
|
||||
|
||||
public static Map<String, String> getFontPairs() {
|
||||
String fonts = fontPairing.get();
|
||||
if (fonts == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<String, String> 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<String, String> fontPairs = getFontPairs();
|
||||
fontPairs.put(key, systemFontName);
|
||||
fontPairs.put(fontName, systemFontName);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Entry<String, String> 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<String, Object> loadFromFile(String file, String replacementsFile) {
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<String, Object> cfg = (HashMap<String, Object>) 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<String, Object> config = new HashMap<>();
|
||||
for (Entry<String, Field> 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<String> 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<String> 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<String> recentFilesArray = new ArrayList<>(getRecentFiles());
|
||||
int idx = recentFilesArray.indexOf(path);
|
||||
if (idx != -1) {
|
||||
recentFilesArray.remove(idx);
|
||||
}
|
||||
recentFiles.set(Helper.joinStrings(recentFilesArray, "::"));
|
||||
}
|
||||
|
||||
public static Map<String, String> getFontPairs() {
|
||||
String fonts = fontPairing.get();
|
||||
if (fonts == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<String, String> 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<String, String> fontPairs = getFontPairs();
|
||||
fontPairs.put(key, systemFontName);
|
||||
fontPairs.put(fontName, systemFontName);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Entry<String, String> 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<String, Object> loadFromFile(String file, String replacementsFile) {
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<String, Object> cfg = (HashMap<String, Object>) 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<String, Object> config = new HashMap<>();
|
||||
for (Entry<String, Field> 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<Replacement> 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<Replacement> getReplacements() {
|
||||
return replacements;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void setConfigurationFields() {
|
||||
try {
|
||||
HashMap<String, Object> config = loadFromFile(getConfigFile(), getReplacementsFile());
|
||||
for (Entry<String, Field> 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<String, Object> config = loadFromFile(getConfigFile(), getReplacementsFile());
|
||||
for (Entry<String, Field> 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<String, Field> getConfigurationFields() {
|
||||
Field[] fields = Configuration.class.getFields();
|
||||
Map<String, Field> 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<String, Field> getConfigurationFields() {
|
||||
Field[] fields = Configuration.class.getFields();
|
||||
Map<String, Field> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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(" ");
|
||||
|
||||
@@ -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<String>(), 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<String>(), 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<String>(), 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<String>(), false);
|
||||
s = writer.toString();
|
||||
} else if (!isStatic) {
|
||||
|
||||
@@ -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<Highlighting> 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);
|
||||
}
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class CodeFormatting {
|
||||
public String newLineChars = "\r\n";
|
||||
public String indentString = " ";
|
||||
public boolean beginBlockOnNewLine = true;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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("}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,13 @@ public class HilightedTextWriter extends GraphTextWriter {
|
||||
public List<Highlighting> instructionHilights = new ArrayList<>();
|
||||
public List<Highlighting> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user