diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfIntelliJIdeaExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfIntelliJIdeaExporter.java
index db9364673..ac0396307 100644
--- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfIntelliJIdeaExporter.java
+++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfIntelliJIdeaExporter.java
@@ -26,14 +26,31 @@ import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
+import java.util.UUID;
/**
*
* @author JPEXS
*/
public class SwfIntelliJIdeaExporter {
+
+ private static final String PROJECTID_CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ private static final int PROJECTID_LENGTH = 27;
+ private static final SecureRandom RANDOM = new SecureRandom();
+
+ private static String generateProjectId() {
+ StringBuilder sb = new StringBuilder(PROJECTID_LENGTH);
+ for (int i = 0; i < PROJECTID_LENGTH; i++) {
+ int randomIndex = RANDOM.nextInt(PROJECTID_CHARACTERS.length());
+ sb.append(PROJECTID_CHARACTERS.charAt(randomIndex));
+ }
+ return sb.toString();
+ }
+
private static String doubleToString(double d) {
String ds = "" + d;
@@ -43,22 +60,30 @@ public class SwfIntelliJIdeaExporter {
return ds;
}
- public void exportIntelliJIdeaProject(SWF swf, File outFile, AbortRetryIgnoreHandler handler) throws IOException {
- exportIntelliJIdeaProject(swf, outFile, handler, null);
- }
+ public void exportIntelliJIdeaProject(SWF swf, File outDir, AbortRetryIgnoreHandler handler) throws IOException {
+ exportIntelliJIdeaProject(swf, outDir, handler, null);
+ }
- public void exportIntelliJIdeaProject(SWF swf, File outFile, AbortRetryIgnoreHandler handler, EventListener eventListener) throws IOException {
+ public void exportIntelliJIdeaProject(SWF swf, File outDir, AbortRetryIgnoreHandler handler, EventListener eventListener) throws IOException {
if (!swf.isAS3()) {
throw new IllegalArgumentException("SWF must be AS3");
}
+
+ if (!outDir.exists()) {
+ if (!outDir.mkdirs()) {
+ throw new IOException("Cannot create directory");
+ }
+ }
+ if (!outDir.isDirectory()) {
+ throw new IOException("The selected file is not a directory");
+ }
- String simpleName = outFile.getName();
+ String simpleName = swf.getShortFileName();
if (simpleName.contains(".")) {
simpleName = simpleName.substring(0, simpleName.lastIndexOf("."));
}
- File baseDir = outFile.getParentFile();
- File ideaDir = new File(baseDir, ".idea");
+ File ideaDir = new File(outDir, ".idea");
String documentClass = swf.getDocumentClass();
if (documentClass == null) {
@@ -100,17 +125,113 @@ public class SwfIntelliJIdeaExporter {
+ " \n"
+ " \n"
+ "";
- try (FileOutputStream fos = new FileOutputStream(outFile)) {
+ try (FileOutputStream fos = new FileOutputStream(new File(outDir, simpleName + ".iml"))) {
fos.write(Utf8Helper.getBytes(imlData));
}
ideaDir.mkdir();
+ long created = System.currentTimeMillis();
+ String workspaceXml = "\n"
+ + "\n"
+ + " \n"
+ + "
\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " " + created + "\n"
+ + " \n"
+ + " \n"
+ + " " + created + "\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + "";
+ try (FileOutputStream fos = new FileOutputStream(new File(ideaDir, "workspace.xml"))) {
+ fos.write(Utf8Helper.getBytes(workspaceXml));
+ }
+
String modulesXml = "\n"
+ "\n"
+ " \n"
+ " \n"
- + " \n"
+ + " \n"
+ " \n"
+ " \n"
+ "";
@@ -130,7 +251,7 @@ public class SwfIntelliJIdeaExporter {
String miscXml = "\n"
+ "\n"
- + " \n"
+ + " \n"
+ " \n"
+ " \n"
+ "";
@@ -139,7 +260,7 @@ public class SwfIntelliJIdeaExporter {
}
try (FileOutputStream fos = new FileOutputStream(new File(ideaDir, ".name"))) {
- fos.write(Utf8Helper.getBytes(outFile.getName()));
+ fos.write(Utf8Helper.getBytes(simpleName + ".iml"));
}
String gitIgnore = "# Default ignored files\n"
@@ -149,13 +270,13 @@ public class SwfIntelliJIdeaExporter {
+ "/httpRequests/\n"
+ "# Datasource local storage ignored files\n"
+ "/dataSources/\n"
- + "/dataSources.local.xml";
+ + "/dataSources.local.xml\n";
try (FileOutputStream fos = new FileOutputStream(new File(ideaDir, ".gitignore"))) {
fos.write(Utf8Helper.getBytes(gitIgnore));
}
boolean parallel = Configuration.parallelSpeedUp.get();
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, false);
- swf.exportActionScript(handler, new File(outFile.getParentFile(), "src").getAbsolutePath(), scriptExportSettings, parallel, eventListener);
+ swf.exportActionScript(handler, new File(outDir, "src").getAbsolutePath(), scriptExportSettings, parallel, eventListener);
}
}
diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java
index b484cebce..1850da607 100644
--- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java
+++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java
@@ -3429,50 +3429,18 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
JFileChooser fc = new JFileChooser();
String selDir = Configuration.lastOpenDir.get();
fc.setCurrentDirectory(new File(selDir));
- if (!selDir.endsWith(File.separator)) {
- selDir += File.separator;
- }
- String swfShortName = swf.getShortFileName();
- if ("".equals(swfShortName)) {
- swfShortName = "untitled.swf";
- }
- String fileName;
- if (swfShortName.contains(".")) {
- fileName = swfShortName.substring(0, swfShortName.lastIndexOf(".")) + ".iml";
- } else {
- fileName = swfShortName + ".iml";
- }
-
- FileFilter f = new FileFilter() {
- @Override
- public boolean accept(File f) {
- return f.isDirectory() || (f.getName().toLowerCase(Locale.ENGLISH).endsWith(".iml"));
- }
-
- @Override
- public String getDescription() {
- return translate("filter.iml");
- }
- };
- fc.setFileFilter(f);
- fc.setAcceptAllFileFilterUsed(false);
- fc.setSelectedFile(new File(selDir + fileName));
-
- if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get()));
+ chooser.setDialogTitle(translate("export.project.select.directory"));
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ chooser.setAcceptAllFileFilterUsed(false);
+ if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
return;
- }
-
- Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
- File sf = Helper.fixDialogFile(fc.getSelectedFile());
- SwfIntelliJIdeaExporter exporter = new SwfIntelliJIdeaExporter();
-
- String path = sf.getAbsolutePath();
- if (path.endsWith(".iml")) {
- path = path.substring(0, path.length() - ".iml".length());
}
- path += ".iml";
+ final String fpath = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath();
+ Configuration.lastExportDir.set(Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath());
+ SwfIntelliJIdeaExporter exporter = new SwfIntelliJIdeaExporter();
- final String fpath = path;
long timeBefore = System.currentTimeMillis();
new CancellableWorker() {
diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties
index 5114e164e..cd39c31b3 100644
--- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties
+++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties
@@ -1291,4 +1291,6 @@ work.exporting.idea = Exporting IntelliJ IDEA project
menu.file.export.idea = Export IDEA project
-contextmenu.exportFla = Export to FLA
\ No newline at end of file
+contextmenu.exportFla = Export to FLA
+
+export.project.select.directory = Select location of the new project directory
\ No newline at end of file
diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties
index 34dde95be..23154a2ee 100644
--- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties
+++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties
@@ -1267,4 +1267,6 @@ work.exporting.idea = Exportov\u00e1n\u00ed IntelliJ IDEA projektu
menu.file.export.idea = Exportovat IDEA projekt
-contextmenu.exportFla = Exportovat do FLA
\ No newline at end of file
+contextmenu.exportFla = Exportovat do FLA
+
+export.project.select.directory = Vyberte um\u00edst\u011bn\u00ed nov\u00e9ho adres\u00e1\u0159e projektu
\ No newline at end of file