Issue #253 Abort/Retry/Ignore dialog on IO errors

This commit is contained in:
Jindra Pet��k
2013-07-18 12:28:07 +02:00
parent 58ab6ab390
commit 12a191de9b
12 changed files with 497 additions and 204 deletions
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
import com.jpexs.decompiler.flash.Configuration;
import com.jpexs.decompiler.flash.EventListener;
import com.jpexs.decompiler.flash.PercentListener;
@@ -27,6 +28,7 @@ import com.jpexs.decompiler.flash.gui.jna.platform.win32.Advapi32Util;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.SHELLEXECUTEINFO;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.Shell32;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.Win32Exception;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg;
import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinUser;
import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel;
@@ -50,6 +52,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Locale;
import java.util.Properties;
import java.util.Scanner;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
@@ -618,6 +621,27 @@ public class Main {
"fla",
"xfl"
};
AbortRetryIgnoreHandler handler = new AbortRetryIgnoreHandler() {
@Override
public int handle(Throwable thrown) {
Scanner sc = new Scanner(System.in);
System.out.println("Error occured: " + thrown.getLocalizedMessage());
String n = null;
do {
System.out.print("Select action: (A)bort, (R)Retry, (I)Ignore:");
n = sc.nextLine();
switch (n.toLowerCase()) {
case "a":
return AbortRetryIgnoreHandler.ABORT;
case "r":
return AbortRetryIgnoreHandler.RETRY;
case "i":
return AbortRetryIgnoreHandler.IGNORE;
}
} while (true);
}
};
String exportFormat = args[pos + 1].toLowerCase();
if (!Arrays.asList(validExportFormats).contains(exportFormat)) {
System.err.println("Invalid export format:" + exportFormat);
@@ -646,27 +670,27 @@ public class Main {
switch (exportFormat) {
case "all":
System.out.println("Exporting images...");
exfile.exportImages(outDir.getAbsolutePath() + File.separator + "images");
exfile.exportImages(handler, outDir.getAbsolutePath() + File.separator + "images");
System.out.println("Exporting shapes...");
exfile.exportShapes(outDir.getAbsolutePath() + File.separator + "shapes");
exfile.exportShapes(handler, outDir.getAbsolutePath() + File.separator + "shapes");
System.out.println("Exporting scripts...");
exfile.exportActionScript(outDir.getAbsolutePath() + File.separator + "scripts", false, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
exfile.exportActionScript(handler, outDir.getAbsolutePath() + File.separator + "scripts", false, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
System.out.println("Exporting movies...");
exfile.exportMovies(outDir.getAbsolutePath() + File.separator + "movies");
exfile.exportMovies(handler, outDir.getAbsolutePath() + File.separator + "movies");
System.out.println("Exporting sounds...");
exfile.exportSounds(outDir.getAbsolutePath() + File.separator + "sounds", true, true);
exfile.exportSounds(handler, outDir.getAbsolutePath() + File.separator + "sounds", true, true);
System.out.println("Exporting binaryData...");
exfile.exportBinaryData(outDir.getAbsolutePath() + File.separator + "binaryData");
exfile.exportBinaryData(handler, outDir.getAbsolutePath() + File.separator + "binaryData");
System.out.println("Exporting texts...");
exfile.exportTexts(outDir.getAbsolutePath() + File.separator + "texts", true);
exfile.exportTexts(handler, outDir.getAbsolutePath() + File.separator + "texts", true);
exportOK = true;
break;
case "image":
exfile.exportImages(outDir.getAbsolutePath());
exfile.exportImages(handler, outDir.getAbsolutePath());
exportOK = true;
break;
case "shape":
exfile.exportShapes(outDir.getAbsolutePath());
exfile.exportShapes(handler, outDir.getAbsolutePath());
exportOK = true;
break;
case "as":
@@ -677,35 +701,35 @@ public class Main {
exportOK = exportOK && exfile.exportAS3Class(args[i], outDir.getAbsolutePath(), exportFormat.equals("pcode"), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
}
} else {
exportOK = !exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode"), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)).isEmpty();
exportOK = !exfile.exportActionScript(handler, outDir.getAbsolutePath(), exportFormat.equals("pcode"), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)).isEmpty();
}
break;
case "movie":
exfile.exportMovies(outDir.getAbsolutePath());
exfile.exportMovies(handler, outDir.getAbsolutePath());
exportOK = true;
break;
case "sound":
exfile.exportSounds(outDir.getAbsolutePath(), true, true);
exfile.exportSounds(handler, outDir.getAbsolutePath(), true, true);
exportOK = true;
break;
case "binarydata":
exfile.exportBinaryData(outDir.getAbsolutePath());
exfile.exportBinaryData(handler, outDir.getAbsolutePath());
exportOK = true;
break;
case "text":
exfile.exportTexts(outDir.getAbsolutePath(), true);
exfile.exportTexts(handler, outDir.getAbsolutePath(), true);
exportOK = true;
break;
case "textplain":
exfile.exportTexts(outDir.getAbsolutePath(), false);
exfile.exportTexts(handler, outDir.getAbsolutePath(), false);
exportOK = true;
break;
case "fla":
exfile.exportFla(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
exfile.exportFla(handler, outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
exportOK = true;
break;
case "xfl":
exfile.exportXfl(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
exfile.exportXfl(handler, outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
exportOK = true;
break;
default:
@@ -1100,15 +1124,19 @@ public class Main {
if (!Platform.isWindows()) {
return false;
}
final String classesPath = "Software\\Classes\\";
if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, classesPath + ".swf")) {
try {
final String classesPath = "Software\\Classes\\";
if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, classesPath + ".swf")) {
return false;
}
String clsName = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, classesPath + ".swf", "");
if (clsName == null) {
return false;
}
return Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, classesPath + clsName + "\\shell\\ffdec");
} catch (Win32Exception ex) {
return false;
}
String clsName = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, classesPath + ".swf", "");
if (clsName == null) {
return false;
}
return Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, classesPath + clsName + "\\shell\\ffdec");
}
public static String getAppDir() {
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
import com.jpexs.decompiler.flash.Configuration;
import com.jpexs.decompiler.flash.FrameNode;
import com.jpexs.decompiler.flash.PackageNode;
@@ -240,6 +241,15 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
private JTextField fontAddCharactersField;
private JButton errorNotificationButton;
private ErrorLogFrame errorLogFrame;
private AbortRetryIgnoreHandler errorHandler = new AbortRetryIgnoreHandler() {
@Override
public int handle(Throwable thrown) {
synchronized (MainFrame.class) {
String options[] = new String[]{translate("button.abort"), translate("button.retry"), translate("button.ignore")};
return JOptionPane.showOptionDialog(null, translate("error.occured").replace("%error%", thrown.getLocalizedMessage()), translate("error"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, "");
}
}
};
public void setPercent(int percent) {
progressBar.setValue(percent);
@@ -633,7 +643,7 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
try {
File ftemp = new File(tempDir);
files = exportSelection(tempDir, export);
files = exportSelection(errorHandler, tempDir, export);
files.clear();
File fs[] = ftemp.listFiles();
@@ -1612,7 +1622,7 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
}
private SearchDialog searchDialog;
public List<File> exportSelection(String selFile, ExportDialog export) throws IOException {
public List<File> exportSelection(AbortRetryIgnoreHandler handler, String selFile, ExportDialog export) throws IOException {
final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1;
final boolean isMp3OrWav = export.getOption(ExportDialog.OPTION_SOUNDS) == 0;
final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1;
@@ -1666,12 +1676,12 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
}
}
}
ret.addAll(swf.exportImages(selFile + File.separator + "images", images));
ret.addAll(SWF.exportShapes(selFile + File.separator + "shapes", shapes));
ret.addAll(swf.exportTexts(selFile + File.separator + "texts", texts, isFormatted));
ret.addAll(swf.exportMovies(selFile + File.separator + "movies", movies));
ret.addAll(swf.exportSounds(selFile + File.separator + "sounds", sounds, isMp3OrWav, isMp3OrWav));
ret.addAll(swf.exportBinaryData(selFile + File.separator + "binaryData", binaryData));
ret.addAll(swf.exportImages(handler, selFile + File.separator + "images", images));
ret.addAll(SWF.exportShapes(handler, selFile + File.separator + "shapes", shapes));
ret.addAll(swf.exportTexts(handler, selFile + File.separator + "texts", texts, isFormatted));
ret.addAll(swf.exportMovies(handler, selFile + File.separator + "movies", movies));
ret.addAll(swf.exportSounds(handler, selFile + File.separator + "sounds", sounds, isMp3OrWav, isMp3OrWav));
ret.addAll(swf.exportBinaryData(handler, selFile + File.separator + "binaryData", binaryData));
if (abcPanel != null) {
for (int i = 0; i < tlsList.size(); i++) {
ScriptPack tls = tlsList.get(i);
@@ -1685,7 +1695,7 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
allNodes.add(asn);
TagNode.setExport(allNodes, false);
TagNode.setExport(actionNodes, true);
ret.addAll(TagNode.exportNodeAS(allNodes, selFile, isPcode));
ret.addAll(TagNode.exportNodeAS(handler, allNodes, selFile, isPcode));
}
}
return ret;
@@ -2071,9 +2081,9 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
public void run() {
try {
if (compressed) {
swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
swf.exportFla(errorHandler, 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));
swf.exportXfl(errorHandler, 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);
@@ -2107,19 +2117,19 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
public void run() {
try {
if (onlySel) {
exportSelection(selFile, export);
exportSelection(errorHandler, selFile, export);
} else {
swf.exportImages(selFile + File.separator + "images");
swf.exportShapes(selFile + File.separator + "shapes");
swf.exportTexts(selFile + File.separator + "texts", isFormatted);
swf.exportMovies(selFile + File.separator + "movies");
swf.exportSounds(selFile + File.separator + "sounds", isMp3OrWav, isMp3OrWav);
swf.exportBinaryData(selFile + File.separator + "binaryData");
swf.exportActionScript(selFile, isPcode, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
swf.exportImages(errorHandler, selFile + File.separator + "images");
swf.exportShapes(errorHandler, selFile + File.separator + "shapes");
swf.exportTexts(errorHandler, selFile + File.separator + "texts", isFormatted);
swf.exportMovies(errorHandler, selFile + File.separator + "movies");
swf.exportSounds(errorHandler, selFile + File.separator + "sounds", isMp3OrWav, isMp3OrWav);
swf.exportBinaryData(errorHandler, selFile + File.separator + "binaryData");
swf.exportActionScript(errorHandler, selFile, isPcode, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE));
}
} catch (Exception ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Error during export", ex);
JOptionPane.showMessageDialog(null, translate("error.export"));
JOptionPane.showMessageDialog(null, translate("error.export") + ": " + ex.getLocalizedMessage());
}
Main.stopWork();
long timeAfter = System.currentTimeMillis();
@@ -316,4 +316,10 @@ FileChooser.viewMenuLabelText = View
FileChooser.fileSizeKiloBytes = {0} KB
FileChooser.fileSizeMegaBytes = {0} MB
FileChooser.fileSizeGigaBytes = {0} GB
FileChooser.folderNameLabelText = Folder name:
FileChooser.folderNameLabelText = Folder name:
error.occured = Error occured : %error%
button.abort = Abort
button.retry = Retry
button.ignore = Ignore
@@ -315,4 +315,9 @@ FileChooser.viewMenuLabelText = Zobrazit
FileChooser.fileSizeKiloBytes = {0} KB
FileChooser.fileSizeMegaBytes = {0} MB
FileChooser.fileSizeGigaBytes = {0} GB
FileChooser.folderNameLabelText = N\u00e1zev slo\u017eky:
FileChooser.folderNameLabelText = N\u00e1zev slo\u017eky:
error.occured = Error occured : %error%
button.abort = P\u0159eru\u0161it
button.retry = Znovu
button.ignore = Ignorovat