SWFs in zip based bundles can be modified & saved

This commit is contained in:
Jindra Petřík
2015-03-07 07:39:44 +01:00
parent 796c9bf3ae
commit 99ec0a592c
17 changed files with 205 additions and 77 deletions
+6 -4
View File
@@ -319,8 +319,9 @@ public class Main {
Stopwatch sw = Stopwatch.startNew();
if (bundle != null) {
result.isBundle = true;
result.bundleClass = bundle.getClass();
//result.isBundle = true;
//result.bundleClass = bundle.getClass();
result.bundle = bundle;
result.name = new File(sourceInfo.getFileTitleOrName()).getName();
for (Entry<String, SeekableInputStream> streamEntry : bundle.getAll().entrySet()) {
InputStream stream = streamEntry.getValue();
@@ -331,6 +332,7 @@ public class Main {
startWork(AppStrings.translate("work.reading.swf"), p);
}
}, Configuration.parallelSpeedUp.get());
swf.bundle = bundle;
result.add(swf);
}
} else {
@@ -409,7 +411,7 @@ public class Main {
}
public static void saveFile(SWF swf, String outfile, SaveFileMode mode) throws IOException {
if (mode == SaveFileMode.SAVEAS && !swf.swfList.isBundle) {
if (mode == SaveFileMode.SAVEAS && swf.swfList.bundle==null) {
swf.setFile(outfile);
swf.swfList.sourceInfo.setFile(outfile);
}
@@ -503,7 +505,7 @@ public class Main {
loadingDialog.setVisible(false);
shouldCloseWhenClosingLoadingDialog = false;
final SWF fswf = firstSWF;
final SWF fswf = firstSWF;
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.console.ContextMenuTools;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.helpers.CheckResources;
import com.jpexs.helpers.ByteArrayRange;
@@ -29,6 +30,7 @@ import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.ScrollPane;
import java.awt.event.KeyEvent;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@@ -48,6 +50,7 @@ public abstract class MainFrameMenu {
private final MainFrame mainFrame;
private SWF swf;
private SWFBundle bundle;
public abstract boolean isInternalFlashViewerSelected();
@@ -66,9 +69,20 @@ public abstract class MainFrameMenu {
}
protected boolean save() {
if (swf != null) {
if (swf != null) {
boolean saved = false;
if (swf.binaryData != null) {
if(swf.bundle!=null){
if(!swf.bundle.isReadOnly()){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
swf.saveTo(baos);
saved = swf.bundle.putSWF(swf.getFileTitle(), new ByteArrayInputStream(baos.toByteArray()));
} catch (IOException ex) {
Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex);
}
}
}
else if (swf.binaryData != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
swf.saveTo(baos);
@@ -101,7 +115,7 @@ public abstract class MainFrameMenu {
protected boolean saveAs() {
if (swf != null) {
if (saveAs(swf, SaveFileMode.SAVEAS)) {
if (saveAs(swf,SaveFileMode.SAVEAS)) {
swf.clearModified();
}
@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.console.ContextMenuTools;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
@@ -728,8 +729,8 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener
closeFileMenu.setEnabled(swfLoaded);
closeAllFilesMenu.setEnabled(swfLoaded);
boolean isBundle = swfLoaded && (swf.swfList != null) && swf.swfList.isBundle;
saveCommandButton.setEnabled(swfLoaded && !isBundle);
boolean isBundle = swfLoaded && (swf.swfList != null) && (swf.swfList.bundle != null);
saveCommandButton.setEnabled(swfLoaded && ((!isBundle) || (!swf.swfList.bundle.isReadOnly())));
saveasCommandButton.setEnabled(swfLoaded);
saveasexeCommandButton.setEnabled(swfLoaded);
exportAllCommandButton.setEnabled(swfLoaded);
@@ -2232,7 +2232,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
TreeItem treeItem = (TreeItem) e.getPath().getLastPathComponent();
if (!(treeItem instanceof SWFList)) {
SWF swf = treeItem.getSwf();
SWF swf = treeItem.getSwf();
if (swfs.isEmpty()) {
// show welcome panel after closing swfs
updateUi();
@@ -313,10 +313,10 @@ public class TagTree extends JTree {
if (t instanceof SWFList) {
SWFList slist = (SWFList) t;
if (slist.bundleClass != null) {
if (slist.bundleClass == ZippedSWFBundle.class) {
if (slist.bundle != null) {
if (slist.bundle.getClass() == ZippedSWFBundle.class) {
return TreeNodeType.BUNDLE_ZIP;
} else if (slist.bundleClass == SWC.class) {
} else if (slist.bundle.getClass() == SWC.class) {
return TreeNodeType.BUNDLE_SWC;
} else {
return TreeNodeType.BUNDLE_BINARY;
@@ -275,7 +275,7 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener {
} else if (item instanceof SWF) {
SWF swf = (SWF) item;
// Do not allow to close SWF in bundle
if (swf.swfList != null && swf.swfList.isBundle) {
if (swf.swfList != null && swf.swfList.bundle!=null) {
allSelectedIsSwf = false;
}
}
@@ -95,7 +95,7 @@ public class TagTreeModel implements TreeModel {
this.tagScriptCache = new HashMap<>();
Main.startWork(AppStrings.translate("work.buildingscripttree") + "...");
for (SWFList swfList : swfs) {
if (swfList.isBundle) {
if (swfList.bundle != null) {
this.swfs.add(swfList);
for (SWF swf : swfList) {
createTagList(swf);