import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import static x30_pkg.x30_util.DynamicObject;
import static uk.co.caprica.vlcjplayer.Application.application;
import uk.co.caprica.vlcj.player.embedded.*;
import uk.co.caprica.vlcjplayer.event.*;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.log.NativeLog;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.runtime.streams.NativeStreams;
import uk.co.caprica.vlcjplayer.view.debug.DebugFrame;
import uk.co.caprica.vlcjplayer.view.effects.EffectsFrame;
import uk.co.caprica.vlcjplayer.view.main.MainFrame;
import uk.co.caprica.vlcjplayer.view.messages.NativeLogFrame;
class main {
// vlcj player
static NativeStreams nativeStreams;
static JFrame mainFrame, messagesFrame, effectsFrame, debugFrame;
static NativeLog nativeLog;
public static void main(final String[] args) throws Exception/*-subst*/ { // fullscreen still has a frame with Substance
pnl(addMegaLibrary(myClassLoader(), "#1400524"));
fixContextClassLoader();
// This will locate LibVLC for the vast majority of cases
new NativeDiscovery().discover();
startPlayer();
if (nempty(args)) {
String fileToPlay = first(args);
if (fileExists(fileToPlay)) {
application().addRecentMedia(fileToPlay);
application().mediaPlayerComponent().getMediaPlayer().playMedia(fileToPlay);
}
}
hideConsole();
}
static void startPlayer() {
{ swing(new Runnable() { public void run() { try {
final EmbeddedMediaPlayerComponent mediaPlayerComponent = application().mediaPlayerComponent();
mainFrame = new MainFrame();
onWindowClosingDoOnly(mainFrame, new Runnable() { public void run() { try {
mediaPlayerComponent.getMediaPlayer().stop();
mediaPlayerComponent.release();
if (nativeStreams != null) nativeStreams.release();
application().post(ShutdownEvent.INSTANCE);
cleanKillInNewThread();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "mediaPlayerComponent.getMediaPlayer().stop();\r\n mediaPlayerComponent.rel..."; }});
EmbeddedMediaPlayer embeddedMediaPlayer = mediaPlayerComponent.getMediaPlayer();
embeddedMediaPlayer.setFullScreenStrategy(new VlcjPlayerFullScreenStrategy(mainFrame));
nativeLog = mediaPlayerComponent.getMediaPlayerFactory().newLog();
messagesFrame = new NativeLogFrame(nativeLog);
effectsFrame = new EffectsFrame();
debugFrame = new DebugFrame();
mainFrame.setVisible(true);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "final EmbeddedMediaPlayerComponent mediaPlayerComponent = application().media..."; }}); }
}
static class VlcjPlayerFullScreenStrategy extends DefaultAdaptiveRuntimeFullScreenStrategy {
VlcjPlayerFullScreenStrategy(Window window) { super(window); }
@Override
protected void beforeEnterFullScreen() {
application().post(BeforeEnterFullScreenEvent.INSTANCE);
}
@Override
protected void afterExitFullScreen() {
application().post(AfterExitFullScreenEvent.INSTANCE);
}
}
static A pnl(A l) { return pnl("", l); }
static A pnl(String prefix, A l) {
printNumberedLines(prefix, l);
return l;
}
static A[] pnl(A[] l) { return pnl("", l); }
static A[] pnl(String prefix, A[] l) {
printNumberedLines(prefix, l);
return l;
}
static A pnl(A map) {
printNumberedLines(map);
return map;
}
static A pnl(String prefix, A map) {
printNumberedLines(prefix, map);
return map;
}
static String pnl(String s) {
printNumberedLines(lines(s));
return s;
}
static MultiMap pnl(MultiMap mm) {
pnl(mm == null ? null : mm.asMap());
return mm;
}
static Pair, List> addMegaLibrary(ClassLoader cl, String snippetID) {
var jars = allJarFiles(unpackZipLibrary(snippetID));
List added = new ArrayList();
List alreadyThere = new ArrayList();
for (var jar : jars)
(addByteCodePathToClassLoader(cl, jar) ? added : alreadyThere).add(jar);
return pair(added, alreadyThere);
}
static ClassLoader myClassLoader() {
return _getClass(mc()).getClassLoader();
}
/* binary break!
static ClassLoader fixContextClassLoader() {
var cl = myClassLoader();
Thread.currentThread().setContextClassLoader(cl);
ret cl;
}*/
static void fixContextClassLoader() {
Thread.currentThread().setContextClassLoader(myClassLoader());
}
static boolean nempty(Collection c) {
return !empty(c);
}
static boolean nempty(CharSequence s) {
return !empty(s);
}
static boolean nempty(Object[] o) { return !empty(o); }
static boolean nempty(byte[] o) { return !empty(o); }
static boolean nempty(int[] o) { return !empty(o); }
static boolean nempty(BitSet bs) { return !empty(bs); }
static boolean nempty(Map m) {
return !empty(m);
}
static boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static boolean nempty(MultiMap mm) { return mm != null && !mm.isEmpty(); }
static boolean nempty(Object o) { return !empty(o); }
static Object first(Object list) {
return first((Iterable) list);
}
static A first(List list) {
return empty(list) ? null : list.get(0);
}
static A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
static Pair first(Map map) {
return mapEntryToPair(first(entrySet(map)));
}
static Pair first(MultiMap mm) {
if (mm == null) return null;
var e = first(mm.data.entrySet());
if (e == null) return null;
return pair(e.getKey(), first(e.getValue()));
}
static A first(IterableIterator i) {
return first((Iterator) i);
}
static A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
static A first(Iterable i) {
if (i == null) return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
static Character first(String s) { return empty(s) ? null : s.charAt(0); }
static Character first(CharSequence s) { return empty(s) ? null : s.charAt(0); }
static A first(Pair p) {
return p == null ? null : p.a;
}
static Byte first(byte[] l) {
return empty(l) ? null : l[0];
}
static A first(A[] l, IF1 pred) {
return firstThat(l, pred);
}
static A first(Iterable l, IF1 pred) {
return firstThat(l, pred);
}
static A first(IF1 pred, Iterable l) {
return firstThat(pred, l);
}
static boolean fileExists(String path) {
return path != null && new File(path).exists();
}
static boolean fileExists(File f) {
return f != null && f.exists();
}
static void hideConsole() {
final JFrame frame = consoleFrame();
if (frame != null) {
autoVMExit();
swingLater(new Runnable() { public void run() { try {
frame.setVisible(false);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "frame.setVisible(false);"; }});
}
}
static Object swing(Object f) {
return swingAndWait(f);
}
static A swing(F0 f) {
return (A) swingAndWait(f);
}
static A swing(IF0 f) {
return (A) swingAndWait(f);
}
static A onWindowClosingDoOnly(A w, final Object r) {
return onWindowClosingOnly(w, r);
}
static void cleanKillInNewThread() {
startThread("Kill", new Runnable() { public void run() { try { cleanKill();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "cleanKill();"; }});
}
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
/*static L printNumberedLines(L l) {
printNumberedLines((Collection) l);
ret l;
}
static L printNumberedLines(S prefix, L l) {
printNumberedLines(prefix, (Collection) l);
ret l;
}*/
static void printNumberedLines(Map map) {
printNumberedLines(mapToLines(map));
}
static void printNumberedLines(String prefix, Map map) {
printNumberedLines(prefix, mapToLines(map));
}
static A printNumberedLines(A l) {
int i = 0;
if (l != null) for (Object a : cloneList(l)) print((++i) + ". " + str(a));
return l;
}
static A printNumberedLines(String prefix, A l) {
int i = 0;
if (l != null) for (Object a : cloneList(l)) print(prefix + (++i) + ". " + str(a));
return l;
}
static void printNumberedLines(Object[] l) { printNumberedLines("", l); }
static void printNumberedLines(String prefix, Object[] l) {
printNumberedLines(prefix, wrapAsList(l));
}
static void printNumberedLines(Object o) {
printNumberedLines(lines(str(o)));
}
static String lines(Iterable lines) { return fromLines(lines); }
static String lines(Object[] lines) { return fromLines(asList(lines)); }
static List lines(String s) { return toLines(s); }
// convenience map call
static String lines(Iterable l, IF1 f) {
return mapToLines(l, f);
}
static List allJarFiles(File dir) {
return findFilesWithExtension(".jar", dir);
}
static File unpackZipLibrary(String snippetID) {
File zip = loadLibrary(snippetID);
File dir = javaxCodeDir("Unpackaged Zip Snippets/" + psI(snippetID));
zip2dir_overwriteIfDifferentSize(zip, dir);
return dir;
}
static boolean addByteCodePathToClassLoader(ClassLoader cl, File bytecode) { return addByteCodePathToClassLoader(cl, bytecode, null); }
static boolean addByteCodePathToClassLoader(ClassLoader cl, File bytecode, String libraryID) { try {
// new method signature
Boolean b = (Boolean) (callOpt(cl, "addFile", bytecode, libraryID));
if (b == null)
// legacy method signature
b = isTrue(call(cl, "addFile", bytecode));
if (b) print("Added byte code path " + bytecode + " to " + cl
+ appendBracketed(libraryID));
return b;
} catch (Exception __e) { throw rethrow(__e); } }
static Pair pair(A a, B b) {
return new Pair(a, b);
}
static Pair pair(A a) {
return new Pair(a, a);
}
static Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null; // could optimize this
}
}
static Class _getClass(Object o) {
return o == null ? null
: o instanceof Class ? (Class) o : o.getClass();
}
static Class _getClass(Object realm, String name) {
try {
return classLoaderForObject(realm).loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null; // could optimize this
}
}
static Class mc() {
return main.class;
}
static boolean empty(Collection c) { return c == null || c.isEmpty(); }
static boolean empty(Iterable c) { return c == null || !c.iterator().hasNext(); }
static boolean empty(CharSequence s) { return s == null || s.length() == 0; }
static boolean empty(Map map) { return map == null || map.isEmpty(); }
static boolean empty(Object[] o) { return o == null || o.length == 0; }
static boolean empty(BitSet bs) { return bs == null || bs.isEmpty(); }
static boolean empty(Object o) {
if (o instanceof Collection) return empty((Collection) o);
if (o instanceof String) return empty((String) o);
if (o instanceof Map) return empty((Map) o);
if (o instanceof Object[]) return empty((Object[]) o);
if (o instanceof byte[]) return empty((byte[]) o);
if (o == null) return true;
throw fail("unknown type for 'empty': " + getType(o));
}
static boolean empty(Iterator i) { return i == null || !i.hasNext(); }
static boolean empty(double[] a) { return a == null || a.length == 0; }
static boolean empty(float[] a) { return a == null || a.length == 0; }
static boolean empty(int[] a) { return a == null || a.length == 0; }
static boolean empty(long[] a) { return a == null || a.length == 0; }
static boolean empty(byte[] a) { return a == null || a.length == 0; }
static boolean empty(short[] a) { return a == null || a.length == 0; }
static boolean empty(MultiMap mm) { return mm == null || mm.isEmpty(); }
static boolean empty(File f) { return getFileSize(f) == 0; }
static Pair mapEntryToPair(Map.Entry e) {
return e == null ? null : pair(e.getKey(), e.getValue());
}
static Set> entrySet(Map map) {
return _entrySet(map);
}
static A firstThat(Iterable l, IF1 pred) {
for (A a : unnullForIteration(l))
if (pred.get(a))
return a;
return null;
}
static A firstThat(A[] l, IF1 pred) {
for (A a : unnullForIteration(l))
if (pred.get(a))
return a;
return null;
}
static A firstThat(IF1 pred, Iterable l) {
return firstThat(l, pred);
}
static A firstThat(IF1 pred, A[] l) {
return firstThat(l, pred);
}
static JFrame consoleFrame() {
return (JFrame) getOpt(get(getJavaX(), "console"), "frame");
}
static void autoVMExit() {
call(getJavaX(), "autoVMExit");
}
static void swingLater(long delay, final Object r) {
javax.swing.Timer timer = new javax.swing.Timer(toInt(delay), actionListener(wrapAsActivity(r)));
timer.setRepeats(false);
timer.start();
}
static void swingLater(Object r) {
SwingUtilities.invokeLater(toRunnable(r));
}
static void swingAndWait(Runnable r) { try {
if (isAWTThread())
r.run();
else
EventQueue.invokeAndWait(addThreadInfoToRunnable(r));
} catch (Exception __e) { throw rethrow(__e); } }
static Object swingAndWait(final Object f) {
if (isAWTThread())
return callF(f);
else {
final Var result = new Var();
swingAndWait(new Runnable() { public void run() { try {
result.set(callF(f));
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "result.set(callF(f));"; }});
return result.get();
}
}
static A onWindowClosingOnly(final A w, final Object r) {
if (w != null) {
onWindowClosing(w, r);
{ swing(new Runnable() { public void run() { try { w.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "w.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);"; }}); }
}
return w;
}
static Thread startThread(Object runnable) {
return startThread(defaultThreadName(), runnable);
}
static Thread startThread(String name, Runnable runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(runnable, name));
}
static Thread startThread(String name, Object runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(toRunnable(runnable), name));
}
static Thread startThread(Thread t) {
_registerThread(t);
t.start();
return t;
}
static void cleanKill() {
cleanKillVM();
}
static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
static List mapToLines(Map map) {
List l = new ArrayList();
for (Object key : keys(map))
l.add(str(key) + " = " + str(map.get(key)));
return l;
}
static String mapToLines(Map map, Object f) {
return lines(map(map, f));
}
static String mapToLines(Object f, Map map) {
return lines(map(map, f));
}
static String mapToLines(Object f, Iterable l) {
return lines(map(f, l));
}
static String mapToLines(Iterable l, IF1 f) {
return mapToLines((Object) f, l);
}
static String mapToLines(IF1 f, Iterable l) {
return mapToLines((Object) f, l);
}
static String mapToLines(Map map, IF2 f) {
return lines(map(map, f));
}
static String mapToLines(IF1 f, A data1, A... moreData) {
return lines(map(f, data1, moreData));
}
static ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
static ArrayList cloneList(Collection l) {
if (l == null) return new ArrayList();
synchronized(collectionMutex(l)) {
return new ArrayList(l);
}
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal