using System; using System.Collections.Generic; using System.Linq; using System.Text; using P4API; using System.Windows.Forms; namespace ProjectScannerP4V { public class P4Tools { public string Port { get; set; } public string User { get; set; } public string Client { get; set; } public string Root { get; set; } public bool MoveFile(string srcDepotPath,string destDepotPath, string CL) { try { using (P4Connection p4con = CreateConnection()) { P4UnParsedRecordSet p4ru = p4con.RunUnParsed("move", "-c" + CL, srcDepotPath, destDepotPath); p4con.Disconnect(); if (p4ru.Errors.Length > 0) { MessageBox.Show(p4ru.ErrorMessage); } return p4ru.Errors.Length == 0; } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return false; } } public string GetLocalPath(string depotPath) { using (P4Connection p4con = CreateConnection()) { P4RecordSet p4ru = p4con.Run("where", depotPath); p4con.Disconnect(); return p4ru[0]["path"]; } } public bool CheckoutFile(string depotPath,string CL,bool reopen) { using (P4Connection p4con = CreateConnection()) { bool bCheckout=true; P4UnParsedRecordSet p4ru=null; if (reopen) { p4ru = p4con.RunUnParsed("opened", "-C" + Client, "-u" + User, depotPath); if (p4ru.Messages.Length > 0) { if (string.IsNullOrEmpty(CL)) CL = "default"; p4ru = p4con.RunUnParsed("reopen", "-c" + CL, depotPath); bCheckout = false; } else bCheckout = true; } if (bCheckout) { p4ru = p4con.RunUnParsed("edit", "-c" + CL, depotPath); } p4con.Disconnect(); if (p4ru!=null && p4ru.Errors.Length > 0) { MessageBox.Show(p4ru.ErrorMessage); } return p4ru.Errors.Length == 0; } } public bool IsDirecty(string depotPath) { using (P4Connection p4con = CreateConnection()) { if (depotPath.EndsWith("/")) depotPath=depotPath.TrimEnd('/'); P4RecordSet p4ru = p4con.Run("dirs", depotPath); p4con.Disconnect(); if (p4ru.Records.Length > 0) return true; else return false; } } public string CreateCl(string Desc) { using (P4Connection p4con = CreateConnection()) { P4PendingChangelist cl = p4con.CreatePendingChangelist(Desc); return cl.Number.ToString(); } } public string[] GetDirectories(string depotPath) { using (P4Connection p4con = CreateConnection()) { if (!depotPath.EndsWith("/")) depotPath += "/"; P4RecordSet p4ru = p4con.Run("dirs", depotPath + "*"); p4con.Disconnect(); int nbCl = p4ru.Records.Length; if (nbCl > 0) { string[] ret = new string[nbCl]; for (int i = 0; i < nbCl; i++) { ret[i] = p4ru[i]["dir"].Replace(depotPath, ""); } return ret; } else return null; } } public string[] GetPendingChangelists() { using (P4Connection p4con = CreateConnection()) { try { P4RecordSet p4ru = p4con.Run("changes", "-spending", "-u" + User); p4con.Disconnect(); int nbCl = p4ru.Records.Length; if (nbCl > 0) { string[] ret = new string[nbCl]; for (int i = 0; i < nbCl; i++) { ret[i] = string.Format("{0} {1}", p4ru[i]["change"], p4ru[i]["desc"]); } return ret; } else return null; } catch (Exception e) { return null; } } } P4Connection CreateConnection() { P4Connection p4con = new P4Connection(); p4con.User = User; p4con.Port = Port; p4con.Client = Client; p4con.Connect(); return p4con; } } }