Esempio n. 1
0
        private static Thread CreateReaderThread(Process process, OnTextReadDelegate textHandler, bool readStdError)
        {
            var threadData = new ThreadData();

            threadData.Process      = process;
            threadData.TextHandler  = textHandler;
            threadData.ReadStdError = readStdError;

            var readerThread = new Thread(ProcessReadingThread);

            readerThread.Start(threadData);

            return(readerThread);
        }
Esempio n. 2
0
        public static bool ReadProcessOutputUntilDone(Process process, OnTextReadDelegate stdOutHandler, OnTextReadDelegate stdErrHandler)
        {
            var stdOutputReaderThread = CreateReaderThread(process, stdOutHandler, false);

            if (stdOutputReaderThread == null)
            {
                return(false);
            }

            var stdErrorReaderThread = CreateReaderThread(process, stdErrHandler, true);

            if (stdErrorReaderThread == null)
            {
                return(false);
            }

            Thread.Sleep(1000);
            process.WaitForExit();
            stdOutputReaderThread.Join();
            stdErrorReaderThread.Join();

            return(process.ExitCode == 0);
        }
        public IEnumerator ReadText(string _filePath, OnTextReadDelegate _onTextReadDelegate)
        {
            // Get the Platform's file path:
            string filePath = GenerateFilePath((Application.streamingAssetsPath), _filePath);

            // Buffer the file:
            string buffer = string.Empty;

            if (filePath.Contains("://") || filePath.Contains(":///"))
            {
                // Handle WebGL/Android path:
                WWW www = new WWW(filePath);
                yield return(www);

                if (www != null)
                {
                    buffer = www.text;
                }
            }
            else
            {
                // Handle local path:
                if (File.Exists(filePath))
                {
                    buffer = File.ReadAllText(filePath);
                }
            }

            if (buffer != string.Empty)
            {
                _onTextReadDelegate(buffer);
            }
            else
            {
                Debug.LogWarningFormat("Failed to read text from {0}!", filePath);
            }
        }
 public static void Read(string _fileName, OnTextReadDelegate _onTextReadDelegate)
 {
     Instance.StartCoroutine(Instance.ReadText(_fileName, _onTextReadDelegate));
 }