Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
WorkshopSocialModule.cs
Go to the documentation of this file.
2using System.IO;
3using System.Linq;
4using Steamworks;
7using Terraria.IO;
9
10namespace Terraria.Social.Steam;
11
13{
15
17
19
20 private string _contentBaseFolder;
21
22 public override void Initialize()
23 {
24 base.Branding = new WorkshopBranding
25 {
26 ResourcePackBrand = ResourcePack.BrandingType.SteamWorkshop
27 };
29 base.ProgressReporter = new WorkshopProgressReporter(_publisherInstances);
30 base.SupportedTags = new SupportedWorkshopTags();
31 _contentBaseFolder = Main.SavePath + Path.DirectorySeparatorChar + "Workshop";
35 workshopIssueReporter.OnNeedToOpenUI += _issueReporter_OnNeedToOpenUI;
36 workshopIssueReporter.OnNeedToNotifyUI += _issueReporter_OnNeedToNotifyUI;
37 base.IssueReporter = workshopIssueReporter;
38 UIWorkshopHub.OnWorkshopHubMenuOpened += RefreshSubscriptionsAndPublishings;
39 }
40
42 {
43 Main.IssueReporterIndicator.AttemptLettingPlayerKnow();
45 }
46
48 {
50 }
51
52 public override void Shutdown()
53 {
54 }
55
56 public override void LoadEarlyContent()
57 {
59 }
60
62 {
63 _downloader.Refresh(base.IssueReporter);
64 _publishedItems.Refresh();
65 }
66
68 {
69 return _downloader.WorldPaths.Select((string folderPath) => folderPath + Path.DirectorySeparatorChar + "world.wld").ToList();
70 }
71
73 {
74 return _downloader.ResourcePackPaths;
75 }
76
77 public override bool TryGetPath(string pathEnd, out string fullPathFound)
78 {
79 fullPathFound = null;
80 string text = _downloader.ResourcePackPaths.FirstOrDefault((string x) => x.EndsWith(pathEnd));
81 if (text == null)
82 {
83 return false;
84 }
85 fullPathFound = text;
86 return true;
87 }
88
94
95 public override void PublishWorld(WorldFileData world, WorkshopItemPublishSettings settings)
96 {
97 string name = world.Name;
98 string textForWorld = GetTextForWorld(world);
100 string text = GetTemporaryFolderPath() + world.GetFileName(includeExtension: false);
101 if (MakeTemporaryFolder(text))
102 {
105 worldPublisherInstance.PublishContent(_publishedItems, base.IssueReporter, Forget, name, textForWorld, text, settings.PreviewImagePath, settings.Publicity, usedTagsInternalNames);
106 }
107 }
108
109 private string GetTextForWorld(WorldFileData world)
110 {
111 string text = "This is \"";
112 text += world.Name;
113 string text2 = "";
114 text2 = world.WorldSizeX switch
115 {
116 4200 => "small",
117 6400 => "medium",
118 8400 => "large",
119 _ => "custom",
120 };
121 string text3 = "";
122 text3 = world.GameMode switch
123 {
124 3 => "journey",
125 0 => "classic",
126 1 => "expert",
127 2 => "master",
128 _ => "custom",
129 };
130 text = text + "\", a " + text2.ToLower() + " " + text3.ToLower() + " world";
131 text = text + " infected by the " + (world.HasCorruption ? "corruption" : "crimson");
132 if (world.IsHardMode)
133 {
134 text += ", in hardmode";
135 }
136 return text + ".";
137 }
138
140 {
141 if (resourcePack.IsCompressed)
142 {
143 base.IssueReporter.ReportInstantUploadProblem("Workshop.ReportIssue_CannotPublishZips");
144 return;
145 }
146 string name = resourcePack.Name;
147 string text = resourcePack.Description;
148 if (string.IsNullOrWhiteSpace(text))
149 {
150 text = "";
151 }
153 string fullPath = resourcePack.FullPath;
156 resourcePackPublisherInstance.PublishContent(_publishedItems, base.IssueReporter, Forget, name, text, fullPath, settings.PreviewImagePath, settings.Publicity, usedTagsInternalNames);
157 }
158
159 private string GetTemporaryFolderPath()
160 {
161 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
162 ulong steamID = SteamUser.GetSteamID().m_SteamID;
163 return _contentBaseFolder + Path.DirectorySeparatorChar + steamID + Path.DirectorySeparatorChar;
164 }
165
167 {
168 bool result = true;
170 {
171 base.IssueReporter.ReportDelayedUploadProblem("Workshop.ReportIssue_CouldNotCreateTemporaryFolder!");
172 result = false;
173 }
174 return result;
175 }
176
177 public override void ImportDownloadedWorldToLocalSaves(WorldFileData world, string newFileName = null, string newDisplayName = null)
178 {
179 Main.menuMode = 10;
181 }
182
184 {
186 if (base.IssueReporter != null)
187 {
188 list.AddRange(base.IssueReporter.GetReports());
189 }
190 return list;
191 }
192
194 {
195 info = null;
196 string text = GetTemporaryFolderPath() + world.GetFileName(includeExtension: false);
197 if (!Directory.Exists(text))
198 {
199 return false;
200 }
201 if (AWorkshopEntry.TryReadingManifest(text + Path.DirectorySeparatorChar + "workshop.json", out info))
202 {
203 return true;
204 }
205 return false;
206 }
207
209 {
210 info = null;
211 string fullPath = resourcePack.FullPath;
213 {
214 return false;
215 }
217 {
218 return true;
219 }
220 return false;
221 }
222}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static bool Exists([NotNullWhen(true)] string? path)
Definition Directory.cs:43
static readonly char DirectorySeparatorChar
Definition Path.cs:71
string GetFileName(bool includeExtension=true)
Definition FileData.cs:43
void CopyToLocal(string newFileName=null, string newDisplayName=null)
static WorkshopPublishingIndicator WorkshopPublishingIndicator
Definition Main.cs:1880
static IssueReportsIndicator IssueReporterIndicator
Definition Main.cs:1882
static void OpenReportsMenu()
Definition Main.cs:49242
static bool TryReadingManifest(string filePath, out FoundWorkshopEntryInfo info)
override bool TryGetInfoForResourcePack(ResourcePack resourcePack, out FoundWorkshopEntryInfo info)
void Forget(WorkshopHelper.UGCBased.APublisherInstance instance)
override bool TryGetPath(string pathEnd, out string fullPathFound)
WorkshopHelper.UGCBased.Downloader _downloader
override void ImportDownloadedWorldToLocalSaves(WorldFileData world, string newFileName=null, string newDisplayName=null)
override void PublishResourcePack(ResourcePack resourcePack, WorkshopItemPublishSettings settings)
override List< string > GetListOfSubscribedResourcePackPaths()
List< WorkshopHelper.UGCBased.APublisherInstance > _publisherInstances
override void PublishWorld(WorldFileData world, WorkshopItemPublishSettings settings)
bool MakeTemporaryFolder(string temporaryFolderPath)
override List< string > GetListOfSubscribedWorldPaths()
override bool TryGetInfoForWorld(WorldFileData world, out FoundWorkshopEntryInfo info)
WorkshopHelper.UGCBased.PublishedItemsFinder _publishedItems
static bool TryCreatingDirectory(string folderPath)
Definition Utils.cs:754