Fixed steam items not being updated correctly
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Steamworks.Ugc;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace Barotrauma
|
||||
{
|
||||
private struct WorkshopItemDownload
|
||||
{
|
||||
public ulong ID;
|
||||
public Steamworks.Ugc.Item Item;
|
||||
public string Destination;
|
||||
public LuaCsAction Callback;
|
||||
}
|
||||
@@ -29,41 +30,41 @@ namespace Barotrauma
|
||||
|
||||
private async void DownloadWorkshopItemAsync(WorkshopItemDownload download, bool startDownload = false)
|
||||
{
|
||||
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(download.ID);
|
||||
|
||||
if (!item.HasValue) { return; }
|
||||
if (startDownload)
|
||||
{
|
||||
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)
|
||||
{
|
||||
download.Callback(item);
|
||||
download.Callback(download.Item);
|
||||
}
|
||||
|
||||
itemsBeingDownloaded.Remove(download);
|
||||
SaveUtil.CopyFolder(item.Value.Directory, download.Destination, true, true);
|
||||
SaveUtil.CopyFolder(download.Item.Directory, download.Destination, true, true);
|
||||
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; }
|
||||
|
||||
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()
|
||||
{
|
||||
ID = id,
|
||||
Item = item.Value,
|
||||
Destination = destination,
|
||||
Callback = callback
|
||||
}, true);
|
||||
@@ -71,7 +72,12 @@ namespace Barotrauma
|
||||
|
||||
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)
|
||||
@@ -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.
|
||||
{
|
||||
foreach (var item in itemsBeingDownloaded)
|
||||
foreach (var item in itemsBeingDownloaded.ToArray())
|
||||
{
|
||||
DownloadWorkshopItemAsync(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user