-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFilesTabPage.cs
100 lines (87 loc) · 2.48 KB
/
FilesTabPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using Lucene.Net.Store;
namespace Lucene.Net.LukeNet
{
[System.ComponentModel.ToolboxItem(true)]
public partial class FilesTabPage : TabPage
{
public FilesTabPage()
{
InitializeComponent();
}
public FilesTabPage(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void ShowFiles(FSDirectory dir)
{
String[] files = dir.ListAll();
listIndexFiles.Items.Clear();
foreach (string file in files)
{
// FileInfo fi = new FileInfo(file);
ListViewItem row = new ListViewItem(
new string[]
{
file, //fi.Name,
NormalizeSize(dir.FileLength(file)),
NormalizeUnit(dir.FileLength(file))
});
listIndexFiles.Items.Add(row);
}
long totalFileSize = CalcTotalFileSize(dir);
lblFileSize.Text = NormalizeSize(totalFileSize) + NormalizeUnit(totalFileSize);
}
public static long CalcTotalFileSize(FSDirectory dir)
{
long totalFileSize = 0;
foreach (string file in dir.ListAll())
{
totalFileSize += dir.FileLength(file);
// FileInfo fi = new FileInfo(file);
// totalFileSize += fi.Length;
}
return totalFileSize;
}
public static String NormalizeUnit(long len)
{
if (len == 1)
{
return "Byte";
}
else if (len < 1024)
{
return "Bytes";
}
else if (len < 51200000)
{
return "Kb";
}
else
{
return "Mb";
}
}
public static String NormalizeSize(long len)
{
if (len < 1024)
{
return len.ToString();
}
else if (len < 51200000)
{
return ((long)(len / 1024)).ToString();
}
else
{
return ((long)(len / 102400)).ToString();
}
}
}
}