Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SearchContext.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4
5public class SearchContext
6{
7 public class Item
8 {
9 public string idFile;
10
11 public string idTopic;
12
13 public string text;
14
15 public string textSearch;
16
17 public bool system;
18 }
19
20 public static int MaxItem = 50;
21
22 public List<Item> items = new List<Item>();
23
24 public List<Item> result = new List<Item>();
25
26 public void Init()
27 {
28 FileInfo[] files = new DirectoryInfo(CorePath.CorePackage.Help).GetFiles();
29 foreach (FileInfo fileInfo in files)
30 {
31 if (fileInfo.Extension != ".txt" || fileInfo.Name == "_topics.txt" || fileInfo.Name == "include.txt")
32 {
33 continue;
34 }
35 string[] array = IO.LoadTextArray(fileInfo.FullName);
36 string idFile = fileInfo.Name.Replace(".txt", "");
37 string idTopic = "";
38 string[] array2 = array;
39 foreach (string text in array2)
40 {
41 if (text.Length == 0 || text.IsEmpty() || text == Environment.NewLine)
42 {
43 continue;
44 }
45 if (text[0] == '$')
46 {
47 idTopic = text.Replace("$", "");
48 continue;
49 }
50 bool flag = false;
51 if (text[0] == '{')
52 {
53 if (text.Length < 6)
54 {
55 continue;
56 }
57 switch (text.Substring(0, 3))
58 {
59 case "{A|":
60 case "{Q|":
61 flag = true;
62 break;
63 case "{pa":
64 break;
65 default:
66 continue;
67 }
68 }
69 Item item = new Item();
70 if (flag)
71 {
72 item.textSearch = (item.text = text.Split('|')[1].Replace("}", "")).ToLower();
73 }
74 else
75 {
76 item.text = text;
77 item.textSearch = text.ToLower();
78 }
79 item.idFile = idFile;
80 item.idTopic = idTopic;
81 items.Add(item);
82 }
83 }
84 }
85
86 public List<Item> Search(string s)
87 {
88 result.Clear();
89 int num = 0;
90 string value = s.ToLower();
91 foreach (Item item in items)
92 {
93 if (item.textSearch.Contains(value))
94 {
95 result.Add(item);
96 num++;
97 if (num >= MaxItem)
98 {
99 result.Add(new Item
100 {
101 system = true,
102 text = "maxResult".lang()
103 });
104 break;
105 }
106 }
107 }
108 if (result.Count == 0)
109 {
110 result.Add(new Item
111 {
112 system = true,
113 text = "noResult".lang()
114 });
115 }
116 return result;
117 }
118}
static string Help
Definition: CorePath.cs:75
List< Item > Search(string s)
List< Item > result
List< Item > items
static int MaxItem