Skip to content

Commit 3ac954a

Browse files
committed
Added "AddFolder" property
1 parent fb2ac46 commit 3ac954a

File tree

2 files changed

+74
-13
lines changed

2 files changed

+74
-13
lines changed
278 Bytes
Binary file not shown.
Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.IO;
31
using System.Net;
42
using Peakboard.ExtensionKit;
53

@@ -19,42 +17,105 @@ protected override CustomListDefinition GetDefinitionOverride()
1917
PropertyInputDefaults = {
2018
new CustomListPropertyDefinition(){ Name = "Domain", Value = "domain"},
2119
new CustomListPropertyDefinition(){ Name = "User", Value = "johndoe"},
22-
new CustomListPropertyDefinition(){ Name = "Password", Masked = true},
20+
new CustomListPropertyDefinition(){ Name = "Password", TypeDefinition = new CustomListPropertyStringTypeDefinition() { Masked = true } },
2321
new CustomListPropertyDefinition(){ Name = "UNCFolder", Value = @"\\server\folder"},
24-
new CustomListPropertyDefinition(){ Name = "CheckSubfolders", Value = "False", TypeDefinition = new CustomListPropertyBooleanTypeDefinition()}
22+
new CustomListPropertyDefinition(){ Name = "CheckSubfolders", Value = "False", TypeDefinition = new CustomListPropertyBooleanTypeDefinition()},
23+
new CustomListPropertyDefinition(){ Name = "AddFolders", Value = "False", TypeDefinition = new CustomListPropertyBooleanTypeDefinition()}
2524
}
2625
};
2726
}
2827

2928
protected override CustomListColumnCollection GetColumnsOverride(CustomListData data)
3029
{
31-
return new CustomListColumnCollection
30+
data.Properties.TryGetValue("AddFolders", out var addFolders);
31+
32+
if (addFolders == "True")
3233
{
33-
new CustomListColumn("Path", CustomListColumnTypes.String),
34-
new CustomListColumn("Name", CustomListColumnTypes.String),
35-
new CustomListColumn("LastModified", CustomListColumnTypes.String),
36-
};
34+
return new CustomListColumnCollection
35+
{
36+
new CustomListColumn("Path", CustomListColumnTypes.String),
37+
new CustomListColumn("Name", CustomListColumnTypes.String),
38+
new CustomListColumn("LastModified", CustomListColumnTypes.String),
39+
new CustomListColumn("IsFolder", CustomListColumnTypes.Boolean),
40+
};
41+
}
42+
else
43+
{
44+
return new CustomListColumnCollection
45+
{
46+
new CustomListColumn("Path", CustomListColumnTypes.String),
47+
new CustomListColumn("Name", CustomListColumnTypes.String),
48+
new CustomListColumn("LastModified", CustomListColumnTypes.String),
49+
};
50+
}
3751
}
3852

3953
protected override CustomListObjectElementCollection GetItemsOverride(CustomListData data)
4054
{
4155
var items = new CustomListObjectElementCollection();
56+
4257
data.Properties.TryGetValue("UNCFolder", out var folder);
4358
data.Properties.TryGetValue("User", out var user);
4459
data.Properties.TryGetValue("Password", out var password);
4560
data.Properties.TryGetValue("Domain", out var domain);
4661
data.Properties.TryGetValue("CheckSubfolders", out var checkSubfolders);
62+
data.Properties.TryGetValue("AddFolders", out var addFolders);
63+
64+
var includeSubfolders = string.Equals(checkSubfolders, "True", StringComparison.OrdinalIgnoreCase);
65+
var includeFolders = string.Equals(addFolders, "True", StringComparison.OrdinalIgnoreCase);
66+
4767
var credentials = new NetworkCredential(user, password, domain);
4868

4969
using (var nc = new NetworkConnection(folder, credentials))
5070
{
51-
foreach (var file in Directory.GetFiles(nc.NetworkName, "*", checkSubfolders == "True" ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
71+
var root = nc.NetworkName.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
72+
AddFolderContent(items, root, includeSubfolders, includeFolders);
73+
}
74+
75+
return items;
76+
}
77+
78+
private void AddFolderContent(CustomListObjectElementCollection items, string folderPath, bool includeSubfolders, bool includeFolders)
79+
{
80+
if (includeFolders)
81+
{
82+
var folderName = Path.GetFileName(folderPath);
83+
84+
var obj = new CustomListObjectElement
85+
{
86+
{ "Path", folderPath },
87+
{ "Name", folderName },
88+
{ "LastModified", string.Empty }
89+
};
90+
91+
obj.Add("IsFolder", true);
92+
93+
items.Add(obj);
94+
}
95+
96+
if (includeSubfolders)
97+
{
98+
foreach (var subFolder in Directory.GetDirectories(folderPath, "*", SearchOption.TopDirectoryOnly))
5299
{
53-
var modified = File.GetLastWriteTime(file);
54-
items.Add(new CustomListObjectElement() { { "Path", file }, { "Name", Path.GetFileName(file) }, { "LastModified", modified.ToString("yyyyMMddHHmmss") } });
100+
AddFolderContent(items, subFolder, includeSubfolders, includeFolders);
55101
}
56102
}
57103

58-
return items;
104+
foreach (var file in Directory.GetFiles(folderPath, "*", SearchOption.TopDirectoryOnly))
105+
{
106+
var modified = File.GetLastWriteTime(file);
107+
108+
var obj = new CustomListObjectElement
109+
{
110+
{ "Path", file },
111+
{ "Name", Path.GetFileName(file) },
112+
{ "LastModified", modified.ToString("yyyyMMddHHmmss") }
113+
};
114+
115+
if (includeFolders)
116+
obj.Add("IsFolder", false);
117+
118+
items.Add(obj);
119+
}
59120
}
60121
}

0 commit comments

Comments
 (0)