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.NumberFormat;
class main {
static void stefansPS_vncToRaspi() {
File exe = assertNotNull(windowsFindExe("RealVNC/VNC Viewer/vncviewer"));
nohup(platformQuote(exe) + " -config " + platformQuote(javaxDataDir("RealVNC Profiles/raspi.vnc")));
}
static A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
static A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
static File windowsFindExe(String relativeName) {
return firstFileThatExists(map(windowsProgramFilesDirs(), dir ->
defaultExtension("exe",newFile(dir, relativeName))));
}
static boolean nohup_debug = false;
static boolean nohup_noSlashB = false;
static ThreadLocal nohup_exitValue = new ThreadLocal();
public static File nohup(String cmd) { try {
File outFile = File.createTempFile("nohup_" + nohup_sanitize(cmd) + "_", ".out");
nohup(cmd, outFile, false);
return outFile;
} catch (Exception __e) { throw rethrow(__e); } }
/** outFile takes stdout and stderr. */
public static void nohup(String cmd, File outFile, boolean append) { try {
String command = nohup_makeNohupCommand(cmd, outFile, append);
File scriptFile = File.createTempFile("_realnohup", isWindows() ? ".bat" : "");
System.out.println("[Nohup] " + command);
try {
if (nohup_debug)
print("[nohup] Script file: " + scriptFile.getPath());
saveTextFile(scriptFile.getPath(), command);
String[] command2;
if (isWindows())
if (nohup_noSlashB)
command2 = new String[] {"cmd", "/c", "start", scriptFile.getPath() };
else
command2 = new String[] {"cmd", "/c", "start", "/b", scriptFile.getPath() };
else
command2 = new String[] {"/bin/bash", scriptFile.getPath() };
printStruct("[nohup] " , command2);
Process process = Runtime.getRuntime().exec(command2);
try {
process.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
int value = process.exitValue();
nohup_exitValue.set(value);
if (value != 0)
warn("nohup exit value != 0: " + value);
//System.out.println("exit value: " + value);
} finally {
if (!isWindows())
scriptFile.delete();
}
} catch (Exception __e) { throw rethrow(__e); } }
public static String nohup_makeNohupCommand(String cmd, File outFile, boolean append) {
mkdirsForFile(outFile);
String command;
if (isWindows())
command = cmd + (append ? " >>" : " >") + winQuote(outFile.getPath()) + " 2>&1";
else
command = "nohup " + cmd + (append ? " >>" : " >") + bashQuote(outFile.getPath()) + " 2>&1 &";
return command;
}
static String platformQuote(String s) {
return isWindows() ? winQuote(s) : bashQuote(s);
}
static String platformQuote(File f) {
return platformQuote(f2s(f));
}
static File javaxDataDir_dir; // can be set to work on different base dir
static File javaxDataDir() {
return javaxDataDir_dir != null ? javaxDataDir_dir : new File(userHome(), "JavaX-Data");
}
static File javaxDataDir(String... subs) {
return newFile(javaxDataDir(), subs);
}
static void assertTrue(Object o) {
if (!(eq(o, true) /*|| isTrue(pcallF(o))*/))
throw fail(str(o));
}
static boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
static boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
static File firstFileThatExists(String... paths) {
return oneOfTheFiles(paths);
}
static File firstFileThatExists(File... files) {
return oneOfTheFiles(files);
}
static File firstFileThatExists(Iterable files) {
return oneOfTheFiles(files);
}
static List map(Iterable l, Object f) { return map(f, l); }
static List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null) for (Object o : l)
x.add(callF(f, o));
return x;
}
static List map(Iterable l, F1 f) { return map(f, l); }
static List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(callF(f, o));
return x;
}
static List map(IF1 f, Iterable l) { return map(l, f); }
static List map(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(f.get(o));
return x;
}
static List map(IF1 f, A[] l) { return map(l, f); }
static List map(A[] l, IF1 f) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(f.get(o));
return x;
}
static List map(Object f, Object[] l) { return map(f, asList(l)); }
static List map(Object[] l, Object f) { return map(f, l); }
static List map(Object f, Map map) {
return map(map, f);
}
// map: func(key, value) -> list element
static List map(Map map, Object f) {
List x = new ArrayList();
if (map != null) for (Object _e : map.entrySet()) {
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
static List map(Map map, IF2 f) {
return map(map, (Object) f);
}
static List windowsProgramFilesDirs() {
return dirsThatExist(
"C:\\Program Files",
"C:\\Program Files (x86)");
}
static File defaultExtension(String ext, File file) {
if (empty(ext)) return file;
if (file == null || fileHasAnyExtensionAtAll(file)) return file;
return appendToFileName(addDotPrefix(ext), file);
}
static String defaultExtension(String ext, String fileName) {
if (empty(ext)) return fileName;
if (fileName == null || contains(fileName, '.')) return fileName;
return rjoin(addDotPrefix(ext), fileName);
}
static File newFile(File base, String... names) {
for (String name : names) base = new File(base, name);
return base;
}
static File newFile(String name) {
return name == null ? null : new File(name);
}
static File newFile(String base, String... names) {
return newFile(newFile(base), names);
}
static String nohup_sanitize(String s) {
return empty(s) ? s : takeFirst(50, s.replaceAll("[^.a-zA-Z0-9\\-_]", ""));
}
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);
}
public static boolean isWindows() {
return System.getProperty("os.name").contains("Windows");
}
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