private static void CommandConnect(string r) { try { TastyScript.Main.AndroidDriver = new Driver(r); } catch (Exception e) { if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
private static void CommandADB(string r) { try { var cmd = r.Replace("adb ", ""); TastyScript.Main.IO.Print("This command does not currently work as expected."); } catch (Exception e) { ExceptionListener.LogThrow("Unexpected error", e); } }
public static void CommandExec(string r) { try { Init(); var cmd = r.Replace("exec ", "").Replace("-e ", ""); var file = "override.Start(){\n" + cmd + "}"; var path = "AnonExecCommand.ts"; TokenParser.SleepDefaultTime = 1200; TokenParser.Stop = false; StartScript(path, file); } catch (Exception e) { if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
private static void CommandShell(string r) { try { if (TastyScript.Main.AndroidDriver != null) { TastyScript.Main.IO.Print($"Result: {TastyScript.Main.AndroidDriver.SendShellCommand(r.Replace("shell ", "").Replace("-sh ", ""))}"); } else { TastyScript.Main.Throw(new ExceptionHandler(ExceptionType.DriverException, "Device must be defined")); } } catch (Exception e) { if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
private static void CommandApp(string r) { try { if (TastyScript.Main.AndroidDriver != null) { TastyScript.Main.AndroidDriver.SetAppPackage(r); } else { TastyScript.Main.Throw(new ExceptionHandler(ExceptionType.DriverException, "Device must be defined")); } } catch (Exception e) { if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
private static void CommandScreenshot(string r) { try { if (TastyScript.Main.AndroidDriver != null) { var ss = TastyScript.Main.AndroidDriver.GetScreenshot(); ss.Result.Save(r, ImageFormat.Png); } else { TastyScript.Main.Throw(new ExceptionHandler(ExceptionType.DriverException, "Device must be defined")); } } catch (Exception e) { if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
private static void DirectRun(string r) { try { var path = r.Replace("\'", "").Replace("\"", ""); var file = Utilities.GetFileFromPath(path); TokenParser.SleepDefaultTime = 1200; TokenParser.Stop = false; StartScript(path, file); } catch (Exception e) { //if loglevel is throw, then compilerControledException gets printed as well //only for debugging srs issues if (!(e is CompilerControledException) || Settings.LogLevel == "throw") { ExceptionListener.LogThrow("Unexpected error", e); } } }
public static void NewWaitForCommand() { while (true) { _consoleCommand = ""; TastyScript.Main.IO.Print("\nSet your game to correct screen and then type run 'file/directory'\n", ConsoleColor.Green); TastyScript.Main.IO.Print('>', false); var r = ""; try { _cancelSource = new CancellationTokenSource(); r = Reader.ReadLine(_cancelSource.Token); } catch (OperationCanceledException e) {} catch (Exception e) { ExceptionListener.LogThrow("Unexpected error", e); } if (_consoleCommand != "") { r = _consoleCommand; } var split = r.Split(' '); var userInput = ""; if (split.Length > 1) { userInput = r.Replace(split[0] + " ", ""); } switch (split[0]) { case ("adb"): CommandADB(userInput); break; case ("app"): CommandApp(userInput); break; case ("-c"): case ("connect"): CommandConnect(userInput); break; case ("-d"): case ("devices"): CommandDevices(userInput); break; case ("dir"): CommandDir(userInput); break; case ("-e"): case ("exec"): TastyScript.Main.CommandExec(userInput); break; case ("-h"): case ("help"): CommandHelp(userInput); break; case ("-ll"): case ("loglevel"): CommandLogLevel(userInput); break; case ("remote"): CommandRemote(userInput); break; case ("-r"): case ("run"): TastyScript.Main.CommandRun(userInput); break; case ("-ss"): case ("screenshot"): CommandScreenshot(userInput); break; case ("-sh"): case ("shell"): CommandShell(userInput); break; default: TastyScript.Main.IO.Print("Enter '-h' for a list of commands!"); break; } } }