diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index e15864d9c..da87c6ccf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1274,7 +1274,8 @@ public final class SWF implements SWFContainerItem, Timelined { } String eventData = cnt + scr.getPath() + " ..."; evl.handleExportingEvent("tag", i + 1, abcList.size(), eventData); - scr.export(outdir, exportSettings, parallel); + File file = scr.getExportFile(outdir, exportSettings); + scr.export(file, exportSettings, parallel); evl.handleExportedEvent("tag", i + 1, abcList.size(), eventData); exported = true; } 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 66bda3a12..e2d4063bd 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 @@ -107,11 +107,14 @@ public class ScriptPack extends AS3ClassTreeItem { return scriptName; } - public File getExportFile(String directory, ScriptExportSettings exportSettings) throws IOException { + public File getExportFile(String directory, ScriptExportSettings exportSettings) { + if (exportSettings.singleFile) { + return null; + } + String scriptName = getPathScriptName(); DottedChain packageName = getPathPackage(); File outDir = new File(directory + File.separatorChar + packageName.toFilePath()); - Path.createDirectorySafe(outDir); String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + exportSettings.getFileExtension(); return new File(fileName); } @@ -189,16 +192,15 @@ public class ScriptPack extends AS3ClassTreeItem { appendTo(writer, traits, exportMode, parallel); } - public File export(String directory, ScriptExportSettings exportSettings, boolean parallel) throws IOException, InterruptedException { - File file = null; - + public File export(File file, ScriptExportSettings exportSettings, boolean parallel) throws IOException, InterruptedException { if (!exportSettings.singleFile) { - file = getExportFile(directory, exportSettings); if (file.exists() && !Configuration.overwriteExistingFiles.get()) { return file; } } + Path.createDirectorySafe(file.getParentFile()); + try (FileTextWriter writer = exportSettings.singleFile ? null : new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) { FileTextWriter writer2 = exportSettings.singleFile ? exportSettings.singleFileWriter : writer; toSource(writer2, abc.script_info.get(scriptIndex).traits.traits, exportSettings.mode, parallel); 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 e10c8b643..0cb560e9a 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 @@ -24,9 +24,12 @@ import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; +import com.jpexs.helpers.Path; import java.io.File; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -51,12 +54,29 @@ public class AS3ScriptExporter { int cnt = 1; List tasks = new ArrayList<>(); + Set files = new HashSet<>(); for (ScriptPack item : packs) { if (!item.isSimple && Configuration.ignoreCLikePackages.get()) { continue; } - tasks.add(new ExportPackTask(handler, cnt++, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl)); + 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.toUpperCase())); + + file = new File(filePath); + } + + files.add(filePath.toLowerCase()); + tasks.add(new ExportPackTask(handler, cnt++, packs.size(), item.getClassPath(), item, file, exportSettings, parallel, evl)); } if (!parallel || tasks.size() < 2) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java index 483d0a21d..48c9363cf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java @@ -36,7 +36,7 @@ public class ExportPackTask implements Callable { ScriptPack pack; - String directory; + File file; ScriptExportSettings exportSettings; @@ -56,9 +56,9 @@ public class ExportPackTask implements Callable { EventListener eventListener; - public ExportPackTask(AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, String directory, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { + public ExportPackTask(AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, File file, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { this.pack = pack; - this.directory = directory; + this.file = file; this.exportSettings = exportSettings; this.path = path; this.index = index; @@ -74,7 +74,7 @@ public class ExportPackTask implements Callable { @Override public void run() throws IOException, InterruptedException { startTime = System.currentTimeMillis(); - this.result = pack.export(directory, exportSettings, parallel); + this.result = pack.export(file, exportSettings, parallel); stopTime = System.currentTimeMillis(); } }; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 792a297fc..7f119c7f8 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1244,7 +1244,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + as3scripts.size() + " " + tls.getPath() + " ...", null); - ret.add(tls.export(scriptsFolder, scriptExportSettings, parallel)); + File file = tls.getExportFile(scriptsFolder, scriptExportSettings); + ret.add(tls.export(file, scriptExportSettings, parallel)); } } } else {