Esempio n. 1
0
        public static async Task OpenP4VAtAsync(string documentPath)
        {
            string output;

            try
            {
                if (string.IsNullOrEmpty(documentPath))
                {
                    output = "Nothing to do, no open document";
                }
                else
                {
                    P4Settings settings = GetSettings(documentPath);
                    P4FileStat fileStat = GetFileStat(documentPath);
                    if (settings != null && fileStat != null)
                    {
                        string arguments = string.Format("-p {0} -c {1} -u {2} -s {3}", settings.Port, settings.Client, settings.User, fileStat.DepotFile);
                        await Helper.VSHelper.OutputLineAsync("ExecuteCommand: p4v {0}", arguments);

                        Helper.ProcessHelper.RunProcess("p4v", arguments, Path.GetDirectoryName(documentPath), out output);
                    }
                    else
                    {
                        output = string.Format("Failed to get FileStat / P4Settings for '{0}'", documentPath);
                    }
                }
            }
            catch (Exception exception)
            {
                output = exception.Message;
            }
            await Helper.VSHelper.OutputLineAsync("Result: {0}", output);
        }
Esempio n. 2
0
        public static async Task <int> ExecuteP4VCommandAsync(string format, string documentPath)
        {
            if (string.IsNullOrEmpty(documentPath))
            {
                await Helper.VSHelper.OutputLineAsync("Result: Nothing to do, no open document");

                return(1);
            }

            P4Settings settings = GetSettings(documentPath);

            if (settings == null)
            {
                await Helper.VSHelper.OutputLineAsync("Result: Failed to get file information");

                return(1);
            }

            string arguments = string.Format("-p {0} -c {1} -u {2} -cmd \"{3}\"", settings.Port, settings.Client, settings.User, string.Format(format, documentPath));

            return(await ExecuteCommandAsync("p4v", arguments, Path.GetDirectoryName(documentPath)));
        }
Esempio n. 3
0
        public static P4Settings GetSettings(string filename)
        {
            try
            {
                string output;
                if (Helper.ProcessHelper.RunProcess("p4", "set", Path.GetDirectoryName(filename), out output) == 0)
                {
                    //P4CLIENT=someclient (set)
                    //P4CONFIG=P4CONFIG (set) (config 'noconfig')
                    //P4EDITOR=C:\windows\SysWOW64\notepad.exe (set)
                    //P4PORT=someport:1667 (set)
                    //P4USER=someuser (set)
                    //P4_proxy.sea.epicgames.net:1667_CHARSET=none (set)

                    var findClient = new System.Text.RegularExpressions.Regex(@"P4CLIENT=([^\n(]+)", System.Text.RegularExpressions.RegexOptions.Multiline);
                    var findPort   = new System.Text.RegularExpressions.Regex(@"P4PORT=([^\n(]+)", System.Text.RegularExpressions.RegexOptions.Multiline);
                    var findUser   = new System.Text.RegularExpressions.Regex(@"P4USER=([^\n(]+)", System.Text.RegularExpressions.RegexOptions.Multiline);

                    P4Settings settings = new P4Settings();
                    settings.Client = findClient.Match(output).Groups[1].ToString().Trim();
                    settings.Port   = findPort.Match(output).Groups[1].ToString().Trim();
                    settings.User   = findUser.Match(output).Groups[1].ToString().Trim();

                    if (!string.IsNullOrEmpty(settings.Client) && !string.IsNullOrEmpty(settings.User) && !string.IsNullOrEmpty(settings.Port))
                    {
                        return(settings);
                    }
                }
            }
            catch
            {
                // Do nothing failed
            }

            return(null);
        }