Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/ContentManagement/ContentPackageManager.cs
1 #nullable enable
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Threading.Tasks;
6 using Barotrauma.IO;
7 using Barotrauma.Steam;
8 
9 namespace Barotrauma
10 {
11  public static partial class ContentPackageManager
12  {
13  public sealed partial class PackageSource : ICollection<ContentPackage>
14  {
15  public string SaveRegularMod(ModProject modProject)
16  {
17  if (modProject.IsCore) { throw new ArgumentException("ModProject must not be a core package"); }
18 
19  string fileListPath = Path.Combine(directory, ToolBox.RemoveInvalidFileNameChars(modProject.Name), ContentPackage.FileListFileName)
20  .CleanUpPathCrossPlatform(correctFilenameCase: false);
21  modProject.Save(fileListPath);
22  Refresh(); EnabledPackages.DisableRemovedMods();
23 
24  return fileListPath;
25  }
26 
27  public RegularPackage GetRegularModByPath(string fileListPath)
28  {
29  return Regular.First(p => p.Path == fileListPath);
30  }
31 
33  {
34  string fileListPath = SaveRegularMod(modProject);
35  var package = GetRegularModByPath(fileListPath);
36  EnabledPackages.EnableRegular(package);
37 
38  return package;
39  }
40  }
41 
42  private static async Task<IEnumerable<Steamworks.Ugc.Item>> EnqueueWorkshopUpdates()
43  {
44  ISet<Steamworks.Ugc.Item> subscribedItems = await SteamManager.Workshop.GetAllSubscribedItems();
45 
46  var needInstalling = subscribedItems.Where(item
47  => !WorkshopPackages.Any(p
48  => p.UgcId.TryUnwrap(out var ugcId)
49  && ugcId is SteamWorkshopId workshopId
50  && item.Id == workshopId.Value
51  && p.InstallTime.TryUnwrap(out var installTime)
52  && item.LatestUpdateTime <= installTime.ToUtcValue()))
53  .ToArray();
54  if (!needInstalling.Any()) { return Enumerable.Empty<Steamworks.Ugc.Item>(); }
55 
56  await Task.WhenAll(
57  needInstalling.Select(SteamManager.Workshop.DownloadModThenEnqueueInstall));
58 
59  return needInstalling;
60  }
61  }
62 }
void Save(string path)
Definition: ModProject.cs:172