33 {
35 {
36 return;
37 }
38 dict =
new Dictionary<string, Dictionary<string, Item>>();
39 List<string> list = new List<string>();
42 {
43 try
44 {
45 list.AddRange(booklistLoader());
46 }
47 catch (Exception arg)
48 {
49 Debug.LogWarning(
$"#book external booklist loader failed\n{arg}");
50 }
51 }
52 foreach (
string item in list)
53 {
54 DirectoryInfo directoryInfo =
new DirectoryInfo(
item);
55 if (!directoryInfo.Exists)
56 {
57 Debug.LogWarning(
"#book invalid booklist path/" +
item);
58 continue;
59 }
60 string name = directoryInfo.Name;
61 dict.TryAdd(name,
new Dictionary<string, Item>());
62 FileInfo[] files = directoryInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly);
63 foreach (FileInfo fileInfo in files)
64 {
65 using StreamReader streamReader = new StreamReader(fileInfo.FullName);
66 string text = Path.ChangeExtension(fileInfo.Name, null);
67 string text2 = streamReader.ReadLine();
68 int? num = text2?.Length;
69 if (!num.HasValue || num.GetValueOrDefault() <= 0)
70 {
71 Debug.LogWarning(
"#book invalid first line/" +
item);
72 continue;
73 }
74 string[] array = text2.Split(',');
76 {
77 cat = name,
79 author = ((array.Length > 1) ? "nameAuthor".lang(array[1]) : "unknownAuthor".lang()),
80 chance = ((array.Length > 2) ? array[2].ToInt() : 100),
81 skin = ((array.Length > 3) ? array[3].ToInt() : 0),
82 id = text,
83 path = fileInfo.FullName
84 };
85 }
86 }
87 }
static string[] LoadDefaultBookList()
static List< Func< string[]> > booklistLoaders