Skip to content

Commit

Permalink
Revert "Change ACF File to just be deleted and left for regeneration …
Browse files Browse the repository at this point in the history
…each launch"

This reverts commit 9b007c2.
  • Loading branch information
Solxanich committed Sep 6, 2023
1 parent 96e6919 commit 48eb28a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions patches/tModLoader/Terraria/Social/Steam/SteamedWraps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,18 @@ public static void BeginPlaytimeTracking()

internal static void OnGameExitCleanup()
{
// PATH/Steamapps/workshop
string workshopFolder = WorkshopHelper.GetWorkshopFolder(ModLoader.Engine.Steam.TMLAppID_t);
// Steamapps/workshop/appworkshop_1281930.acf
string targetACF = Path.Combine(workshopFolder, $"appworkshop_{ModLoader.Engine.Steam.TMLAppID}.acf");
if (!SteamAvailable) {
CleanupACF();
return;
}

if (SteamClient)
if (SteamClient) {
SteamAPI.Shutdown();
else if (SteamAvailable)
GameServer.Shutdown();

if (!File.Exists(targetACF)) {
Logging.tML.Error($"Unable to locate tmodloader steam acf. Expected path: {targetACF}");
return;
}

File.Delete(targetACF);
GameServer.Shutdown();
CleanupACF();
}

public static uint GetWorkshopItemState(PublishedFileId_t publishId)
Expand Down Expand Up @@ -400,6 +396,18 @@ public static void UninstallWorkshopItem(PublishedFileId_t publishId, string ins

// Remove the files
Directory.Delete(installPath, true);

if (!SteamClient)
// Steam Game Server has to be terminated before the ACF file is modified, so we defer cleanup to end of game likse steam client.
deletedItems.Add(publishId);
}

private static List<PublishedFileId_t> deletedItems = new List<PublishedFileId_t>();

private static void CleanupACF()
{
foreach (var item in deletedItems)
UninstallACF(item);
}

private static void UninstallACF(PublishedFileId_t publishId)
Expand Down

0 comments on commit 48eb28a

Please sign in to comment.