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); }
public static async Task CopyP4PathToClipboardAsync(string documentPath) { string output; try { if (string.IsNullOrEmpty(documentPath)) { output = "Nothing to do, no open document"; } else { P4FileStat fileStat = GetFileStat(documentPath); if (fileStat != null) { System.Windows.Forms.Clipboard.SetText(fileStat.DepotFile); output = string.Format("Copied '{0}' to clipboard", fileStat.DepotFile); } else { output = string.Format("Failed to get FileStat for '{0}'", documentPath); } } } catch (Exception exception) { output = exception.Message; } await Helper.VSHelper.OutputLineAsync("Result: {0}", output); }
public static P4FileStat GetFileStat(string filename) { try { string output; if (filename.StartsWith("//")) { if (Helper.ProcessHelper.RunProcess("p4", "fstat " + filename, out output) != 0) { return(null); } } else { if (Helper.ProcessHelper.RunProcess("p4", "fstat " + Path.GetFileName(filename), Path.GetDirectoryName(filename), out output) != 0) { return(null); } } //... depotFile //UE4/Release-4.22/GenerateProjectFiles.bat //... clientFile D:\stu.mckenna-4-22\GenerateProjectFiles.bat //... isMapped //... headAction branch //... headType text+x //... headTime 1548987099 //... headRev 1 //... headChange 4862694 //... headModTime 1481225333 //... haveRev 1 var findDepotFile = new System.Text.RegularExpressions.Regex(@"depotFile([^\n]+)$", System.Text.RegularExpressions.RegexOptions.Multiline); var findClientFile = new System.Text.RegularExpressions.Regex(@"clientFile([^\n]+)$", System.Text.RegularExpressions.RegexOptions.Multiline); var findHeadRevision = new System.Text.RegularExpressions.Regex(@"headRev([^\n]+)$", System.Text.RegularExpressions.RegexOptions.Multiline); var findHaveRevision = new System.Text.RegularExpressions.Regex(@"haveRev([^\n]+)$", System.Text.RegularExpressions.RegexOptions.Multiline); P4FileStat fileStat = new P4FileStat(); fileStat.DepotFile = findDepotFile.Match(output).Groups[1].ToString().TrimEnd('\r', '\n').Trim(); fileStat.HeadRevision = int.Parse(findHeadRevision.Match(output).Groups[1].ToString().TrimEnd('\r', '\n').Trim()); var clientMatch = findClientFile.Match(output); if (clientMatch.Groups.Count > 1) { fileStat.ClientFile = findClientFile.Match(output).Groups[1].ToString().TrimEnd('\r', '\n').Trim(); fileStat.HaveRevision = int.Parse(findHaveRevision.Match(output).Groups[1].ToString().TrimEnd('\r', '\n').Trim()); } return(fileStat); } catch { // Do nothing failed } return(null); }
public static async Task AddOrEditAsync(string documentPath) { if (string.IsNullOrEmpty(documentPath)) { await Helper.VSHelper.OutputLineAsync("Nothing to do, no open document"); return; } P4FileStat fileStat = GetFileStat(documentPath); if (fileStat == null || string.IsNullOrEmpty(fileStat.DepotFile)) { await Helper.P4Helper.ExecuteP4CommandAsync("add {0}", await Helper.VSHelper.GetOpenDocumentNameAsync()); } else { await Helper.P4Helper.ExecuteP4CommandAsync("edit {0}", documentPath); } }