From c4a7ac1e3266abdc8eb46eb190efbd6cf15796e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 5 May 2013 18:49:25 +0200 Subject: [PATCH] Issue #86 open file dialog accepts names with quotes --- trunk/src/com/jpexs/decompiler/flash/Main.java | 7 ++++--- .../decompiler/flash/abc/gui/ClassesListTree.java | 6 +++--- .../com/jpexs/decompiler/flash/gui/MainFrame.java | 8 ++++---- .../com/jpexs/decompiler/flash/helpers/Helper.java | 13 +++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/Main.java b/trunk/src/com/jpexs/decompiler/flash/Main.java index 5aefc1cc6..f436a5ffa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/Main.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.gui.NewVersionDialog; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel; import com.jpexs.decompiler.flash.gui.proxy.ProxyFrame; +import com.jpexs.decompiler.flash.helpers.Helper; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -277,7 +278,7 @@ public class Main { View.setWindowIcon(f); int returnVal = fc.showSaveDialog(f); if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); + File file = Helper.fixDialogFile(fc.getSelectedFile()); try { Main.saveFile(file.getAbsolutePath()); Configuration.setConfig("lastSaveDir", file.getParentFile().getAbsolutePath()); @@ -309,8 +310,8 @@ public class Main { View.setWindowIcon(f); int returnVal = fc.showOpenDialog(f); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.setConfig("lastOpenDir", fc.getSelectedFile().getParentFile().getAbsolutePath()); - File selfile = fc.getSelectedFile(); + Configuration.setConfig("lastOpenDir", Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath()); + File selfile = Helper.fixDialogFile(fc.getSelectedFile()); Main.openFile(selfile.getAbsolutePath()); return true; } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTree.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTree.java index e1d9bd87e..6825354c7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTree.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTree.java @@ -103,10 +103,10 @@ public class ClassesListTree extends JTree implements TreeSelectionListener { ABC abc = tag.getABC(); for (int i = 0; i < abc.script_info.length; i++) { ScriptInfo script = abc.script_info[i]; - HashMap packs=script.getPacks(abc, i); - for(String path:packs.keySet()){ + HashMap packs = script.getPacks(abc, i); + for (String path : packs.keySet()) { ret.put(path, packs.get(path)); - } + } } } return ret; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 6b8a5d367..f18ee43d4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1154,8 +1154,8 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi View.setWindowIcon(f); int returnVal = fc.showOpenDialog(f); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.setConfig("lastOpenDir", fc.getSelectedFile().getParentFile().getAbsolutePath()); - File selfile = fc.getSelectedFile(); + Configuration.setConfig("lastOpenDir", Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath()); + File selfile = Helper.fixDialogFile(fc.getSelectedFile()); byte data[] = Helper.readFile(selfile.getAbsolutePath()); try { it.setImage(data); @@ -1289,8 +1289,8 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final long timeBefore = System.currentTimeMillis(); Main.startWork("Exporting..."); - final String selFile = chooser.getSelectedFile().getAbsolutePath(); - Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath()); + final String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); + Configuration.setConfig("lastExportDir", Helper.fixDialogFile(chooser.getSelectedFile()).getParentFile().getAbsolutePath()); final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; final boolean isMp3 = export.getOption(ExportDialog.OPTION_SOUNDS) == 0; final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1; diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/Helper.java b/trunk/src/com/jpexs/decompiler/flash/helpers/Helper.java index 60c76f095..af605921f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/Helper.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/Helper.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.helpers; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -29,6 +30,8 @@ import java.util.List; import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Class with helper method @@ -346,4 +349,14 @@ public class Helper { ret += "]"; return Highlighting.stripHilights(ret); } + + public static File fixDialogFile(File f) { + Pattern pat = Pattern.compile("\"([^\"]+)\""); + String name = f.getAbsolutePath(); + Matcher m = pat.matcher(name); + if (m.find()) { + f = new File(m.group(1)); + } + return f; + } }