简体   繁体   English

用c#在树视图中显示perforce的库

[英]show perforce's depot in a treeview with c#

I'm not an expert in P4.NET and I would like to show perforce's depot in a treeview (windowsform application c#)... 我不是P4.NET的专家,我想在树视图中显示perforce的depot(windowsform应用程序c#)......

* "p4 dirs" to get all depots => p4 dirs "//*" for exemple this may give depot1 depot2 ..etc * “p4 dirs”获取所有depots => p4 dirs“// *”例如这可能会给depot1 depot2 ..etc

P4Connection p4 = new P4Connection();
p4.Connect();
P4RecordSet tab1 = p4.Run("dirs","//depot/*"); // to get folders in depot
foreach (P4Record a in tab1 )
{
  richTextBox1.Text += (a["dir"]) + "\n";// show the results in richTextBox

}

* To get a list of files in a directory, run fstat=> p4 fstat "//depot1/*" *要获取目录中的文件列表,请运行fstat => p4 \\ tfstat“// depot1 / *”

P4RecordSet tab2 = p4.Run("fstat","//depot/your_folder/*"); // to get files existing in your_folder
foreach (P4Record b in tab2 )
{
  richTextBox1.Text += (b["depotFile"]) + "\n";// show the results in richTextBox

}

now, how to use this code to build a treeview ? 现在,如何使用此代码构建树视图? Any help would be most welcome 任何帮助都是最受欢迎的

The code below will only support a hardcoded depot, but it wouldn't be hard to extend to look at all depots on a Perforce server by using the "depots" command. 下面的代码只支持硬编码的软件仓库,但是通过使用“depots”命令来查看Perforce服务器上的所有软件仓库并不难。

public void PopulateTreeview()
{
    TreeNode depotNode = new TreeNode("//depot");

    P4Connection p4 = new P4Connection();
    p4.Connect();

    ProcessFolder(p4, "//depot", depotNode);

    treeView.Nodes.Add(depotNode);
}

public void ProcessFolder(P4Connection p4, string folderPath, TreeNode node)
{
    P4RecordSet folders = p4.Run("dirs", folderPath + "/*");
    foreach(P4Record folder in folders)
    {
        string newFolderPath = folder["dir"];
        string[] splitFolderPath = newFolderPath.Split('/');
        string folderName = splitFolderPath[splitFolderPath.Length - 1];

        TreeNode folderNode = new TreeNode(folderName);
        ProcessFolder(p4, newFolderPath, folderNode);

        node.Nodes.Add(folderNode);
    }

    P4RecordSet files = p4.Run("fstat", folderPath + "/*");
    foreach(P4Record file in files)
    {
        string[] splitFilePath = file["depotFile"].Split('/');
        string fileName = splitFilePath[splitFilePath.Length - 1];

        TreeNode fileNode = new TreeNode(fileName);
        node.Nodes.Add(fileNode);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM