p4 di-6ren">
gpt4 book ai didi

c# - 使用 C# 在 TreeView 中显示 perforce 的仓库

转载 作者:行者123 更新时间:2023-11-30 18:05:47 24 4
gpt4 key购买 nike

我不是 P4.NET 的专家,我想在 TreeView 中显示 perforce 的仓库(windowsform 应用程序 c#)...

* "p4 dirs"获取所有 depots => p4 dirs "//*"例如这可能会给出仓库1depot2 ..等

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

}

* 要获取目录中的文件列表,请运行 fstat=>p4 fstat "//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

}

现在,如何使用这段代码来构建 TreeView ?欢迎任何帮助

最佳答案

下面的代码将只支持一个硬编码的 depot,但是通过使用“depots”命令不难扩展以查看 Perforce 服务器上的所有 depot。

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);
}
}

关于c# - 使用 C# 在 TreeView 中显示 perforce 的仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com