Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AWorkshopEntry.cs
Go to the documentation of this file.
1using System;
3using System.IO;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6
8
9public abstract class AWorkshopEntry
10{
11 public const int CurrentWorkshopPublishVersion = 1;
12
13 public const string ContentTypeName_World = "World";
14
15 public const string ContentTypeName_ResourcePack = "ResourcePack";
16
17 protected const string HeaderFileName = "Workshop.json";
18
19 protected const string ContentTypeJsonCategoryField = "ContentType";
20
21 protected const string WorkshopPublishedVersionField = "WorkshopPublishedVersion";
22
23 protected const string WorkshopEntryField = "SteamEntryId";
24
25 protected const string TagsField = "Tags";
26
27 protected const string PreviewImageField = "PreviewImagePath";
28
29 protected const string PublictyField = "Publicity";
30
32 {
35 Formatting = (Formatting)1
36 };
37
38 public static string ReadHeader(string jsonText)
39 {
40 JToken val = default(JToken);
41 if (!JObject.Parse(jsonText).TryGetValue("ContentType", ref val))
42 {
43 return null;
44 }
45 return val.ToObject<string>();
46 }
47
48 protected static string CreateHeaderJson(string contentTypeName, ulong workshopEntryId, string[] tags, WorkshopItemPublicSettingId publicity, string previewImagePath)
49 {
50 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
51 new JObject();
53 dictionary["WorkshopPublishedVersion"] = 1;
54 dictionary["ContentType"] = contentTypeName;
55 dictionary["SteamEntryId"] = workshopEntryId;
56 if (tags != null && tags.Length != 0)
57 {
58 dictionary["Tags"] = JArray.FromObject((object)tags);
59 }
60 dictionary["Publicity"] = publicity;
61 return JsonConvert.SerializeObject((object)dictionary, SerializerSettings);
62 }
63
65 {
66 info = null;
67 if (!File.Exists(filePath))
68 {
69 return false;
70 }
71 string text = File.ReadAllText(filePath);
74 if (dictionary == null)
75 {
76 return false;
77 }
78 if (!TryGet<ulong>(dictionary, "SteamEntryId", out info.workshopEntryId))
79 {
80 return false;
81 }
82 if (!TryGet<int>(dictionary, "WorkshopPublishedVersion", out var outputValue))
83 {
84 outputValue = 1;
85 }
86 info.publishedVersion = outputValue;
88 {
89 info.tags = ((JToken)outputValue2).ToObject<string[]>();
90 }
91 if (TryGet<int>(dictionary, "Publicity", out var outputValue3))
92 {
94 }
95 TryGet<string>(dictionary, "PreviewImagePath", out info.previewImagePath);
96 return true;
97 }
98
99 protected static bool TryGet<T>(Dictionary<string, object> dict, string name, out T outputValue)
100 {
101 //IL_0034: Unknown result type (might be due to invalid IL or missing references)
102 //IL_003e: Expected O, but got Unknown
103 outputValue = default(T);
104 try
105 {
106 if (dict.TryGetValue(name, out var value))
107 {
108 if (value is T)
109 {
111 return true;
112 }
113 if (value is JObject)
114 {
115 outputValue = JsonConvert.DeserializeObject<T>(((object)(JObject)value).ToString());
116 return true;
117 }
119 return true;
120 }
121 return false;
122 }
123 catch
124 {
125 return false;
126 }
127 }
128}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
static ? object ChangeType(object? value, TypeCode typeCode)
Definition Convert.cs:229
static bool Exists([NotNullWhen(true)] string? path)
Definition File.cs:97
static string ReadAllText(string path)
Definition File.cs:246
static string CreateHeaderJson(string contentTypeName, ulong workshopEntryId, string[] tags, WorkshopItemPublicSettingId publicity, string previewImagePath)
static readonly JsonSerializerSettings SerializerSettings
static bool TryReadingManifest(string filePath, out FoundWorkshopEntryInfo info)
static string ReadHeader(string jsonText)
static bool TryGet< T >(Dictionary< string, object > dict, string name, out T outputValue)