Fixed steam items not being updated correctly

This commit is contained in:
EvilFactory
2023-01-03 17:13:07 -03:00
parent 6de4a1bd09
commit f252fce6ef
@@ -7,6 +7,7 @@ using System.Linq;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using Steamworks.Ugc;
namespace Barotrauma namespace Barotrauma
{ {
@@ -14,7 +15,7 @@ namespace Barotrauma
{ {
private struct WorkshopItemDownload private struct WorkshopItemDownload
{ {
public ulong ID; public Steamworks.Ugc.Item Item;
public string Destination; public string Destination;
public LuaCsAction Callback; public LuaCsAction Callback;
} }
@@ -29,41 +30,41 @@ namespace Barotrauma
private async void DownloadWorkshopItemAsync(WorkshopItemDownload download, bool startDownload = false) private async void DownloadWorkshopItemAsync(WorkshopItemDownload download, bool startDownload = false)
{ {
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(download.ID); if (startDownload)
{
if (!item.HasValue) { return; } SteamManager.Workshop.NukeDownload(download.Item);
SteamUGC.Download(download.Item.Id, true);
itemsBeingDownloaded.Add(download);
}
if (item.Value.IsInstalled) if (download.Item.IsInstalled && Directory.Exists(download.Item.Directory))
{ {
if (download.Callback != null) if (download.Callback != null)
{ {
download.Callback(item); download.Callback(download.Item);
} }
itemsBeingDownloaded.Remove(download); itemsBeingDownloaded.Remove(download);
SaveUtil.CopyFolder(item.Value.Directory, download.Destination, true, true); SaveUtil.CopyFolder(download.Item.Directory, download.Destination, true, true);
return; return;
} }
if (startDownload)
{
SteamUGC.Download(item.Value.Id, true);
}
if (!itemsBeingDownloaded.Contains(download))
{
itemsBeingDownloaded.Add(download);
}
} }
public void DownloadWorkshopItem(ulong id, string destination, LuaCsAction callback) public async void DownloadWorkshopItem(ulong id, string destination, LuaCsAction callback)
{ {
if (!LuaCsFile.IsPathAllowedException(destination)) { return; } if (!LuaCsFile.IsPathAllowedException(destination)) { return; }
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(id);
if (item == null)
{
throw new Exception($"Tried to download invalid workshop item {id}.");
}
DownloadWorkshopItemAsync(new WorkshopItemDownload() DownloadWorkshopItemAsync(new WorkshopItemDownload()
{ {
ID = id, Item = item.Value,
Destination = destination, Destination = destination,
Callback = callback Callback = callback
}, true); }, true);
@@ -71,7 +72,12 @@ namespace Barotrauma
public void DownloadWorkshopItem(Steamworks.Ugc.Item item, string destination, LuaCsAction callback) public void DownloadWorkshopItem(Steamworks.Ugc.Item item, string destination, LuaCsAction callback)
{ {
DownloadWorkshopItem(item.Id.Value, destination, callback); DownloadWorkshopItemAsync(new WorkshopItemDownload()
{
Item = item,
Destination = destination,
Callback = callback
}, true);
} }
public async void GetWorkshopItem(UInt64 id, LuaCsAction callback) public async void GetWorkshopItem(UInt64 id, LuaCsAction callback)
@@ -84,7 +90,7 @@ namespace Barotrauma
{ {
if (itemsBeingDownloaded.Count > 0 && Timing.TotalTime > lastTimeChecked) // SteamUGC.OnDownloadItemResult for some reason doesn't work, so i need to do this stupid thing. if (itemsBeingDownloaded.Count > 0 && Timing.TotalTime > lastTimeChecked) // SteamUGC.OnDownloadItemResult for some reason doesn't work, so i need to do this stupid thing.
{ {
foreach (var item in itemsBeingDownloaded) foreach (var item in itemsBeingDownloaded.ToArray())
{ {
DownloadWorkshopItemAsync(item); DownloadWorkshopItemAsync(item);
} }