Files
SharePermissions/Permissions/multiPath.cs
Patrick Smits 3225a4fd8e - FIX: File browser "This PC" section empy
- FIX: File browser "Path incorrect" error on multiple folders selected
- FIX: File browser allowed addition of incorrect file share paths (will now throw an error when the path does not exist)
- Changed: Some changes to the UI for the file browser (no more dropdown select for "This PC". Instead a "localhost" entry is now added to the tree selection
2026-05-28 12:44:25 +02:00

260 lines
7.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace Permissions
{
public partial class multiPath : Form
{
ArrayList pathList = new ArrayList();
string basePath = @"";
Form1 main = new Form1();
public multiPath()
{
InitializeComponent();
Error_label.Visible = false;
path_panel.Visible = true;
string[] drives = System.IO.Directory.GetLogicalDrives(); // Get local drives
foreach (string str in drives)
{
string strShare = "\\\\localhost\\" + str.Replace(":\\", "$\\"); ;
basePath = strShare;
makeDocumentTree();
}
}
private void cancel_bttn_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void ok_bttn_Click(object sender, EventArgs e)
{
foreach (string checkNode in CheckedNodes(treeView1.Nodes, "fullPath"))
{
pathList.Add(@"\\" + checkNode);
}
Form1.folderList.Clear();
foreach (string i in pathList)
{
Form1.folderList.Add(i);
}
this.DialogResult = DialogResult.OK;
}
public void makeDocumentTree()
{
var locationsSub = new List<string>();
foreach (string d in DirSearch(basePath, true))
{
locationsSub.Add(d);
}
foreach (string f in Form1.folderList)
{
locationsSub.Add(f);
}
PopulateTreeView(treeView1, locationsSub, '\\');
treeView1.Refresh();
}
public delegate void treeviewRefreshCallback();
public void treeviewRefresh()
{
treeView1.Refresh();
}
private void PopulateTreeView(TreeView treeView, IEnumerable<string> paths, char pathSeparator)
{
ArrayList test = new ArrayList();
TreeNode lastNode = null;
string subPathAgg;
foreach (string path in paths)
{
subPathAgg = string.Empty;
foreach (string subPath in path.Split(pathSeparator))
{
if (subPath != "")
{
subPathAgg += subPath + pathSeparator;
TreeNode[] nodes = treeView.Nodes.Find(subPathAgg, true);
if (nodes.Length == 0)
if (lastNode == null)
lastNode = treeView.Nodes.Add(subPathAgg, subPath);
else
lastNode = lastNode.Nodes.Add(subPathAgg, subPath);
else
lastNode = nodes[0];
}
}
}
}
public ArrayList DirSearch(string sDir)
{
ArrayList directories = new ArrayList();
main.updateDebugInfo("Function DirSearch(string " + sDir + ") was called");
directories.Add(sDir);
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
string[] dirCount = sDir.Split('\\');
directories.Add(d);
}
}
catch { }
return directories;
}
public ArrayList DirSearch(string sDir, bool incSub)
{
if (incSub == true)
{
ArrayList directories = new ArrayList();
main.updateDebugInfo("Function DirSearch(string " + sDir + ", bool " + incSub + ") was called");
directories.Add(sDir);
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
string[] dirCount = sDir.Split('\\');
directories.Add(d);
try
{
foreach (string d2 in Directory.GetDirectories(d))
{
directories.Add(d2);
}
}
catch //(InvalidCastException e)
{
//throw (e);
}
}
}
catch //( InvalidCastException e )
{
//throw (e);
}
return directories;
}
else
{
return DirSearch(sDir);
}
}
private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
panel1.Enabled = false;
loading_pnl.Visible = true;
folderScan.RunWorkerAsync(e.Node.FullPath.ToString());
}
private List<String> CheckedNodes(System.Windows.Forms.TreeNodeCollection theNodes, string result)
{
List<String> aResult = new List<String>();
if (theNodes != null)
{
foreach (TreeNode aNode in theNodes)
{
if (aNode.Checked)
{
if (result == "name")
{
aResult.Add(aNode.Text);
}
else if (result == "fullPath")
{
aResult.Add(aNode.FullPath);
}
}
aResult.AddRange(CheckedNodes(aNode.Nodes, result));
}
}
return aResult;
}
private void checkNodes(System.Windows.Forms.TreeNodeCollection theNodes, string result)
{
foreach (TreeNode node in theNodes)
{
if (Form1.folderList.Contains(@"\\" + node.FullPath.ToString()))
{
node.Checked = true;
}
}
}
private void folderScan_DoWork(object sender, DoWorkEventArgs e)
{
var locationsSub = new List<string>();
foreach (string d in DirSearch(@"\\" + e, true))
{
if (d.StartsWith(basePath)) { locationsSub.Add(d); };
}
PopulateTreeView(treeView1, locationsSub, '\\');
treeView1.Invoke(new treeviewRefreshCallback(this.treeviewRefresh));
}
private void folderScan_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
loading_pnl.Visible = false;
panel1.Enabled = true;
}
private void startFrom_select_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void refresh_button_Click(object sender, EventArgs e)
{
if (!Directory.Exists(startFrom_textbox.Text))
{ Error_label.Text = "Invalid path: " + startFrom_textbox.Text; Error_label.Visible = true; }
else
{
Error_label.Text = ""; Error_label.Visible = false;
basePath = startFrom_textbox.Text;
makeDocumentTree();
}
}
}
}