Skip to content

Commit b635d81

Browse files
committed
Add Search
1 parent 3ddd8ef commit b635d81

5 files changed

Lines changed: 2774 additions & 2597 deletions

File tree

LazerFilesViewer/FakeDirectory.cs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Http.Headers;
45
using System.Text;
56
using System.Threading.Tasks;
67
using System.Xml.Linq;
@@ -13,14 +14,17 @@ public class FakeDirectory
1314

1415
public string FullName { get; set; }
1516

17+
public string KeyWords { get; set; }
18+
1619
public List<FakeDirectory> ChildDirectories { get; set; }
1720
public List<FakeFile> ChildFiles { get; set; }
18-
public FakeDirectory(string name, string preName)
21+
public FakeDirectory(string name, string preName, string keyWords = "")
1922
{
2023
Name = name;
2124
FullName = preName + "\\" + name;
2225
ChildDirectories = new List<FakeDirectory>();
2326
ChildFiles = new List<FakeFile>();
27+
KeyWords = keyWords;
2428
}
2529

2630
public FakeDirectory? GetDirectory(string name)
@@ -58,11 +62,11 @@ public FakeDirectory(string name, string preName)
5862
return ChildFiles.Find(x => x.Name == name);
5963
}
6064

61-
public FakeDirectory AddDirectory(string name)
65+
public FakeDirectory AddDirectory(string name, string keyWords = "")
6266
{
6367
FakeDirectory? d = GetDirectory(name);
6468
if (d != null) return d;
65-
d = new FakeDirectory(name, FullName);
69+
d = new FakeDirectory(name, FullName, keyWords);
6670
ChildDirectories.Add(d);
6771
return d;
6872
}
@@ -96,7 +100,7 @@ public FakeFile AddFile(string name, string hash)
96100
{
97101
FakeFile? f = GetFile(name);
98102
if (f != null) return f;
99-
f = new FakeFile(name, hash);
103+
f = new FakeFile(name, hash, FullName);
100104
ChildFiles.Add(f);
101105
return f;
102106
}
@@ -110,7 +114,37 @@ public bool DeleteFile(string name)
110114
return true;
111115
}
112116

117+
public List<FakeDirectory> SearchDirectories(string keyWord)
118+
{
119+
if (ChildDirectories.Count <= 0) return new List<FakeDirectory>();
120+
List<FakeDirectory> dirs = ChildDirectories.FindAll(dir => (dir.Name.Contains(keyWord, StringComparison.OrdinalIgnoreCase)) || (dir.KeyWords.Contains(keyWord, StringComparison.OrdinalIgnoreCase)));
121+
foreach (FakeDirectory dir in ChildDirectories)
122+
{
123+
List<FakeDirectory> subdirs = dir.SearchDirectories(keyWord);
124+
if (subdirs != null && subdirs.Count > 0)
125+
{
126+
dirs.AddRange(subdirs);
127+
}
128+
}
129+
return dirs;
130+
}
113131

114-
132+
public List<FakeFile> SearchFiles(string keyWord)
133+
{
134+
List<FakeFile> files = new List<FakeFile> ();
135+
if (ChildFiles.Count > 0) files = ChildFiles.FindAll(file => (file.Name.Contains(keyWord, StringComparison.OrdinalIgnoreCase)));
136+
if (ChildDirectories.Count > 0)
137+
{
138+
foreach (FakeDirectory dir in ChildDirectories)
139+
{
140+
List<FakeFile> subfiles = dir.SearchFiles(keyWord);
141+
if(subfiles != null && subfiles.Count > 0)
142+
{
143+
files.AddRange(subfiles);
144+
}
145+
}
146+
}
147+
return files;
148+
}
115149
}
116150
}

LazerFilesViewer/FakeFile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ namespace LazerFilesViewer
99
public class FakeFile
1010
{
1111
public string Name { get; set; }
12+
public string FullName { get; set; }
1213
public string Hash { get; set; }
13-
public FakeFile(string name, string hash) {
14+
public FakeFile(string name, string hash, string preName) {
1415
Name = name;
1516
Hash = hash;
17+
FullName = preName + "\\" + name;
1618
}
1719

1820
public string GetFileType()

LazerFilesViewer/MainForm.Designer.cs

Lines changed: 30 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)