From b786104aaa03e0c5e8e4157cd3792d5c83f54ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Tue, 9 Jul 2013 14:05:47 +0200 Subject: [PATCH] Issue #212 Cannot create directory issue / parallel mkdirs --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 58 ++++++++++++------- .../com/jpexs/decompiler/flash/TagNode.java | 4 +- .../decompiler/flash/abc/ScriptPack.java | 4 +- .../flash/abc/types/traits/Trait.java | 6 +- .../com/jpexs/decompiler/flash/gui/Main.java | 26 ++++++--- .../jpexs/decompiler/flash/gui/MainFrame.java | 21 +++++-- .../flash/gui/proxy/ProxyFrame.java | 14 ++++- .../decompiler/flash/xfl/XFLConverter.java | 16 ++++- 8 files changed, 108 insertions(+), 41 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 7b885576a..ffeff2c0e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -989,9 +989,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1176,9 +1179,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1198,9 +1204,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1228,9 +1237,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1254,9 +1266,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1277,9 +1292,12 @@ public class SWF { if (tags.isEmpty()) { return ret; } - if (!(new File(outdir)).exists()) { - if (!(new File(outdir)).mkdirs()) { - throw new IOException("Cannot create directory " + outdir); + File foutdir = new File(outdir); + if (!foutdir.exists()) { + if (!foutdir.mkdirs()) { + if (!foutdir.exists()) { + throw new IOException("Cannot create directory " + outdir); + } } } for (Tag t : tags) { @@ -1975,11 +1993,11 @@ public class SWF { return ret; } - public void exportFla(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) { + public void exportFla(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) throws IOException { XFLConverter.convertSWF(this, swfName, outfile, true, generator, generatorVerName, generatorVersion, paralel); } - public void exportXfl(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) { + public void exportXfl(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) throws IOException { XFLConverter.convertSWF(this, swfName, outfile, false, generator, generatorVerName, generatorVersion, paralel); } diff --git a/trunk/src/com/jpexs/decompiler/flash/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/TagNode.java index 2351d9358..0d4335b52 100644 --- a/trunk/src/com/jpexs/decompiler/flash/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/TagNode.java @@ -257,7 +257,9 @@ public class TagNode { if ((node.tag instanceof ASMSource) && (node.export)) { if (!dir.exists()) { if (!dir.mkdirs()) { - continue; + if (!dir.exists()) { + continue; + } } } try { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 92a96e4ef..ee437d92f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -102,7 +102,9 @@ public class ScriptPack { File outDir = new File(directory + File.separatorChar + makeDirPath(packageName)); if (!outDir.exists()) { if (!outDir.mkdirs()) { - throw new IOException("cannot create directory " + outDir); + if (!outDir.exists()) { + throw new IOException("cannot create directory " + outDir); + } } } String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + ".as"; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 9c6012085..e59550df2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -159,7 +159,11 @@ public abstract class Trait implements Serializable { String objectName = name.getName(abc.constants, new ArrayList()); File outDir = new File(directory + File.separatorChar + packageName.replace('.', File.separatorChar)); if (!outDir.exists()) { - outDir.mkdirs(); + if (!outDir.mkdirs()) { + if (!outDir.exists()) { + throw new IOException("Cannot create directory " + outDir); + } + } } String fileName = outDir.toString() + File.separator + objectName + ".as"; try (FileOutputStream fos = new FileOutputStream(fileName)) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index b490c8c77..1104b6f53 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -680,10 +680,14 @@ public class Main { } } - public static String tempFile(String url) { + public static String tempFile(String url) throws IOException { File f = new File(getFFDecHome() + "saved" + File.separator); if (!f.exists()) { - f.mkdirs(); + if (!f.mkdirs()) { + if (!f.exists()) { + throw new IOException("cannot create directory " + f); + } + } } return getFFDecHome() + "saved" + File.separator + "asdec_" + Integer.toHexString(url.hashCode()) + ".tmp"; @@ -774,7 +778,11 @@ public class Main { } public static void exit() { - Configuration.saveToFile(getConfigFile(), getReplacementsFile()); + try { + Configuration.saveToFile(getConfigFile(), getReplacementsFile()); + } catch (IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } FlashPlayerPanel.unload(); System.exit(0); } @@ -933,7 +941,7 @@ public class Main { return id; } - public static String getFFDecHome() { + public static String getFFDecHome() throws IOException { if (directory == unspecifiedFile) { directory = null; String userHome = null; @@ -975,7 +983,11 @@ public class Main { } } if (!directory.exists()) { - directory.mkdirs(); + if (!directory.mkdirs()) { + if (!directory.exists()) { + throw new IOException("cannot create directory " + directory); + } + } } String ret = directory.getAbsolutePath(); if (!ret.endsWith(File.separator)) { @@ -984,11 +996,11 @@ public class Main { return ret; } - private static String getReplacementsFile() { + private static String getReplacementsFile() throws IOException { return getFFDecHome() + REPLACEMENTS_NAME; } - private static String getConfigFile() { + private static String getConfigFile() throws IOException { return getFFDecHome() + CONFIG_NAME; } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 701560139..798c46359 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -611,7 +611,14 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection } Random rnd = new Random(); tempDir += "ffdec" + File.separator + "export" + File.separator + System.currentTimeMillis() + "_" + rnd.nextInt(1000); - new File(tempDir).mkdirs(); + File fTempDir = new File(tempDir); + if (!fTempDir.exists()) { + if (!fTempDir.mkdirs()) { + if (!fTempDir.exists()) { + throw new IOException("cannot create directory " + fTempDir); + } + } + } final ExportDialog export = new ExportDialog(); try { @@ -1940,10 +1947,14 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection (new Thread() { @Override public void run() { - if (compressed) { - swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); - } else { - swf.exportXfl(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); + try { + if (compressed) { + swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); + } else { + swf.exportXfl(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); + } + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, translate("error.export") + ": " + ex.getLocalizedMessage(), translate("error"), JOptionPane.ERROR_MESSAGE); } Main.stopWork(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java index 78335f8b1..c0cb9ba39 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java @@ -32,6 +32,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Calendar; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.*; /** @@ -190,10 +192,16 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe if (e.getActionCommand().equals("CLEAR")) { for (int i = 0; i < listModel.getSize(); i++) { Replacement r = (Replacement) listModel.getElementAt(i); - File f = (new File(Main.tempFile(r.targetFile))); - if (f.exists()) { - f.delete(); + File f; + try { + f = (new File(Main.tempFile(r.targetFile))); + if (f.exists()) { + f.delete(); + } + } catch (IOException ex) { + Logger.getLogger(ProxyFrame.class.getName()).log(Level.SEVERE, null, ex); } + } listModel.clear(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index c67347a79..5d4cdf043 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -2450,7 +2450,7 @@ public class XFLConverter { return ret; } - public static void convertSWF(SWF swf, String swfFileName, String outfile, boolean compressed, String generator, String generatorVerName, String generatorVersion, boolean paralel) { + public static void convertSWF(SWF swf, String swfFileName, String outfile, boolean compressed, String generator, String generatorVerName, String generatorVersion, boolean paralel) throws IOException { File file = new File(outfile); File outDir = file.getParentFile(); String domDocument = ""; @@ -2530,7 +2530,11 @@ public class XFLConverter { expPath = expPath.replace(".", File.separator); File cdir = new File(outDir.getAbsolutePath() + File.separator + expDir); if (!cdir.exists()) { - cdir.mkdirs(); + if (!cdir.mkdirs()) { + if (!cdir.exists()) { + throw new IOException("cannot create directory " + cdir); + } + } } try { writeFile(data.getBytes("UTF-8"), outDir.getAbsolutePath() + File.separator + expPath + ".as"); @@ -2770,7 +2774,13 @@ public class XFLConverter { } else { - outDir.mkdirs(); + if (!outDir.exists()) { + if (!outDir.mkdirs()) { + if (!outDir.exists()) { + throw new IOException("cannot create directory " + outDir); + } + } + } try { writeFile(domDocument.getBytes("UTF-8"), outDir.getAbsolutePath() + File.separator + "DOMDocument.xml"); } catch (UnsupportedEncodingException ex) {