Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ResourcePackList.cs
Go to the documentation of this file.
1using System;
3using System.IO;
4using System.Linq;
5using Newtonsoft.Json;
6using Newtonsoft.Json.Linq;
9
10namespace Terraria.IO;
11
12public class ResourcePackList
13{
14 private struct ResourcePackEntry
15 {
16 public string FileName;
17
18 public bool Enabled;
19
20 public int SortingOrder;
21
22 public ResourcePackEntry(string name, bool enabled, int sortingOrder)
23 {
24 FileName = name;
25 Enabled = enabled;
27 }
28 }
29
31
33 where pack.IsEnabled
34 orderby pack.SortingOrder, pack.Name, pack.Version, pack.FileName
35 select pack;
36
38 where !pack.IsEnabled
39 orderby pack.Name, pack.Version, pack.FileName
40 select pack;
41
43 orderby pack.Name, pack.Version, pack.FileName
44 select pack;
45
47 {
48 }
49
54
55 public JArray ToJson()
56 {
58 list.AddRange(_resourcePacks.Select((ResourcePack pack) => new ResourcePackEntry(pack.FileName, pack.IsEnabled, pack.SortingOrder)));
59 return JArray.FromObject((object)list);
60 }
61
75
87
89 {
91 {
92 if (item2.FileName == null)
93 {
94 continue;
95 }
96 string text = Path.Combine(searchPath, item2.FileName);
97 try
98 {
99 bool flag = File.Exists(text) || Directory.Exists(text);
101 if (!flag && SocialAPI.Workshop != null && SocialAPI.Workshop.TryGetPath(item2.FileName, out var fullPathFound))
102 {
104 flag = true;
105 branding = SocialAPI.Workshop.Branding.ResourcePackBrand;
106 }
107 if (flag)
108 {
110 {
111 IsEnabled = item2.Enabled,
112 SortingOrder = item2.SortingOrder
113 };
115 }
116 }
117 catch (Exception arg)
118 {
119 Console.WriteLine("Failed to read resource pack {0}: {1}", text, arg);
120 }
121 }
122 }
123
125 {
127 foreach (string text in directories)
128 {
129 try
130 {
132 if (resourcePacks.All((ResourcePack pack) => pack.FileName != folderName))
133 {
135 }
136 }
137 catch (Exception arg)
138 {
139 Console.WriteLine("Failed to read resource pack {0}: {1}", text, arg);
140 }
141 }
142 }
143
145 {
146 string[] files = Directory.GetFiles(searchPath, "*.zip");
147 foreach (string text in files)
148 {
149 try
150 {
151 string fileName = Path.GetFileName(text);
152 if (resourcePacks.All((ResourcePack pack) => pack.FileName != fileName))
153 {
155 }
156 }
157 catch (Exception arg)
158 {
159 Console.WriteLine("Failed to read resource pack {0}: {1}", text, arg);
160 }
161 }
162 }
163
165 {
167 if (workshop == null)
168 {
169 return;
170 }
171 List<string> listOfSubscribedResourcePackPaths = workshop.GetListOfSubscribedResourcePackPaths();
172 ResourcePack.BrandingType resourcePackBrand = workshop.Branding.ResourcePackBrand;
173 foreach (string item in listOfSubscribedResourcePackPaths)
174 {
175 try
176 {
178 if (resourcePacks.All((ResourcePack pack) => pack.FileName != folderName))
179 {
181 }
182 }
183 catch (Exception arg)
184 {
185 Console.WriteLine("Failed to read resource pack {0}: {1}", item, arg);
186 }
187 }
188 }
189
191 {
192 //IL_0017: Expected O, but got Unknown
193 try
194 {
195 if (serializedState != null && ((JContainer)serializedState).Count != 0)
196 {
197 return ((JToken)serializedState).ToObject<List<ResourcePackEntry>>();
198 }
199 }
200 catch (JsonReaderException val)
201 {
202 JsonReaderException arg = val;
203 Console.WriteLine("Failed to parse configuration entry for resource pack list. {0}", arg);
204 }
205 return new List<ResourcePackEntry>();
206 }
207}
void Add(TKey key, TValue value)
void AddRange(IEnumerable< T > collection)
Definition List.cs:275
static void WriteLine()
Definition Console.cs:733
static string[] GetDirectories(string path)
Definition Directory.cs:156
static string[] GetFiles(string path)
Definition Directory.cs:136
static bool Exists([NotNullWhen(true)] string? path)
Definition Directory.cs:43
static bool Exists([NotNullWhen(true)] string? path)
Definition File.cs:97
static string Combine(string path1, string path2)
Definition Path.cs:304
static ? string GetFileName(string? path)
Definition Path.cs:200
static void CreatePacksFromZips(IServiceProvider services, string searchPath, List< ResourcePack > resourcePacks)
IEnumerable< ResourcePack > pack.pack.pack.FileName select pack
static ResourcePackList FromJson(JArray serializedState, IServiceProvider services, string searchPath)
IEnumerable< ResourcePack > DisabledPacks
static IEnumerable< ResourcePackEntry > CreatePackEntryListFromJson(JArray serializedState)
static void CreatePacksFromSavedJson(JArray serializedState, IServiceProvider services, string searchPath, List< ResourcePack > resourcePacks)
IEnumerable< ResourcePack > AllPacks
static ResourcePackList Publishable(JArray serializedState, IServiceProvider services, string searchPath)
ResourcePackList(IEnumerable< ResourcePack > resourcePacks)
IEnumerable< ResourcePack > pack.pack.FileName select pack
static void CreatePacksFromWorkshopFolders(IServiceProvider services, List< ResourcePack > resourcePacks)
static void CreatePacksFromDirectories(IServiceProvider services, string searchPath, List< ResourcePack > resourcePacks)
IEnumerable< ResourcePack > EnabledPacks
readonly List< ResourcePack > _resourcePacks
static Terraria.Social.Base.WorkshopSocialModule Workshop
Definition SocialAPI.cs:24
ResourcePackEntry(string name, bool enabled, int sortingOrder)