From 0419fbc399b469619edca235fc0929a9746058c8 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sat, 30 Apr 2016 14:00:04 +0200 Subject: [PATCH] show warning when parallel export and single file export are both enabled --- .../decompiler/flash/abc/ScriptPack.java | 4 ++- .../exporters/script/AS3ScriptExporter.java | 30 +++++++++++-------- .../console/CommandLineArgumentParser.java | 13 ++++---- .../jpexs/decompiler/flash/gui/MainPanel.java | 24 +++++++++++++-- .../flash/gui/locales/MainFrame.properties | 1 + 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 2313ca712..517152c1f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -275,7 +275,9 @@ public class ScriptPack extends AS3ClassTreeItem { } } - Path.createDirectorySafe(file.getParentFile()); + if (file != null) { + Path.createDirectorySafe(file.getParentFile()); + } try (FileTextWriter writer = exportSettings.singleFile ? null : new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) { FileTextWriter writer2 = exportSettings.singleFile ? exportSettings.singleFileWriter : writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java index 06166ce43..099e63d3f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java @@ -376,22 +376,26 @@ public class AS3ScriptExporter { } } - File file = item.getExportFile(outdir, exportSettings); - String filePath = file.getPath(); - if (files.contains(filePath.toLowerCase())) { - String parentPath = file.getParent(); - String fileName = file.getName(); - String extension = Path.getExtension(fileName); - String fileNameWithoutExtension = Path.getFileNameWithoutExtension(file); - int i = 2; - do { - filePath = Path.combine(parentPath, fileNameWithoutExtension + "_" + i++ + extension); - } while (files.contains(filePath.toLowerCase())); + File file = null; + if (!exportSettings.singleFile) { + file = item.getExportFile(outdir, exportSettings); + String filePath = file.getPath(); + if (files.contains(filePath.toLowerCase())) { + String parentPath = file.getParent(); + String fileName = file.getName(); + String extension = Path.getExtension(fileName); + String fileNameWithoutExtension = Path.getFileNameWithoutExtension(file); + int i = 2; + do { + filePath = Path.combine(parentPath, fileNameWithoutExtension + "_" + i++ + extension); + } while (files.contains(filePath.toLowerCase())); - file = new File(filePath); + file = new File(filePath); + } + + files.add(filePath.toLowerCase()); } - files.add(filePath.toLowerCase()); tasks.add(new ExportPackTask(handler, cnt++, packs.size(), item.getClassPath(), item, file, exportSettings, parallel, evl)); } diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index a19695fbc..f8c1c38b2 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -81,6 +81,7 @@ import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; +import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.SearchInMemory; import com.jpexs.decompiler.flash.gui.SearchInMemoryListener; @@ -219,8 +220,8 @@ public class CommandLineArgumentParser { return commandLineMode; } - public static void printCmdLineUsage(String filter) { - printCmdLineUsage(System.out, true, filter); + public static void printCmdLineUsage(String filter, boolean webHelp) { + printCmdLineUsage(System.out, webHelp, filter); } public static void printCmdLineUsage(PrintStream out, boolean webHelp, String filter) { @@ -784,11 +785,11 @@ public class CommandLineArgumentParser { parseResourceDates(args); } else if (nextParam.equals("-help") || nextParam.equals("--help") || nextParam.equals("/?") || nextParam.equals("\\_") /* /? translates as this on windows */) { printHeader(); - printCmdLineUsage(null); + printCmdLineUsage(null, false); System.exit(0); } else if (nextParam.equals("--webhelp")) { //for generating commandline usage on webpages ByteArrayOutputStream whbaos = new ByteArrayOutputStream(); - printCmdLineUsage(new PrintStream(whbaos, true), false, null); + printCmdLineUsage(new PrintStream(whbaos, true), true, null); String wh = new String(whbaos.toByteArray()); wh = wh.replace("<", "<").replace(">", ">"); System.out.println(wh); @@ -840,7 +841,7 @@ public class CommandLineArgumentParser { public static void badArguments(String command) { System.err.println("Error: Bad Commandline Arguments!"); - printCmdLineUsage(command); + printCmdLineUsage(command, false); System.exit(1); } @@ -1561,7 +1562,7 @@ public class CommandLineArgumentParser { } if (parallel && singleScriptFile) { - System.out.println("Single file script export is not supported with enabled parallel speedup"); + logger.log(Level.WARNING, AppStrings.translate("export.script.singleFilePallelModeWarning")); singleScriptFile = false; } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 8d08d3958..575a7e367 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1263,7 +1263,13 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se boolean parallel = Configuration.parallelSpeedUp.get(); String scriptsFolder = Path.combine(selFile2, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); - ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), !parallel && Configuration.scriptExportSingleFile.get()); + boolean singleScriptFile = Configuration.scriptExportSingleFile.get(); + if (parallel && singleScriptFile) { + logger.log(Level.WARNING, AppStrings.translate("export.script.singleFilePallelModeWarning")); + singleScriptFile = false; + } + + ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) { scriptExportSettings.singleFileWriter = writer; @@ -1365,7 +1371,13 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se boolean parallel = Configuration.parallelSpeedUp.get(); String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); - ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), !parallel && Configuration.scriptExportSingleFile.get()); + boolean singleScriptFile = Configuration.scriptExportSingleFile.get(); + if (parallel && singleScriptFile) { + logger.log(Level.WARNING, AppStrings.translate("export.script.singleFilePallelModeWarning")); + singleScriptFile = false; + } + + ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) { scriptExportSettings.singleFileWriter = writer; @@ -1477,7 +1489,13 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se for (ScriptExportMode exportMode : ScriptExportMode.values()) { String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME, exportMode.name()); Path.createDirectorySafe(new File(scriptsFolder)); - ScriptExportSettings scriptExportSettings = new ScriptExportSettings(exportMode, !parallel && Configuration.scriptExportSingleFile.get()); + boolean singleScriptFile = Configuration.scriptExportSingleFile.get(); + if (parallel && singleScriptFile) { + logger.log(Level.WARNING, AppStrings.translate("export.script.singleFilePallelModeWarning")); + singleScriptFile = false; + } + + ScriptExportSettings scriptExportSettings = new ScriptExportSettings(exportMode, singleScriptFile); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) { scriptExportSettings.singleFileWriter = writer; diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 581c7ea8a..664df88d2 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -716,3 +716,4 @@ message.warning.outOfMemory32BitJre = OutOfMemory error occured. You are running menu.file.reloadAll = Reload all message.confirm.reloadAll = This action cancels all unsaved changes in all SWF files and reloads whole application again.\nDo you want to continue? +export.script.singleFilePallelModeWarning = Single file script export is not supported with enabled parallel speedup