使用 C# 在树视图中显示 perforce 的仓库

发布于 2024-10-20 18:40:43 字数 766 浏览 1 评论 0原文

我不是 P4.NET 方面的专家,我想在树视图中显示 perforce 的仓库 (windowsform 应用程序 C#)...

* "p4 dirs" 获取所有仓库 => p4 dirs "//*" 例如,这可能会给出 仓库1 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

}

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

}

现在,如何使用此代码构建树视图?非常欢迎任何帮助

I'm not an expert in P4.NET and I would like to show perforce's depot in a treeview
(windowsform application c#)...

* "p4 dirs" to get all depots => p4 dirs "//*" for exemple this may give
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/*"

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷雾森÷林ヴ 2024-10-27 18:40:44

下面的代码仅支持硬编码的仓库,但使用“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);
    }
}

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.

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文