Skip to content

Commit

Permalink
Forwards compatibility? fix for version metadata change (#2859)
Browse files Browse the repository at this point in the history
  • Loading branch information
Solxanich authored Aug 21, 2022
1 parent 877fb72 commit 1dd652f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
30 changes: 18 additions & 12 deletions patches/tModLoader/Terraria/Social/Steam/WorkshopHelper.TML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Terraria.Social.Steam
{
public partial class WorkshopHelper
{
internal static string[] MetadataKeys = new string[7] { "name", "author", "modside", "homepage", "modloaderversion", "version", "modreferences" };
internal static string[] MetadataKeys = new string[8] { "name", "author", "modside", "homepage", "modloaderversion", "version", "modreferences", "versionsummary" };
private static readonly Regex MetadataInDescriptionFallbackRegex = new Regex(@"\[quote=GithubActions\(Don't Modify\)\]Version Summary: (.*) \[/quote\]", RegexOptions.Compiled);

public class ModPublisherInstance : UGCBased.APublisherInstance
Expand Down Expand Up @@ -270,12 +270,13 @@ internal static bool CheckWorkshopConnection() {
return Items.Count + IncompleteModCount != 0;
}

private static System.Version CalculateRelevantVersion(string mbDescription, string mbVersionSummary) {
System.Version selectVersion = new(0, 0);
if (!mbVersionSummary.Contains(':'))
return new System.Version(mbVersionSummary.Replace("v", ""));
private static (System.Version modV, string tmlV) CalculateRelevantVersion(string mbDescription, NameValueCollection metadata) {
(System.Version modV, string tmlV) selectVersion = new (new System.Version(metadata["version"].Replace("v", "")), metadata["modloaderversion"]);
// Backwards compat after metadata version change
if (!metadata["versionsummary"].Contains(':'))
return selectVersion;

InnerCalculateRelevantVersion(ref selectVersion, mbVersionSummary);
InnerCalculateRelevantVersion(ref selectVersion, metadata["versionsummary"]);

// Handle Github Actions metadata from description
// Nominal string: [quote=GithubActions(Don't Modify)]Version Summary: YYYY.MM:#.#.#.#;YYYY.MM:#.#.#.#;... [/quote]
Expand All @@ -288,10 +289,11 @@ private static System.Version CalculateRelevantVersion(string mbDescription, str
}

// This and VersionSummaryToArray need a refactor for cleaner code. Not bad for now
private static void InnerCalculateRelevantVersion(ref System.Version selectVersion, string versionSummary) {
private static void InnerCalculateRelevantVersion(ref (System.Version modV, string tmlV) selectVersion, string versionSummary) {
foreach (var item in VersionSummaryToArray(versionSummary)) {
if (selectVersion < item.modVersion && BuildInfo.tMLVersion.MajorMinor() >= item.tmlVersion.MajorMinor()) {
selectVersion = item.modVersion;
if (selectVersion.modV < item.modVersion && BuildInfo.tMLVersion.MajorMinor() >= item.tmlVersion.MajorMinor()) {
selectVersion.modV = item.modVersion;
selectVersion.tmlV = item.tmlVersion.MajorMinor().ToString();
}
}
}
Expand Down Expand Up @@ -413,6 +415,10 @@ private void ProcessPageResult() {
// Item Tagged data
SteamedWraps.FetchMetadata(_primaryUGCHandle, i, out var metadata);

// Backwards compat code for the metadata version change
if (metadata["versionsumamry"] == null)
metadata["versionsummary"] = metadata["version"];

string[] missingKeys = MetadataKeys.Where(k => metadata.Get(k) == null).ToArray();

if (missingKeys.Length != 0) {
Expand All @@ -430,7 +436,7 @@ private void ProcessPageResult() {
// Partial Description - we don't include Long Description so this is only first handful of characters
string description = pDetails.m_rgchDescription;

var cVersion = CalculateRelevantVersion(description, metadata["version"]);
var cVersion = CalculateRelevantVersion(description, metadata);

// Assign ModSide Enum
ModSide modside = ModSide.Both;
Expand All @@ -455,12 +461,12 @@ private void ProcessPageResult() {
bool updateIsDowngrade = false;

var installed = InstalledMods.FirstOrDefault(m => m.Name == metadata["name"]);
bool update = installed != null && DoesWorkshopItemNeedUpdate(id, installed, cVersion);
bool update = installed != null && DoesWorkshopItemNeedUpdate(id, installed, cVersion.modV);

// The below line is to identify the transient state where it isn't installed, but Steam considers it as such
bool needsRestart = installed == null && SteamedWraps.IsWorkshopItemInstalled(id);

Items.Add(new ModDownloadItem(displayname, metadata["name"], cVersion.ToString(), metadata["author"], metadata["modreferences"], modside, modIconURL, id.m_PublishedFileId.ToString(), (int)downloads, (int)hot, lastUpdate, update, updateIsDowngrade, installed, metadata["modloaderversion"], metadata["homepage"], needsRestart));
Items.Add(new ModDownloadItem(displayname, metadata["name"], cVersion.ToString(), metadata["author"], metadata["modreferences"], modside, modIconURL, id.m_PublishedFileId.ToString(), (int)downloads, (int)hot, lastUpdate, update, updateIsDowngrade, installed, cVersion.tmlV, metadata["homepage"], needsRestart));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,24 @@
SteamUGC.SetItemDescription(uGCUpdateHandle_t, _entryData.Description);

SteamUGC.SetItemContent(uGCUpdateHandle_t, _entryData.ContentFolderPath);
@@ -253,21 +_,65 @@
@@ -253,21 +_,68 @@
if (_entryData.Visibility.HasValue)
SteamUGC.SetItemVisibility(uGCUpdateHandle_t, _entryData.Visibility.Value);

+ SteamUGC.SetItemUpdateLanguage(uGCUpdateHandle_t, SteamedWraps.GetCurrentSteamLangKey());
+
+ string patchNotes = "";
+
+ // Needed for backwards compat on version metadata change
+ _entryData.BuildData["version"] = "0.0.0";
+
+ if (_entryData.BuildData != null) {
+ foreach (var key in MetadataKeys) {
+ SteamUGC.RemoveItemKeyValueTags(uGCUpdateHandle_t, key);
+ SteamUGC.AddItemKeyValueTag(uGCUpdateHandle_t, key, _entryData.BuildData[key]);
+ }
+
+ patchNotes = $"Version {_entryData.BuildData["version"]} has been published to {BuildInfo.Purpose} learn more @ {_entryData.BuildData["homepage"]}\n{_entryData.ChangeNotes}";
+ patchNotes = $"Version {_entryData.BuildData["trueversion"]} has been published to {BuildInfo.Purpose} learn more @ {_entryData.BuildData["homepage"]}\n{_entryData.ChangeNotes}";
+
+ string refs = _entryData.BuildData["workshopdeps"];
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public override bool PublishMod(TmodFile modFile, NameValueCollection buildData,
ulong currPublishID = 0;
string workshopFolderPath = GetTemporaryFolderPath() + modFile.Name;
buildData["versionsummary"] = $"{buildData["modloaderversion"]}:{buildData["version"]}";
// Needed for backwards compat from previous version metadata
buildData["trueversion"] = buildData["version"];

if (existing != null) {
currPublishID = ulong.Parse(existing.PublishId);
Expand Down

0 comments on commit 1dd652f

Please sign in to comment.