Added Show imported files on script import, able to cancel import

This commit is contained in:
Jindra Petřík
2021-12-05 18:30:17 +01:00
parent e9cc551c37
commit 05e8f68ea9
12 changed files with 168 additions and 61 deletions
@@ -196,6 +196,8 @@ public class Main {
public static SearchResultsStorage searchResultsStorage = new SearchResultsStorage();
public static CancellableWorker importWorker = null;
//This method makes file watcher to shut up during our own file saving
public static void startSaving(File savedFile) {
savedFiles.add(savedFile);
@@ -1046,6 +1048,9 @@ public class Main {
if (event.equals("rename")) {
startWork(AppStrings.translate("work.renaming") + "..." + (String) data, null);
}
if (event.equals("importing_as")) {
startWork(AppStrings.translate("work.importing_as") + "..." + (String) data, importWorker);
}
}
});
}
@@ -101,6 +101,7 @@ import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
import com.jpexs.decompiler.flash.importers.BinaryDataImporter;
import com.jpexs.decompiler.flash.importers.FFDecAs3ScriptReplacer;
import com.jpexs.decompiler.flash.importers.ImageImporter;
import com.jpexs.decompiler.flash.importers.ScriptImporterProgressListener;
import com.jpexs.decompiler.flash.importers.ShapeImporter;
import com.jpexs.decompiler.flash.importers.SwfXmlImporter;
import com.jpexs.decompiler.flash.importers.SymbolClassImporter;
@@ -2500,18 +2501,56 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath();
String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME);
final long timeBefore = System.currentTimeMillis();
new CancellableWorker<Void>() {
private int countAs2 = 0;
private int countAs3 = 0;
@Override
public Void doInBackground() throws Exception {
new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true), new ScriptImporterProgressListener() {
@Override
public void scriptImported() {
countAs2++;
}
});
new AS3ScriptImporter().importScripts(as3ScriptReplacer, scriptsFolder, swf.getAS3Packs(), new ScriptImporterProgressListener() {
@Override
public void scriptImported() {
countAs3++;
}
}
);
int countAs2 = new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true));
int countAs3 = new AS3ScriptImporter().importScripts(as3ScriptReplacer, scriptsFolder, swf.getAS3Packs());
if (countAs3 > 0) {
updateClassesList();
}
return null;
}
if (countAs3 > 0) {
updateClassesList();
}
@Override
protected void onStart() {
Main.importWorker = this;
Main.startWork(translate("work.importing_as") + "...", this);
}
@Override
protected void done() {
Main.stopWork();
long timeAfter = System.currentTimeMillis();
final long timeMs = timeAfter - timeBefore;
Main.importWorker = null;
View.execInEventDispatch(() -> {
setStatus(translate("importing_as.finishedin").replace("%time%", Helper.formatTimeSec(timeMs)));
ViewMessages.showMessageDialog(MainPanel.this, translate("import.script.result").replace("%count%", Integer.toString(countAs2 + countAs3)));
if (countAs2 != 0 || countAs3 != 0) {
reload(true);
}
});
}
}.execute();
ViewMessages.showMessageDialog(this, translate("import.script.result").replace("%count%", Integer.toString(countAs2 + countAs3)));
if (countAs2 != 0 || countAs3 != 0) {
reload(true);
}
}
}
@@ -848,4 +848,7 @@ message.info.importXml = For XML importing, you need a XML file in special forma
tagInfo.dependentFrames = Dependent Frames
imagePanel.depth = depth:
imagePanel.depth = depth:
work.importing_as = Importing script
importing_as.finishedin = Imported in %time%