//------------------------------------------------------------------------------------------- public static string P4GetDirectory(string workingDirectory, string p4Path) { string path = null; string args = "where " + p4Path; P4Result result = P4Command(workingDirectory, args); if (result.resultCode == 0) { if (result.stderr == "") { StringReader strReader = new System.IO.StringReader(result.stdout); string pathString = strReader.ReadLine(); string[] splitPaths = pathString.Split(' '); if (splitPaths.Length == 3) { path = splitPaths[2]; path = path.Trim(new char[] { ' ', '.' }); } } else { //TODO: add some error output here e.g. -- files not in client view } } return(path); }
//------------------------------------------------------------------------------------------- private static P4Result ShellCommand(string workingDirectory, string command, string fileName, bool redirectOutput) { P4Result result = new P4Result(); string prevDirectory = System.IO.Directory.GetCurrentDirectory(); try { System.IO.Directory.SetCurrentDirectory(workingDirectory); ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = fileName; processStartInfo.Arguments = command; processStartInfo.RedirectStandardOutput = redirectOutput; processStartInfo.RedirectStandardError = redirectOutput; processStartInfo.UseShellExecute = false; processStartInfo.CreateNoWindow = true; if (!processStartInfo.EnvironmentVariables.ContainsKey("P4CONFIG")) { processStartInfo.EnvironmentVariables.Add("P4CONFIG", "P4CONFIG"); } processStartInfo.WorkingDirectory = workingDirectory; Process proc = Process.Start(processStartInfo); bool reading = redirectOutput; while (reading) { string outLine = proc.StandardOutput.ReadLine(); string errLine = proc.StandardError.ReadLine(); if (outLine != null && outLine != "") { result.stdout += outLine + "\r"; } if (errLine != null && errLine != "") { result.stderr += errLine + "\r"; } reading = (outLine != null) || (errLine != null); } proc.WaitForExit(); result.resultCode = proc.ExitCode; } catch (System.Exception ex) { UnityEngine.Debug.LogError("EB.Perforce > Something is wrong: " + ex.ToString()); } finally { System.IO.Directory.SetCurrentDirectory(prevDirectory); } UnityEngine.Debug.Log("EB.Perforce > Running: " + fileName + " " + command + ", cwd: " + workingDirectory); UnityEngine.Debug.Log("EB.Perforce > Output: " + result.stdout + " " + result.stderr); return(result); }