diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java index 3fad0d23e..c6dbc6d0d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java @@ -122,7 +122,7 @@ public class AS2ScriptExporter { Path.createDirectorySafe(new File(outdir)); } - String f = outdir + name + exportSettings.getFileExtension(); + String f = Path.combine(outdir, name) + exportSettings.getFileExtension(); if (evl != null) { evl.handleExportingEvent("script", currentIndex, count, f); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java index c318c2150..28a26d092 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java @@ -23,6 +23,9 @@ import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -36,16 +39,39 @@ public class ScriptImporter { private static final Logger logger = Logger.getLogger(ScriptImporter.class.getName()); public void importScripts(String scriptsFolder, Map asms) { + if (!scriptsFolder.endsWith(File.separator)) { + scriptsFolder += File.separator; + } + + Map> existingNamesMap = new HashMap<>(); for (String key : asms.keySet()) { - String fileName = Path.combine(scriptsFolder, key) + ".as"; + ASMSource asm = asms.get(key); + String currentOutDir = scriptsFolder + key + File.separator; + currentOutDir = new File(currentOutDir).getParentFile().toString() + File.separator; + + List existingNames = existingNamesMap.get(currentOutDir); + if (existingNames == null) { + existingNames = new ArrayList<>(); + existingNamesMap.put(currentOutDir, existingNames); + } + + String name = Helper.makeFileName(asm.getExportFileName()); + int i = 1; + String baseName = name; + while (existingNames.contains(name)) { + i++; + name = baseName + "_" + i; + } + existingNames.add(name); + + String fileName = Path.combine(currentOutDir, name) + ".as"; if (new File(fileName).exists()) { - ASMSource src = asms.get(key); String as = Helper.readTextFile(fileName); - com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser par = new com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser(src.getSwf().version); + com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser par = new com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser(asm.getSwf().version); try { - src.setActions(par.actionsFromString(as)); + asm.setActions(par.actionsFromString(as)); } catch (ActionParseException ex) { logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex); } catch (CompilationException ex) { @@ -54,7 +80,7 @@ public class ScriptImporter { logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex); } - src.setModified(); + asm.setModified(); } } }