Ejemplo n.º 1
0
    public int KillServer(WaitingProcessToExitCallback waitingProcessToExitCallback)
    {
        string outputString;
        string errorString;

        int exitCode = RunCommand(new string[] { "kill-server" }, waitingProcessToExitCallback, out outputString, out errorString);

        return(exitCode);
    }
Ejemplo n.º 2
0
    public int ForwardPort(int port, WaitingProcessToExitCallback waitingProcessToExitCallback)
    {
        string outputString;
        string errorString;

        string portString = string.Format("tcp:{0}", port);

        int exitCode = RunCommand(new string[] { "forward", portString, portString }, waitingProcessToExitCallback, out outputString, out errorString);

        return(exitCode);
    }
Ejemplo n.º 3
0
    public int RunCommand(string[] arguments, WaitingProcessToExitCallback waitingProcessToExitCallback, out string outputString, out string errorString)
    {
        int exitCode = -1;

        if (!isReady)
        {
            Debug.LogWarning("OVRADBTool not ready");
            outputString = string.Empty;
            errorString  = "OVRADBTool not ready";
            return(exitCode);
        }

        string args = string.Join(" ", arguments);

        ProcessStartInfo startInfo = new ProcessStartInfo(adbPath, args);

        startInfo.WorkingDirectory       = androidSdkRoot;
        startInfo.CreateNoWindow         = true;
        startInfo.UseShellExecute        = false;
        startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardError  = true;

        outputStringBuilder = new StringBuilder("");
        errorStringBuilder  = new StringBuilder("");

        Process process = Process.Start(startInfo);

        process.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceivedHandler);
        process.ErrorDataReceived  += new DataReceivedEventHandler(ErrorDataReceivedHandler);

        process.BeginOutputReadLine();
        process.BeginErrorReadLine();

        try
        {
            do
            {
                if (waitingProcessToExitCallback != null)
                {
                    waitingProcessToExitCallback();
                }
            } while (!process.WaitForExit(100));

            process.WaitForExit();
        }
        catch (Exception e)
        {
            Debug.LogWarningFormat("[OVRADBTool.RunCommand] exception {0}", e.Message);
        }

        exitCode = process.ExitCode;

        process.Close();

        outputString = outputStringBuilder.ToString();
        errorString  = errorStringBuilder.ToString();

        outputStringBuilder = null;
        errorStringBuilder  = null;

        if (!string.IsNullOrEmpty(errorString))
        {
            if (errorString.Contains("Warning"))
            {
                UnityEngine.Debug.LogWarning("OVRADBTool " + errorString);
            }
            else
            {
                UnityEngine.Debug.LogError("OVRADBTool " + errorString);
            }
        }

        return(exitCode);
    }