4 using System.Threading;
5 using System.Collections.Generic;
8 using System.Threading.Tasks;
16 private struct WorkshopItemDownload
18 public Steamworks.Ugc.Item
Item;
19 public string Destination;
23 double lastTimeChecked = 0;
24 List<WorkshopItemDownload> itemsBeingDownloaded =
new List<WorkshopItemDownload>();
31 private static void CopyFolder(
string sourceDirName,
string destDirName,
bool copySubDirs,
bool overwriteExisting =
false)
34 DirectoryInfo dir =
new DirectoryInfo(sourceDirName);
38 throw new System.IO.DirectoryNotFoundException(
39 "Source directory does not exist or could not be found: "
43 IEnumerable<DirectoryInfo> dirs = dir.GetDirectories();
45 if (!Directory.Exists(destDirName))
47 Directory.CreateDirectory(destDirName);
51 IEnumerable<FileInfo> files = dir.GetFiles();
52 foreach (FileInfo file
in files)
54 string tempPath = Path.Combine(destDirName, file.Name);
55 if (!overwriteExisting && File.Exists(tempPath)) {
continue; }
56 file.CopyTo(tempPath,
true);
62 foreach (DirectoryInfo subdir
in dirs)
64 string tempPath = Path.Combine(destDirName, subdir.Name);
65 CopyFolder(subdir.FullName, tempPath, copySubDirs, overwriteExisting);
70 private async
void DownloadWorkshopItemAsync(WorkshopItemDownload download,
bool startDownload =
false)
74 SteamManager.Workshop.NukeDownload(download.Item);
75 SteamUGC.Download(download.Item.Id,
true);
76 itemsBeingDownloaded.Add(download);
79 if (download.Item.IsInstalled && Directory.Exists(download.Item.Directory))
81 if (download.Callback !=
null)
83 download.Callback(download.Item);
86 itemsBeingDownloaded.Remove(download);
87 CopyFolder(download.Item.Directory, download.Destination,
true,
true);
97 Option<Steamworks.Ugc.Item> itemOption = await SteamManager.Workshop.GetItem(
id);
99 if (itemOption.TryUnwrap(out Steamworks.Ugc.Item item))
101 DownloadWorkshopItemAsync(
new WorkshopItemDownload()
104 Destination = destination,
110 throw new Exception($
"Tried to download invalid workshop item {id}.");
116 DownloadWorkshopItemAsync(
new WorkshopItemDownload()
119 Destination = destination,
126 Option<Steamworks.Ugc.Item> itemOption = await SteamManager.Workshop.GetItem(
id);
128 if (itemOption.TryUnwrap(out Steamworks.Ugc.Item item))
140 if (itemsBeingDownloaded.Count > 0 && Timing.TotalTime > lastTimeChecked)
142 foreach (var item
in itemsBeingDownloaded.ToArray())
144 DownloadWorkshopItemAsync(item);
147 lastTimeChecked = Timing.TotalTime + 15;
static bool IsPathAllowedException(string path, bool write=true, LuaCsMessageOrigin origin=LuaCsMessageOrigin.Unknown)
async void DownloadWorkshopItem(ulong id, string destination, LuaCsAction callback)
void DownloadWorkshopItem(Steamworks.Ugc.Item item, string destination, LuaCsAction callback)
async void GetWorkshopItem(UInt64 id, LuaCsAction callback)
delegate void LuaCsAction(params object[] args)