prepare for dumpview

This commit is contained in:
honfika
2014-06-18 20:48:08 +02:00
parent d4cd0eb844
commit fb21f408cd
123 changed files with 15359 additions and 15197 deletions
@@ -500,11 +500,13 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE);
}
}
swf.clearModified();
}
break;
case ACTION_SAVE_AS: {
SWF swf = mainFrame.panel.getCurrentSwf();
saveAs(swf, SaveFileMode.SAVEAS);
swf.clearModified();
}
break;
case ACTION_SAVE_AS_EXE: {
@@ -539,15 +539,6 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
}
}
private void clearModified(SWF swf) {
for (Tag tag : swf.tags) {
if (tag.isModified()) {
tag.createOriginalData();
tag.setModified(false);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
@@ -689,13 +680,13 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE);
}
}
clearModified(swf);
swf.clearModified();
}
break;
case ACTION_SAVE_AS: {
SWF swf = mainFrame.panel.getCurrentSwf();
saveAs(swf, SaveFileMode.SAVEAS);
clearModified(swf);
swf.clearModified();
}
break;
case ACTION_SAVE_AS_EXE: {
@@ -2222,7 +2222,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
try {
SWF swf = it.getSwf();
if (it instanceof DefineBitsTag) {
DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, it.getOriginalHeaderData(), it.getOriginalData(), it.getPos(), it.getCharacterId(), data);
DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, it.getPos(), it.getOriginalLength(), it.getCharacterId(), data);
jpeg2Tag.setModified(true);
swf.tags.set(swf.tags.indexOf(it), jpeg2Tag);
swf.updateCharacters();
@@ -515,7 +515,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
byte[] data;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
SWFOutputStream sos2 = new SWFOutputStream(baos, 10);
SWFOutputStream sos2 = new SWFOutputStream(baos, SWF.DEFAULT_VERSION);
int width = swf.displayRect.Xmax - swf.displayRect.Xmin;
int height = swf.displayRect.Ymax - swf.displayRect.Ymin;
sos2.writeRECT(swf.displayRect);
@@ -684,7 +684,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
List<Action> actions;
DoActionTag doa;
doa = new DoActionTag(swf, new byte[0], new byte[0], 0);
doa = new DoActionTag(swf, 0, 0);
actions = ASMParser.parse(0, 0, false,
"ConstantPool \"_root\" \"my_sound\" \"Sound\" \"my_define_sound\" \"attachSound\"\n"
+ "Push \"_root\"\n"
@@ -1,211 +1,210 @@
/*
* Copyright (C) 2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.gui.player.MediaDisplay;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.helpers.SoundPlayer;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
*
* @author JPEXS
*/
public class SoundTagPlayer implements MediaDisplay {
private final SoundPlayer player;
private Thread thr;
private int actualPos = 0;
private final SoundTag tag;
private final List<PlayerListener> listeners = new ArrayList<>();
public void addListener(PlayerListener l) {
listeners.add(l);
}
public void removeListener(PlayerListener l) {
listeners.remove(l);
}
public void fireFinished() {
for (PlayerListener l : listeners) {
l.playingFinished();
}
}
private static final int FRAME_DIVISOR = 8000;
private int loops;
private boolean paused = true;
private final Object playLock = new Object();
public SoundTagPlayer(SoundTag tag, int loops) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
this.tag = tag;
this.loops = loops;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(tag.getRawSoundData());
tag.getSoundFormat().createWav(bais, baos);
player = new SoundPlayer(new ByteArrayInputStream(baos.toByteArray()));
}
@Override
public synchronized int getCurrentFrame() {
synchronized (playLock) {
if (isPlaying()) {
actualPos = (int) (player.getSamplePosition() / FRAME_DIVISOR);
}
return actualPos;
}
}
@Override
public synchronized int getTotalFrames() {
int ret = (int) (player.samplesCount() / FRAME_DIVISOR);
return ret;
}
@Override
public synchronized void pause() {
if (!isPlaying()) {
paused = true;
return;
}
synchronized (playLock) {
actualPos = (int) (player.getSamplePosition() / FRAME_DIVISOR);
}
waitStop();
}
private void waitStop() {
synchronized (playLock) {
if (!paused) {
paused = true;
player.stop();
try {
playLock.wait();
} catch (InterruptedException ex) {
Logger.getLogger(SoundTagPlayer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void play(boolean async) {
waitStop();
Runnable r = new Runnable() {
@Override
public void run() {
boolean playAgain = true;
while (playAgain) {
int startPos = 0;
synchronized (playLock) {
startPos = actualPos * FRAME_DIVISOR;
}
player.setPosition(startPos);
player.play();
synchronized (playLock) {
playAgain = !paused && loops > 0;
if (!paused) {
if (loops == 0) {
paused = true;
} else if (loops != Integer.MAX_VALUE) {
loops--;
}
}
if (playAgain) {
actualPos = 0;
}
}
}
fireFinished();
synchronized (playLock) {
playLock.notifyAll();
}
}
};
synchronized (playLock) {
paused = false;
}
if (async) {
thr = new Thread(r);
thr.start();
} else {
r.run();
}
}
@Override
public synchronized void play() {
play(true);
}
@Override
public void rewind() {
gotoFrame(0);
}
@Override
public boolean isPlaying() {
return player.isPlaying();
}
@Override
public synchronized void gotoFrame(int frame) {
pause();
synchronized (playLock) {
actualPos = frame;
}
}
@Override
public void setBackground(Color color) {
}
@Override
public int getFrameRate() {
if (player == null) {
return 1;
}
return (int) (player.getFrameRate() / FRAME_DIVISOR);
}
@Override
public boolean isLoaded() {
return true;
}
}
/*
* Copyright (C) 2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.gui.player.MediaDisplay;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.helpers.SoundPlayer;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
*
* @author JPEXS
*/
public class SoundTagPlayer implements MediaDisplay {
private final SoundPlayer player;
private Thread thr;
private int actualPos = 0;
private final SoundTag tag;
private final List<PlayerListener> listeners = new ArrayList<>();
public void addListener(PlayerListener l) {
listeners.add(l);
}
public void removeListener(PlayerListener l) {
listeners.remove(l);
}
public void fireFinished() {
for (PlayerListener l : listeners) {
l.playingFinished();
}
}
private static final int FRAME_DIVISOR = 8000;
private int loops;
private boolean paused = true;
private final Object playLock = new Object();
public SoundTagPlayer(SoundTag tag, int loops) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
this.tag = tag;
this.loops = loops;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tag.getSoundFormat().createWav(tag.getRawSoundData(), baos);
player = new SoundPlayer(new ByteArrayInputStream(baos.toByteArray()));
}
@Override
public synchronized int getCurrentFrame() {
synchronized (playLock) {
if (isPlaying()) {
actualPos = (int) (player.getSamplePosition() / FRAME_DIVISOR);
}
return actualPos;
}
}
@Override
public synchronized int getTotalFrames() {
int ret = (int) (player.samplesCount() / FRAME_DIVISOR);
return ret;
}
@Override
public synchronized void pause() {
if (!isPlaying()) {
paused = true;
return;
}
synchronized (playLock) {
actualPos = (int) (player.getSamplePosition() / FRAME_DIVISOR);
}
waitStop();
}
private void waitStop() {
synchronized (playLock) {
if (!paused) {
paused = true;
player.stop();
try {
playLock.wait();
} catch (InterruptedException ex) {
Logger.getLogger(SoundTagPlayer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void play(boolean async) {
waitStop();
Runnable r = new Runnable() {
@Override
public void run() {
boolean playAgain = true;
while (playAgain) {
int startPos = 0;
synchronized (playLock) {
startPos = actualPos * FRAME_DIVISOR;
}
player.setPosition(startPos);
player.play();
synchronized (playLock) {
playAgain = !paused && loops > 0;
if (!paused) {
if (loops == 0) {
paused = true;
} else if (loops != Integer.MAX_VALUE) {
loops--;
}
}
if (playAgain) {
actualPos = 0;
}
}
}
fireFinished();
synchronized (playLock) {
playLock.notifyAll();
}
}
};
synchronized (playLock) {
paused = false;
}
if (async) {
thr = new Thread(r);
thr.start();
} else {
r.run();
}
}
@Override
public synchronized void play() {
play(true);
}
@Override
public void rewind() {
gotoFrame(0);
}
@Override
public boolean isPlaying() {
return player.isPlaying();
}
@Override
public synchronized void gotoFrame(int frame) {
pause();
synchronized (playLock) {
actualPos = frame;
}
}
@Override
public void setBackground(Color color) {
}
@Override
public int getFrameRate() {
if (player == null) {
return 1;
}
return (int) (player.getFrameRate() / FRAME_DIVISOR);
}
@Override
public boolean isLoaded() {
return true;
}
}