private void mDepotTreeView_AfterSelect(object sender, TreeViewEventArgs e) { Object obj = mDepotTreeView.SelectedNode.Tag; if (ShowOpenConnectionBtn) { if (obj is P4.FileMetaData) { SelectedFile = mDepotTreeView.SelectedNode.Text.ToString(); string file = SelectedFile.Substring(SelectedFile.LastIndexOf('/') + 1); mSolutionPathTxt.Text = file; } else { mSolutionPathTxt.Text = string.Empty; } } else { if (obj is P4.FileMetaData) { SelectedFile = mDepotTreeView.SelectedNode.Text.ToString(); mSolutionPathTxt.Text = SelectedFile; } else { P4Directory p4Dir = (P4Directory)mDepotTreeView.SelectedNode.Tag; SelectedFile = p4Dir.DepotPath + "/..."; mSolutionPathTxt.Text = SelectedFile; } } }
private void getLatestToolStripMenuItem_Click(object sender, EventArgs e) { IList <P4.FileSpec> filesChanged = new List <FileSpec>(); Object obj = mDepotTreeView.SelectedNode.Tag; Options opts = new P4.SyncFilesCmdOptions( SyncFilesCmdFlags.None, 0); if (obj is P4.FileMetaData) { FileMetaData fmd = obj as FileMetaData; SccService.ScmProvider.SyncFiles(out filesChanged, opts, fmd.DepotPath.Path); } else { P4Directory p4Dir = (P4Directory)mDepotTreeView.SelectedNode.Tag; SccService.ScmProvider.SyncFiles(out filesChanged, opts, p4Dir.DepotPath + "/..."); } }
private void Init(P4ScmProvider scm, Client nWorkspace, String nName, String nDepotPath, String nLocalPath, P4Directory parent) { if (scm == null) { throw new ArgumentNullException("server", Resources.P4Directory_InvalidRepositoryError); } if (String.IsNullOrEmpty(nDepotPath) && String.IsNullOrEmpty(nLocalPath)) { throw new ArgumentNullException("nDepotPath/nLocalPath", Resources.P4Directory_InvalidNullPathError); } _scm = scm; Workspace = nWorkspace; name = nName; depotPath = nDepotPath; localPath = nLocalPath; // We'll determine the unspecified paths when( if) we add files to a // directory, because the server will provide us with enough // information to accurately determine the correct paths, because // depending on the mapping, the structure of the two trees might // differ in the levels between the roots and the first directories // down ith tree containing files. //if( String.IsNullOrEmpty( nLocalPath ) && parent != null && !String.IsNullOrEmpty( parent.LocalPath ) ) //{ // // see if we can determine the local directory if not specified // localPath = String.Format( "{0}/{1}", parent.LocalPath, Path.GetFileName( depotPath ) ); //} //if( String.IsNullOrEmpty( nDepotPath ) && parent != null && !String.IsNullOrEmpty( parent.DepotPath ) ) //{ // // see if we can determine the depot directory if not specified // depotPath = String.Format( "{0}/{1}", parent.DepotPath, Path.GetFileName( localPath ) ); //} parentDirectory = parent; }
private void removeFromToolStripMenuItem_Click(object sender, EventArgs e) { IList <P4.FileSpec> filesChanged = new List <FileSpec>(); Object obj = mDepotTreeView.SelectedNode.Tag; Options opts = new P4.SyncFilesCmdOptions( SyncFilesCmdFlags.None, 0); if (obj is P4.FileMetaData) { FileMetaData fmd = obj as FileMetaData; FileSpec fs = new FileSpec(fmd.DepotPath, null, null, new NoneRevision()); filesChanged.Add(fs); SccService.ScmProvider.SyncFiles(opts, filesChanged); } else { P4Directory p4Dir = (P4Directory)mDepotTreeView.SelectedNode.Tag; FileSpec fs = new FileSpec(new DepotPath(p4Dir.DepotPath + "/..."), null, null, new NoneRevision()); filesChanged.Add(fs); SccService.ScmProvider.SyncFiles(opts, filesChanged); } }
/// <summary> /// Expand the directory by filling in the list of child directories /// and file within the directory. /// </summary> /// <returns>false if an error prevented completion</returns> public bool Expand(bool filtered) { if (String.IsNullOrEmpty(depotPath)) { return(false); } if (_scm.ServerVersion >= Versions.V12_1) { if (!String.IsNullOrEmpty(depotPath)) { IList <string> subdirs = new List <string>(); IList <FileMetaData> fileList = new List <FileMetaData>(); Options options = new Options(); options["-Ol"] = null; options["-D"] = null; options["-F"] = "^headAction=delete & ^headAction=move/delete"; options["-T"] = "depotFile, dir"; if (filtered) { options = new Options(); options["-Ol"] = null; options["-Dlc"] = null; options["-Rc"] = null; options["-F"] = "^headAction=delete & ^headAction=move/delete"; options["-T"] = "depotFile, dir"; } IList <FileMetaData> fmd = _scm.GetFileMetaData(options, DepotPath + "/*"); foreach (FileMetaData f in fmd) { if (f.DepotPath != null) { fileList.Add(f); } if (f.Directory != null) { subdirs.Add(f.Directory); } } if ((subdirs != null) && (subdirs.Count > 0)) { subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs); foreach (P4Directory dir in subdirectories.Values) { dir.InDepot = true; } } if (fileList != null) { files = P4FileMap.FromFstatOutput(fileList); // if the directory contains files from the depot, we can use // the local path of one of those files to determine the local // path for this directory if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0)) { foreach (FileMetaData f in files.Values) { if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path)) { localPath = f.LocalPath.GetDirectoryName(); break; } } } } } } else { // old tree builder using dirs and fstat //***************************************************************************************** // if we have the depot path, get a list of the subdirectories from the depot if (!String.IsNullOrEmpty(depotPath)) { IList <string> subdirs = _scm.GetDepotDirs(null, String.Format("{0}/*", depotPath)); if ((subdirs != null) && (subdirs.Count > 0)) { subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs); foreach (P4Directory dir in subdirectories.Values) { dir.InDepot = true; } } IList <FileMetaData> fileList = _scm.GetFileMetaData(null, String.Format("{0}/*", depotPath)); // get a list of the files in the directory if (fileList != null) { files = P4FileMap.FromFstatOutput(fileList); // if the directory contains files from the depot, we can use // the local path of one of those files to determine the local // path for this directory if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0)) { foreach (FileMetaData f in files.Values) { if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path)) { localPath = f.LocalPath.GetDirectoryName(); break; } } } } } //***************************************************************************************** } // if we have a workspace and a local path, match the files and // subdirectories in the depot with the files in the file system if ((!String.IsNullOrEmpty(localPath)) && (Workspace != null)) { DirectoryInfo[] directoryList = null; FileInfo[] fileList = null; try { DirectoryInfo di = new DirectoryInfo(localPath); directoryList = di.GetDirectories(); fileList = di.GetFiles(); } catch { //LogFile.LogException( "Initializing Directory from Workspace", ex ); } // get the subdirectories listed in the file and match them up // with the one in the list from the depot if ((directoryList != null) && (directoryList.Length > 0)) { foreach (DirectoryInfo di in directoryList) { string itemName = di.Name; if (subdirectories.ContainsKey(itemName)) { subdirectories[itemName].InWorkspace = true; } else { P4Directory subDir = new P4Directory(_scm, Workspace, itemName, null, di.FullName, parentDirectory); subDir.InDepot = false; subDir.InWorkspace = true; subdirectories[itemName] = subDir; } } } // get the files listed in the subdirectory and match them up // with the one in the list from the depot if ((fileList != null) && (fileList.Length > 0)) { foreach (FileInfo fi in fileList) { string itemName = fi.Name; if (files != null && files.ContainsKey(itemName) == false) { FileMetaData file = new FileMetaData(); file.LocalPath = new LocalPath(fi.FullName); file.DepotPath = null; file.FileSize = fi.Length; files[itemName] = file; } } } } return(true); }
/// <summary> /// Create a new P4Directory /// </summary> /// <param name="server">Perforce Server</param> /// <param name="nWorkspace">Active workspace(client), can be null</param> /// <param name="nDepotPath">Full path in the depot, can be null</param> /// <param name="nLocalPath">Full path in the local file system, can be null</param> /// <param name="parent">Parent directory, can be null</param> /// <remarks> /// Either the depot or local path can be null, not both. The file name /// will be taken from the depot path if provided, otherwise from the /// local path /// </remarks> public P4Directory(P4ScmProvider scm, Client nWorkspace, String nDepotPath, String nLocalPath, P4Directory parent) { String nName; if (!String.IsNullOrEmpty(nDepotPath)) { nName = nDepotPath.Substring(nDepotPath.LastIndexOf('/') + 1); } else if (!String.IsNullOrEmpty(nLocalPath)) { nName = nLocalPath.Substring(nLocalPath.LastIndexOf('/') + 1); } else { nName = "????"; } Init(scm, nWorkspace, nName, nDepotPath, nLocalPath, parent); }
/// <summary> /// Create a new P4Directory /// </summary> /// <param name="server">Perforce Server</param> /// <param name="nWorkspace">Active workspace(client), can be null</param> /// <param name="nName">The name of the directory</param> /// <param name="nDepotPath">Full path in the depot, can be null</param> /// <param name="nLocalPath">Full path in the local file system, can be null</param> /// <param name="parent">Parent directory, can be null</param> /// <remarks> /// Either the depot or local path can be null, not both. /// </remarks> public P4Directory(P4ScmProvider scm, Client nWorkspace, String nName, String nDepotPath, String nLocalPath, P4Directory parent) { Init(scm, nWorkspace, nName, nDepotPath, nLocalPath, parent); }
public void Init() { envCB.Checked = UseEnvConnect; filterCB.Visible = true; filterCB.Enabled = true; if (ShowOpenConnectionBtn) { filterCB.Checked = Preferences.LocalSettings.GetBool("DepotPathDlg.FilterCB.Checked", true); } else { filterCB.Checked = true; filterCB.Enabled = false; OpenConnectionBtn.Visible = false; OpenConnectionBtn.Enabled = false; } if (SccService.ScmProvider == null || SccService.ScmProvider.Connected == false || string.IsNullOrEmpty(SccService.ScmProvider.Connection.Workspace)) { connectionLbl.Text = string.Format(Resources.DepotPathDlg_NoConnection); mDepotTreeView.Nodes.Clear(); mDepotTreeView.Enabled = false; return; } if ((SccService.ScmProvider.Connection.Disconnected != true) && (SccService.ScmProvider.ServerVersion != null) && (SccService.ScmProvider.ServerVersion < Versions.V12_1)) { filterCB.Visible = false; filterCB.Enabled = false; } mDepotTreeView.Nodes.Clear(); connectionLbl.Text = string.Format(Resources.DepotPathDlg_Connection, SccService.ScmProvider.Connection.Port + ", " + SccService.ScmProvider.Connection.User + ", " + SccService.ScmProvider.Connection.Workspace); IList <P4.Depot> depots = SccService.ScmProvider.GetDepots(); if (depots != null) { foreach (P4.Depot depot in depots) { if (!(depot.Type == DepotType.Local) && !(depot.Type == DepotType.Stream)) { continue; } if (filterCB.Checked) { bool inView = false; ViewMap vm = SccService.ScmProvider.Connection.Repository.Connection.Client.ViewMap; foreach (MapEntry m in vm) { if (m.Left.Path.Contains(string.Format("//{0}/", depot.Id))) { inView = true; break; } } if (!inView) { continue; } } int badIdx = depot.Id.IndexOf('\\'); // Initialize the depot tree view P4Directory root = new P4Directory(SccService.ScmProvider, null, depot.Id, string.Format("//{0}", depot.Id), null, null); TreeNode rootNode = new TreeNode(depot.Id); rootNode.Tag = root; rootNode.ImageIndex = 0; rootNode.SelectedImageIndex = 0; if (depot.Type == DepotType.Stream) { rootNode.ImageIndex = 3; rootNode.SelectedImageIndex = 3; } if (badIdx >= 0) { rootNode.Text += "(*)"; rootNode.ForeColor = Color.Red; } else { rootNode.Nodes.Add(new TreeNode("empty")); } mDepotTreeView.Nodes.Add(rootNode); } mDepotTreeView.Enabled = true; } }
private void mDepotTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) { // insanity check, should never be null if (e.Node == null) { e.Cancel = true; return; } try { TreeNode node = e.Node; // clear any old data node.Nodes.Clear(); P4Directory p4Dir = (P4Directory)node.Tag; char[] bad = Path.GetInvalidPathChars(); int badIdx = p4Dir.DepotPath.IndexOfAny(bad); if (filterCB.Checked) { if (String.IsNullOrEmpty(p4Dir.DepotPath) || (p4Dir.DepotPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) || !p4Dir.Expand(true)) { e.Cancel = true; return; } } else if (String.IsNullOrEmpty(p4Dir.DepotPath) || (p4Dir.DepotPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) || !p4Dir.Expand(false)) { e.Cancel = true; return; } if ((p4Dir.Subdirectories != null) && (p4Dir.Subdirectories.Count > 0)) { foreach (P4Directory p4SubDir in p4Dir.Subdirectories) { if (!p4SubDir.InDepot) { continue; } TreeNode child = new TreeNode(p4SubDir.Name); child.Tag = p4SubDir; child.ImageIndex = 1; child.SelectedImageIndex = 1; child.Nodes.Add(new TreeNode("<empty>")); e.Node.Nodes.Add(child); } } if ((p4Dir.Files != null) && (p4Dir.Files.Count > 0)) { foreach (P4.FileMetaData file in p4Dir.Files) { try { if (ShowOpenConnectionBtn) { string ext = Path.GetExtension(file.DepotPath.Path); if (ext != null && ((ext == ".sln") || ext.Contains("proj") || ext.Contains("proj"))) { TreeNode child = new TreeNode(file.DepotPath.Path); child.Tag = file; child.ImageIndex = 2; child.SelectedImageIndex = 2; e.Node.Nodes.Add(child); } } else { { TreeNode child = new TreeNode(file.DepotPath.Path); child.Tag = file; child.ImageIndex = 2; child.SelectedImageIndex = 2; e.Node.Nodes.Add(child); } } } catch (Exception ex) { logger.Trace("Error in file name, {0}: {1}\r\n\t{2}", file.DepotPath.Path, ex.Message, ex.StackTrace); } } } } catch { } }