Skip to content

Commit fc04c8b

Browse files
committed
Moved DiskUsage to Information page. Changed DirSize Method.
1 parent c305e58 commit fc04c8b

4 files changed

Lines changed: 34 additions & 9 deletions

File tree

WolfLeash/Components/Layout/MainLayout.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
new NavItem { Id = "9", Href = "/clients/paired", IconName = IconName.List, Text = "Paired Clients", ParentId="8"},
8383
new NavItem { Id = "10", Href = "/clients/pairing", IconName = IconName.Plus, Text = "Pairing Requests", ParentId="8"},
8484

85-
new NavItem { Id = "11", Href = "/settings", IconName = IconName.Gear, Text = "Settings" }
85+
new NavItem { Id = "11", Href = "/info", IconName = IconName.ClipboardData, Text = "Information" },
86+
87+
new NavItem { Id = "12", Href = "/settings", IconName = IconName.Gear, Text = "Settings" }
8688
};
8789

8890
return navItems;

WolfLeash/Components/Misc/DiskUsage.razor

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,18 @@
154154
{
155155
try
156156
{
157-
return DirSize(new DirectoryInfo(path)) / (double)1_000_000_000;
157+
158+
return GetDirectorySize(new DirectoryInfo(path)) / (double)1_000_000_000;
158159
}
159160
catch (DirectoryNotFoundException)
160161
{
161162
return 0;
162163
}
163164
}
164165

165-
private static long DirSize(DirectoryInfo d)
166+
/*private static long DirSize(DirectoryInfo d)
166167
{
167-
long size = 0;
168+
long size = 0;
168169
// Add file sizes.
169170
var fis = d.GetFiles();
170171
foreach (var fi in fis)
@@ -175,9 +176,26 @@
175176
var dis = d.GetDirectories();
176177
foreach (var di in dis)
177178
{
178-
size += DirSize(di);
179+
size += DirSize(di);
179180
}
180181
return size;
182+
}*/
183+
184+
private static long GetDirectorySize(DirectoryInfo? directoryInfo, bool recursive = true)
185+
{
186+
var startDirectorySize = default(long);
187+
if (directoryInfo is not { Exists: true })
188+
return startDirectorySize; //Return 0 while Directory does not exist.
189+
190+
//Add size of files in the Current Directory to main size.
191+
foreach (var fileInfo in directoryInfo.GetFiles())
192+
System.Threading.Interlocked.Add(ref startDirectorySize, fileInfo.Length);
193+
194+
if (recursive) //Loop on Sub Direcotries in the Current Directory and Calculate its files size.
195+
System.Threading.Tasks.Parallel.ForEach(directoryInfo.GetDirectories(), (subDirectory) =>
196+
System.Threading.Interlocked.Add(ref startDirectorySize, GetDirectorySize(subDirectory, recursive)));
197+
198+
return startDirectorySize; //Return full Size of this Directory.
181199
}
182200

183201
#endregion Data Preparation

WolfLeash/Components/Pages/Home.razor

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
@page "/"
22

33
<PageTitle>Home</PageTitle>
4-
5-
<h1>Overview</h1>
6-
7-
<DiskUsage />
4+
<h3>Welcome</h3>
85

96
@code
107
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/Info"
2+
<h1>Overview</h1>
3+
4+
<DiskUsage />
5+
6+
@code {
7+
8+
}

0 commit comments

Comments
 (0)