Exemple #1
0
 public WindowCMDCallbackRef(WindowCMDCallback callback)
 {
     m_callback = callback;
 }
    public static void LoadCommitsFromDateToDate(string repositoryAbsolutePath, GitDateFormat dateFromFormat, GitDateFormat dateToFormat, out List <LogCommitReceived> commits, out WindowCMDCallback callback, int maxToRecover = 50000)
    {
        commits = new List <LogCommitReceived>();

        string cmd = string.Format("git log --after=\"{0}\" --before=\"{1}\" --pretty=format:\"%H|%an|%ae|%ad|%s\" --date=format:%Y:%m:%d:%H:%M:%S:%z -n {2}",
                                   dateFromFormat.GetGitTimeFormat(), dateToFormat.GetGitTimeFormat(), maxToRecover);

        WindowCMD.RunCommands(new string[] { cmd }, repositoryAbsolutePath, false, out callback);
        string[] receivedLines = callback.GetReceivedTextAsLines();
        Debug.Log("Received Lines:" + receivedLines.Length);
        Debug.Log("Cmd:" + cmd);
        for (int i = 0; i < receivedLines.Length; i++)
        {
            //3a8c1a82146c13cb9e26359aaa73d49b9c81ca84|ddd|[email protected]|2020:06:19:09:53:30:+0200|Commit
            //50d63eb71ce042349f45ba4a3bd80da925bac915|Eloi Stree|[email protected]|2020:06:19:07:36:50:+0200|Commit
            string[] lineTokens = receivedLines[i].Split('|');
            if (lineTokens.Length == 5)
            {
                LogCommitReceived commit;
                ConvertTableToCommitFromStringOfConsole(lineTokens, out commit);
                commits.Add(commit);
            }
        }
    }
Exemple #3
0
    public static void RunCommands(string[] cmds, string workingDirectory, bool useDebug, out WindowCMDCallback callback)
    {
        callback = new WindowCMDCallback();
        WindowCMDCallbackRef callbackRef = new WindowCMDCallbackRef(callback);

        callback.SetUsedDirectory(workingDirectory);
        callback.AddCommandsToUsed(cmds);
        callback.StartExecuting();
        try
        {
            if (workingDirectory.Length < 2)
            {
                return;
            }

            char disk = 'C';
            if (workingDirectory[1] == ':')
            {
                disk = workingDirectory[0];
            }

            var process = new Process();
            var psi     = new ProcessStartInfo();
            psi.FileName = "cmd.exe";
            //psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            psi.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Minimized;
            psi.RedirectStandardInput  = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            psi.UseShellExecute        = false;
            psi.CreateNoWindow         = true;
            psi.WorkingDirectory       = workingDirectory;
            process.StartInfo          = psi;
            process.Start();
            process.OutputDataReceived += (sender, e) =>
            {
                callbackRef.m_callback.AddConsoleCallback(e.Data);
                if (useDebug)
                {
                    UnityEngine.Debug.Log(e.Data);
                }
            };
            process.ErrorDataReceived += (sender, e) =>
            {
                callbackRef.m_callback.AddConsoleError(e.Data);
                if (useDebug)
                {
                    UnityEngine.Debug.Log(e.Data);
                }
            };
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            using (StreamWriter sw = process.StandardInput)
            {
                sw.WriteLine(disk + ":");
                sw.WriteLine("cd " + workingDirectory);
                foreach (var cmd in cmds)
                {
                    callbackRef.m_callback.SetAsExecutingCommand(cmd);
                    if (useDebug)
                    {
                        UnityEngine.Debug.Log("> " + cmd);
                    }
                    sw.WriteLine(cmd);
                    callbackRef.m_callback.AddExecutedCommand(cmd);
                }
            }
            process.WaitForExit();
        }
        catch (Exception e)
        {
            callback.NotifyError(e.StackTrace);
        }
        callback.RemoveMicrosfotReservedLabelOfConsoleCallback();
        callback.RemoveSentInfoOfConsoleCallback();
        callback.SetAsFinished();
    }