mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-08 20:08:06 +00:00
Wrtie log message when can't initialize flash panel
This commit is contained in:
@@ -1,182 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
||||
import com.jpexs.decompiler.flash.abc.types.ConvertData;
|
||||
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
|
||||
import com.jpexs.decompiler.flash.action.ActionList;
|
||||
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.helpers.ImmediateFuture;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DecompilerPool {
|
||||
|
||||
private final ThreadPoolExecutor executor;
|
||||
|
||||
public DecompilerPool() {
|
||||
int threadCount = Configuration.getParallelThreadCount();
|
||||
executor = new ThreadPoolExecutor(threadCount, threadCount,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>());
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ASMSource src, ActionList actions, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
writer.startFunction("!script");
|
||||
src.getActionScriptSource(writer, actions);
|
||||
writer.endFunction();
|
||||
|
||||
HighlightedText result = new HighlightedText(writer);
|
||||
SWF swf = src.getSwf();
|
||||
if (swf != null) {
|
||||
swf.as2Cache.put(src, result);
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onComplete(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ScriptPack pack, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
int scriptIndex = pack.scriptIndex;
|
||||
ScriptInfo script = null;
|
||||
if (scriptIndex > -1) {
|
||||
script = pack.abc.script_info.get(scriptIndex);
|
||||
}
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
pack.toSource(writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel);
|
||||
|
||||
HighlightedText result = new HighlightedText(writer);
|
||||
SWF swf = pack.getSwf();
|
||||
if (swf != null) {
|
||||
swf.as3Cache.put(pack, result);
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onComplete(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
private Future<HighlightedText> submit(Callable<HighlightedText> callable) {
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
if (parallel) {
|
||||
Future<HighlightedText> f = executor.submit(callable);
|
||||
return f;
|
||||
} else {
|
||||
boolean cancelled = false;
|
||||
Throwable throwable = null;
|
||||
HighlightedText result = null;
|
||||
try {
|
||||
result = callable.call();
|
||||
} catch (InterruptedException ex) {
|
||||
cancelled = true;
|
||||
} catch (Exception ex) {
|
||||
throwable = ex;
|
||||
}
|
||||
|
||||
return new ImmediateFuture<>(result, throwable, cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStat() {
|
||||
return "core: " + executor.getCorePoolSize()
|
||||
+ " size: " + executor.getPoolSize()
|
||||
+ " largest: " + executor.getLargestPoolSize()
|
||||
+ " max: " + executor.getMaximumPoolSize()
|
||||
+ " active: " + executor.getActiveCount()
|
||||
+ " count: " + executor.getTaskCount()
|
||||
+ " completed: " + executor.getCompletedTaskCount();
|
||||
}
|
||||
|
||||
public HighlightedText decompile(ASMSource src, ActionList actions) throws InterruptedException {
|
||||
Future<HighlightedText> future = submitTask(src, actions, null);
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException ex) {
|
||||
future.cancel(true);
|
||||
throw ex;
|
||||
} catch (ExecutionException ex) {
|
||||
Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public HighlightedText decompile(ScriptPack pack) throws InterruptedException {
|
||||
Future<HighlightedText> future = submitTask(pack, null);
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException ex) {
|
||||
future.cancel(true);
|
||||
throw ex;
|
||||
} catch (ExecutionException ex) {
|
||||
Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void shutdown() throws InterruptedException {
|
||||
executor.shutdown();
|
||||
if (!executor.awaitTermination(100, TimeUnit.SECONDS)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
||||
import com.jpexs.decompiler.flash.abc.types.ConvertData;
|
||||
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
|
||||
import com.jpexs.decompiler.flash.action.ActionList;
|
||||
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.helpers.ImmediateFuture;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DecompilerPool {
|
||||
|
||||
private final ThreadPoolExecutor executor;
|
||||
|
||||
public DecompilerPool() {
|
||||
int threadCount = Configuration.getParallelThreadCount();
|
||||
executor = new ThreadPoolExecutor(threadCount, threadCount,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>());
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ASMSource src, ActionList actions, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
writer.startFunction("!script");
|
||||
src.getActionScriptSource(writer, actions);
|
||||
writer.endFunction();
|
||||
|
||||
HighlightedText result = new HighlightedText(writer);
|
||||
SWF swf = src.getSwf();
|
||||
if (swf != null) {
|
||||
swf.as2Cache.put(src, result);
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onComplete(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ScriptPack pack, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
int scriptIndex = pack.scriptIndex;
|
||||
ScriptInfo script = null;
|
||||
if (scriptIndex > -1) {
|
||||
script = pack.abc.script_info.get(scriptIndex);
|
||||
}
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
pack.toSource(writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel);
|
||||
|
||||
HighlightedText result = new HighlightedText(writer);
|
||||
SWF swf = pack.getSwf();
|
||||
if (swf != null) {
|
||||
swf.as3Cache.put(pack, result);
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onComplete(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
private Future<HighlightedText> submit(Callable<HighlightedText> callable) {
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
if (parallel) {
|
||||
Future<HighlightedText> f = executor.submit(callable);
|
||||
return f;
|
||||
} else {
|
||||
boolean cancelled = false;
|
||||
Throwable throwable = null;
|
||||
HighlightedText result = null;
|
||||
try {
|
||||
result = callable.call();
|
||||
} catch (InterruptedException ex) {
|
||||
cancelled = true;
|
||||
} catch (Exception ex) {
|
||||
throwable = ex;
|
||||
}
|
||||
|
||||
return new ImmediateFuture<>(result, throwable, cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStat() {
|
||||
return "core: " + executor.getCorePoolSize()
|
||||
+ " size: " + executor.getPoolSize()
|
||||
+ " largest: " + executor.getLargestPoolSize()
|
||||
+ " max: " + executor.getMaximumPoolSize()
|
||||
+ " active: " + executor.getActiveCount()
|
||||
+ " count: " + executor.getTaskCount()
|
||||
+ " completed: " + executor.getCompletedTaskCount();
|
||||
}
|
||||
|
||||
public HighlightedText decompile(ASMSource src, ActionList actions) throws InterruptedException {
|
||||
Future<HighlightedText> future = submitTask(src, actions, null);
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException ex) {
|
||||
future.cancel(true);
|
||||
throw ex;
|
||||
} catch (ExecutionException ex) {
|
||||
Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public HighlightedText decompile(ScriptPack pack) throws InterruptedException {
|
||||
Future<HighlightedText> future = submitTask(pack, null);
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException ex) {
|
||||
future.cancel(true);
|
||||
throw ex;
|
||||
} catch (ExecutionException ex) {
|
||||
Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void shutdown() throws InterruptedException {
|
||||
executor.shutdown();
|
||||
if (!executor.awaitTermination(100, TimeUnit.SECONDS)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2016 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.abc;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.types.ConvertData;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitType;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.search.ABCSearchResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class TraitsListItem {
|
||||
|
||||
private final TraitType type;
|
||||
|
||||
private final boolean isStatic;
|
||||
|
||||
private final ABC abc;
|
||||
|
||||
private final int classIndex;
|
||||
|
||||
private final int index;
|
||||
|
||||
private final int scriptIndex;
|
||||
|
||||
public static String STR_INSTANCE_INITIALIZER = ABCSearchResult.STR_INSTANCE_INITIALIZER;
|
||||
|
||||
public static String STR_CLASS_INITIALIZER = ABCSearchResult.STR_CLASS_INITIALIZER;
|
||||
|
||||
public static String STR_SCRIPT_INITIALIZER = ABCSearchResult.STR_SCRIPT_INITIALIZER;
|
||||
|
||||
public TraitsListItem(TraitType type, int index, boolean isStatic, ABC abc, int classIndex, int scriptIndex) {
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.isStatic = isStatic;
|
||||
this.abc = abc;
|
||||
this.classIndex = classIndex;
|
||||
this.scriptIndex = scriptIndex;
|
||||
}
|
||||
|
||||
public int getGlobalTraitId() {
|
||||
return abc.getGlobalTraitId(type, isStatic, classIndex, index);
|
||||
}
|
||||
|
||||
public String toStringName() {
|
||||
|
||||
if (type == TraitType.INITIALIZER) {
|
||||
if (!isStatic) {
|
||||
return "__" + STR_INSTANCE_INITIALIZER;
|
||||
} else {
|
||||
return "__" + STR_CLASS_INITIALIZER;
|
||||
}
|
||||
}
|
||||
if (type == TraitType.SCRIPT_INITIALIZER) {
|
||||
return "__" + STR_SCRIPT_INITIALIZER;
|
||||
}
|
||||
if (isStatic) {
|
||||
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
|
||||
} else {
|
||||
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
try {
|
||||
if (type == TraitType.SCRIPT_INITIALIZER) {
|
||||
s = STR_SCRIPT_INITIALIZER;
|
||||
} else if (type == TraitType.INITIALIZER) {
|
||||
if (!isStatic) {
|
||||
s = STR_INSTANCE_INITIALIZER;
|
||||
} else {
|
||||
s = STR_CLASS_INITIALIZER;
|
||||
}
|
||||
} else if (isStatic) {
|
||||
ConvertData convertData = new ConvertData();
|
||||
Trait trait = abc.class_info.get(classIndex).static_traits.traits.get(index);
|
||||
trait.convertHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
trait.toStringHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
|
||||
s = writer.toString();
|
||||
} else {
|
||||
ConvertData convertData = new ConvertData();
|
||||
Trait trait = abc.instance_info.get(classIndex).instance_traits.traits.get(index);
|
||||
trait.convertHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
trait.toStringHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
|
||||
s = writer.toString();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
s = s.replaceAll("[ \r\n]+", " ");
|
||||
return s;
|
||||
}
|
||||
|
||||
public TraitType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
public int getClassIndex() {
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2016 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.abc;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.types.ConvertData;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitType;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.search.ABCSearchResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class TraitsListItem {
|
||||
|
||||
private final TraitType type;
|
||||
|
||||
private final boolean isStatic;
|
||||
|
||||
private final ABC abc;
|
||||
|
||||
private final int classIndex;
|
||||
|
||||
private final int index;
|
||||
|
||||
private final int scriptIndex;
|
||||
|
||||
public static String STR_INSTANCE_INITIALIZER = ABCSearchResult.STR_INSTANCE_INITIALIZER;
|
||||
|
||||
public static String STR_CLASS_INITIALIZER = ABCSearchResult.STR_CLASS_INITIALIZER;
|
||||
|
||||
public static String STR_SCRIPT_INITIALIZER = ABCSearchResult.STR_SCRIPT_INITIALIZER;
|
||||
|
||||
public TraitsListItem(TraitType type, int index, boolean isStatic, ABC abc, int classIndex, int scriptIndex) {
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.isStatic = isStatic;
|
||||
this.abc = abc;
|
||||
this.classIndex = classIndex;
|
||||
this.scriptIndex = scriptIndex;
|
||||
}
|
||||
|
||||
public int getGlobalTraitId() {
|
||||
return abc.getGlobalTraitId(type, isStatic, classIndex, index);
|
||||
}
|
||||
|
||||
public String toStringName() {
|
||||
|
||||
if (type == TraitType.INITIALIZER) {
|
||||
if (!isStatic) {
|
||||
return "__" + STR_INSTANCE_INITIALIZER;
|
||||
} else {
|
||||
return "__" + STR_CLASS_INITIALIZER;
|
||||
}
|
||||
}
|
||||
if (type == TraitType.SCRIPT_INITIALIZER) {
|
||||
return "__" + STR_SCRIPT_INITIALIZER;
|
||||
}
|
||||
if (isStatic) {
|
||||
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
|
||||
} else {
|
||||
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
try {
|
||||
if (type == TraitType.SCRIPT_INITIALIZER) {
|
||||
s = STR_SCRIPT_INITIALIZER;
|
||||
} else if (type == TraitType.INITIALIZER) {
|
||||
if (!isStatic) {
|
||||
s = STR_INSTANCE_INITIALIZER;
|
||||
} else {
|
||||
s = STR_CLASS_INITIALIZER;
|
||||
}
|
||||
} else if (isStatic) {
|
||||
ConvertData convertData = new ConvertData();
|
||||
Trait trait = abc.class_info.get(classIndex).static_traits.traits.get(index);
|
||||
trait.convertHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
trait.toStringHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
|
||||
s = writer.toString();
|
||||
} else {
|
||||
ConvertData convertData = new ConvertData();
|
||||
Trait trait = abc.instance_info.get(classIndex).instance_traits.traits.get(index);
|
||||
trait.convertHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
|
||||
trait.toStringHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
|
||||
s = writer.toString();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
s = s.replaceAll("[ \r\n]+", " ");
|
||||
return s;
|
||||
}
|
||||
|
||||
public TraitType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
public int getClassIndex() {
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,433 +1,438 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2016 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.player;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.gui.FlashUnsupportedException;
|
||||
import com.jpexs.decompiler.flash.gui.Main;
|
||||
import com.jpexs.helpers.CancellableWorker;
|
||||
import com.jpexs.javactivex.ActiveX;
|
||||
import com.jpexs.javactivex.ActiveXEvent;
|
||||
import com.jpexs.javactivex.ActiveXException;
|
||||
import com.jpexs.javactivex.example.controls.flash.ShockwaveFlash;
|
||||
import com.sun.jna.Platform;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public final class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
|
||||
|
||||
private final int setMovieDelay = Configuration.setMovieDelay.get();
|
||||
|
||||
private final List<MediaDisplayListener> listeners = new ArrayList<>();
|
||||
|
||||
private final ShockwaveFlash flash;
|
||||
|
||||
private final Timer timer;
|
||||
|
||||
private boolean stopped = true;
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private float frameRate;
|
||||
|
||||
@Override
|
||||
public boolean loopAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean screenAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoomAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZoomToFit() {
|
||||
//TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zoom getZoom() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private double zoom = 1.0;
|
||||
|
||||
@Override
|
||||
public synchronized void zoom(Zoom zoom) {
|
||||
double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value;
|
||||
int zoomint = (int) Math.round(100 / (zoomDouble / this.zoom));
|
||||
if (zoomint == 0) {
|
||||
zoomint = 1;
|
||||
}
|
||||
if (zoomint > 32767) {
|
||||
zoomint = 32767;
|
||||
}
|
||||
if (zoomint == 100) {
|
||||
zoomint = 0;
|
||||
}
|
||||
|
||||
flash.Zoom(0); // hack, but this call is needed otherwise unzoom will fail for larger zoom values
|
||||
flash.Zoom(zoomint);
|
||||
}
|
||||
|
||||
public synchronized String getVariable(String name) throws IOException {
|
||||
return flash.GetVariable(name);
|
||||
}
|
||||
|
||||
public synchronized void setVariable(String name, String value) throws IOException {
|
||||
flash.SetVariable(name, value);
|
||||
}
|
||||
|
||||
public synchronized String call(String callString) throws IOException {
|
||||
|
||||
return flash.CallFunction(callString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getCurrentFrame() {
|
||||
if (flash == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return flash.getFrameNum();
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getTotalFrames() {
|
||||
if (flash == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
if (flash.getReadyState() == 4) {
|
||||
return flash.getTotalFrames();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setBackground(Color color) {
|
||||
try {
|
||||
flash.setBackgroundColor((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
public FlashPlayerPanel(Component frame) {
|
||||
if (!Platform.isWindows()) {
|
||||
throw new FlashUnsupportedException();
|
||||
}
|
||||
|
||||
try {
|
||||
Callable<ShockwaveFlash> callable = new Callable<ShockwaveFlash>() {
|
||||
@Override
|
||||
public ShockwaveFlash call() throws InterruptedException {
|
||||
return ActiveX.createObject(ShockwaveFlash.class, FlashPlayerPanel.this);
|
||||
}
|
||||
};
|
||||
|
||||
// hack: Kernel32.INSTANCE.ConnectNamedPipe never completes in ActiveXControl static constructor
|
||||
flash = CancellableWorker.call(callable, 5, TimeUnit.SECONDS);
|
||||
} catch (ActiveXException | TimeoutException | InterruptedException | ExecutionException ex) {
|
||||
throw new FlashUnsupportedException();
|
||||
}
|
||||
|
||||
flash.setAllowScriptAccess("always");
|
||||
try {
|
||||
flash.setAllowNetworking("all");
|
||||
} catch (ActiveXException ex) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
flash.addOnReadyStateChangeListener((ActiveXEvent axe) -> {
|
||||
fireMediaDisplayStateChanged();
|
||||
});
|
||||
|
||||
flash.addFlashCallListener((ActiveXEvent axe) -> {
|
||||
String req = (String) axe.args.get("request");
|
||||
Matcher m = Pattern.compile("<invoke name=\"([^\"]+)\" returntype=\"xml\"><arguments><string>(.*)</string></arguments></invoke>").matcher(req);
|
||||
if (m.matches()) {
|
||||
String funname = m.group(1);
|
||||
String msg = m.group(2);
|
||||
if (funname.equals("alert") || funname.equals("console.log")) {
|
||||
if (Main.debugDialog != null) {
|
||||
Main.debugDialog.log(funname + ":" + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
private boolean isPlaying = false;
|
||||
|
||||
private int currentFrame = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ShockwaveFlash flash1 = flash;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
if (flash1.getReadyState() >= 3) {
|
||||
boolean isPlaying = flash1.IsPlaying();
|
||||
if (this.isPlaying != isPlaying) {
|
||||
this.isPlaying = isPlaying;
|
||||
}
|
||||
|
||||
int currentFrame = flash1.CurrentFrame();
|
||||
if (this.currentFrame != currentFrame) {
|
||||
this.currentFrame = currentFrame;
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
this.isPlaying = false;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 100, 100);
|
||||
}
|
||||
|
||||
public synchronized void stopSWF() {
|
||||
displaySWF("-", null, 1);
|
||||
stopped = true;
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
|
||||
public synchronized boolean isStopped() {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage printScreen() {
|
||||
Point screenloc = getLocationOnScreen();
|
||||
try {
|
||||
return new Robot().createScreenCapture(new Rectangle(screenloc.x, screenloc.y, getWidth(), getHeight()));
|
||||
} catch (AWTException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String movieToPlay = null;
|
||||
|
||||
private Thread playQueue;
|
||||
|
||||
private final Object queueLock = new Object();
|
||||
|
||||
public synchronized void displaySWF(final String flashName, final Color bgColor, final float frameRate) {
|
||||
|
||||
// Minimum of 1000 ms (setMovieDelay) delay before calling flash.setMovie to avoid illegalAccess errors
|
||||
if (playQueue == null) {
|
||||
playQueue = new Thread() {
|
||||
long lastTime;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
boolean empty;
|
||||
synchronized (queueLock) {
|
||||
empty = movieToPlay == null;
|
||||
if (empty) {
|
||||
try {
|
||||
queueLock.wait();
|
||||
} catch (InterruptedException ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty) {
|
||||
flash.setMovie(movieToPlay);
|
||||
synchronized (queueLock) {
|
||||
movieToPlay = null;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(setMovieDelay);
|
||||
} catch (InterruptedException ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
playQueue.start();
|
||||
}
|
||||
zoom = 1.0;
|
||||
this.frameRate = frameRate;
|
||||
if (bgColor != null) {
|
||||
setBackground(bgColor);
|
||||
}
|
||||
synchronized (queueLock) {
|
||||
movieToPlay = flashName;
|
||||
queueLock.notify();
|
||||
}
|
||||
|
||||
//play
|
||||
stopped = false;
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() throws IOException {
|
||||
timer.cancel();
|
||||
closed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Stop();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Stop();
|
||||
flash.Rewind();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rewind() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Rewind();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Play();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlaying() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
return flash.IsPlaying();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoop(boolean loop
|
||||
) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotoFrame(int frame
|
||||
) {
|
||||
if (frame < 0) {
|
||||
return;
|
||||
}
|
||||
if (frame >= getTotalFrames()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.GotoFrame(frame);
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFrameRate() {
|
||||
return frameRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return !isStopped();
|
||||
}
|
||||
|
||||
public void fireMediaDisplayStateChanged() {
|
||||
for (MediaDisplayListener l : listeners) {
|
||||
l.mediaDisplayStateChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventListener(MediaDisplayListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventListener(MediaDisplayListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2016 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.player;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.gui.FlashUnsupportedException;
|
||||
import com.jpexs.decompiler.flash.gui.Main;
|
||||
import com.jpexs.helpers.CancellableWorker;
|
||||
import com.jpexs.javactivex.ActiveX;
|
||||
import com.jpexs.javactivex.ActiveXEvent;
|
||||
import com.jpexs.javactivex.ActiveXException;
|
||||
import com.jpexs.javactivex.example.controls.flash.ShockwaveFlash;
|
||||
import com.sun.jna.Platform;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public final class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FlashPlayerPanel.class.getName());
|
||||
|
||||
private final int setMovieDelay = Configuration.setMovieDelay.get();
|
||||
|
||||
private final List<MediaDisplayListener> listeners = new ArrayList<>();
|
||||
|
||||
private final ShockwaveFlash flash;
|
||||
|
||||
private final Timer timer;
|
||||
|
||||
private boolean stopped = true;
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private float frameRate;
|
||||
|
||||
@Override
|
||||
public boolean loopAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean screenAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoomAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZoomToFit() {
|
||||
//TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zoom getZoom() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private double zoom = 1.0;
|
||||
|
||||
@Override
|
||||
public synchronized void zoom(Zoom zoom) {
|
||||
double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value;
|
||||
int zoomint = (int) Math.round(100 / (zoomDouble / this.zoom));
|
||||
if (zoomint == 0) {
|
||||
zoomint = 1;
|
||||
}
|
||||
if (zoomint > 32767) {
|
||||
zoomint = 32767;
|
||||
}
|
||||
if (zoomint == 100) {
|
||||
zoomint = 0;
|
||||
}
|
||||
|
||||
flash.Zoom(0); // hack, but this call is needed otherwise unzoom will fail for larger zoom values
|
||||
flash.Zoom(zoomint);
|
||||
}
|
||||
|
||||
public synchronized String getVariable(String name) throws IOException {
|
||||
return flash.GetVariable(name);
|
||||
}
|
||||
|
||||
public synchronized void setVariable(String name, String value) throws IOException {
|
||||
flash.SetVariable(name, value);
|
||||
}
|
||||
|
||||
public synchronized String call(String callString) throws IOException {
|
||||
|
||||
return flash.CallFunction(callString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getCurrentFrame() {
|
||||
if (flash == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return flash.getFrameNum();
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getTotalFrames() {
|
||||
if (flash == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
if (flash.getReadyState() == 4) {
|
||||
return flash.getTotalFrames();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setBackground(Color color) {
|
||||
try {
|
||||
flash.setBackgroundColor((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
public FlashPlayerPanel(Component frame) {
|
||||
if (!Platform.isWindows()) {
|
||||
throw new FlashUnsupportedException();
|
||||
}
|
||||
|
||||
try {
|
||||
Callable<ShockwaveFlash> callable = new Callable<ShockwaveFlash>() {
|
||||
@Override
|
||||
public ShockwaveFlash call() throws InterruptedException {
|
||||
return ActiveX.createObject(ShockwaveFlash.class, FlashPlayerPanel.this);
|
||||
}
|
||||
};
|
||||
|
||||
// hack: Kernel32.INSTANCE.ConnectNamedPipe never completes in ActiveXControl static constructor
|
||||
flash = CancellableWorker.call(callable, 5, TimeUnit.SECONDS);
|
||||
} catch (ActiveXException | TimeoutException | InterruptedException | ExecutionException ex) {
|
||||
logger.log(Level.WARNING, "Cannot initialize flash panel", ex);
|
||||
throw new FlashUnsupportedException();
|
||||
}
|
||||
|
||||
flash.setAllowScriptAccess("always");
|
||||
try {
|
||||
flash.setAllowNetworking("all");
|
||||
} catch (ActiveXException ex) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
flash.addOnReadyStateChangeListener((ActiveXEvent axe) -> {
|
||||
fireMediaDisplayStateChanged();
|
||||
});
|
||||
|
||||
flash.addFlashCallListener((ActiveXEvent axe) -> {
|
||||
String req = (String) axe.args.get("request");
|
||||
Matcher m = Pattern.compile("<invoke name=\"([^\"]+)\" returntype=\"xml\"><arguments><string>(.*)</string></arguments></invoke>").matcher(req);
|
||||
if (m.matches()) {
|
||||
String funname = m.group(1);
|
||||
String msg = m.group(2);
|
||||
if (funname.equals("alert") || funname.equals("console.log")) {
|
||||
if (Main.debugDialog != null) {
|
||||
Main.debugDialog.log(funname + ":" + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
private boolean isPlaying = false;
|
||||
|
||||
private int currentFrame = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ShockwaveFlash flash1 = flash;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
if (flash1.getReadyState() >= 3) {
|
||||
boolean isPlaying = flash1.IsPlaying();
|
||||
if (this.isPlaying != isPlaying) {
|
||||
this.isPlaying = isPlaying;
|
||||
}
|
||||
|
||||
int currentFrame = flash1.CurrentFrame();
|
||||
if (this.currentFrame != currentFrame) {
|
||||
this.currentFrame = currentFrame;
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
this.isPlaying = false;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 100, 100);
|
||||
}
|
||||
|
||||
public synchronized void stopSWF() {
|
||||
displaySWF("-", null, 1);
|
||||
stopped = true;
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
|
||||
public synchronized boolean isStopped() {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage printScreen() {
|
||||
Point screenloc = getLocationOnScreen();
|
||||
try {
|
||||
return new Robot().createScreenCapture(new Rectangle(screenloc.x, screenloc.y, getWidth(), getHeight()));
|
||||
} catch (AWTException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String movieToPlay = null;
|
||||
|
||||
private Thread playQueue;
|
||||
|
||||
private final Object queueLock = new Object();
|
||||
|
||||
public synchronized void displaySWF(final String flashName, final Color bgColor, final float frameRate) {
|
||||
|
||||
// Minimum of 1000 ms (setMovieDelay) delay before calling flash.setMovie to avoid illegalAccess errors
|
||||
if (playQueue == null) {
|
||||
playQueue = new Thread() {
|
||||
long lastTime;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
boolean empty;
|
||||
synchronized (queueLock) {
|
||||
empty = movieToPlay == null;
|
||||
if (empty) {
|
||||
try {
|
||||
queueLock.wait();
|
||||
} catch (InterruptedException ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty) {
|
||||
flash.setMovie(movieToPlay);
|
||||
synchronized (queueLock) {
|
||||
movieToPlay = null;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(setMovieDelay);
|
||||
} catch (InterruptedException ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
playQueue.start();
|
||||
}
|
||||
zoom = 1.0;
|
||||
this.frameRate = frameRate;
|
||||
if (bgColor != null) {
|
||||
setBackground(bgColor);
|
||||
}
|
||||
synchronized (queueLock) {
|
||||
movieToPlay = flashName;
|
||||
queueLock.notify();
|
||||
}
|
||||
|
||||
//play
|
||||
stopped = false;
|
||||
fireMediaDisplayStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() throws IOException {
|
||||
timer.cancel();
|
||||
closed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Stop();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Stop();
|
||||
flash.Rewind();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rewind() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Rewind();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.Play();
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlaying() {
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
return flash.IsPlaying();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoop(boolean loop
|
||||
) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotoFrame(int frame
|
||||
) {
|
||||
if (frame < 0) {
|
||||
return;
|
||||
}
|
||||
if (frame >= getTotalFrames()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (flash.getReadyState() >= 3) {
|
||||
flash.GotoFrame(frame);
|
||||
}
|
||||
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFrameRate() {
|
||||
return frameRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return !isStopped();
|
||||
}
|
||||
|
||||
public void fireMediaDisplayStateChanged() {
|
||||
for (MediaDisplayListener l : listeners) {
|
||||
l.mediaDisplayStateChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventListener(MediaDisplayListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventListener(MediaDisplayListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user