Beispiel #1
0
 static void PrintItemStatus(Steamworks.Ugc.Item dependencyItem)
 {
     if (dependencyItem.IsInstalled && dependencyItem.IsSubscribed)
     {
         Write("   INSTALLED   ", ConsoleColor.Black, ConsoleColor.DarkGreen);
         WriteLine($" {dependencyItem.Title}");
     }
     else if (dependencyItem.IsDownloading)
     {
         Write("  DOWNLOADING  ", ConsoleColor.Black, ConsoleColor.Yellow);
         WriteLine($" {dependencyItem.Title}");
     }
     else if (dependencyItem.IsDownloadPending)
     {
         Write("    PENDING    ", ConsoleColor.Black, ConsoleColor.DarkYellow);
         WriteLine($" {dependencyItem.Title}");
     }
     else
     {
         Write(" NOT INSTALLED ", ConsoleColor.White, ConsoleColor.DarkRed);
         WriteLine($" {dependencyItem.Title}");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Will attempt to download this item asyncronously - allowing you to instantly react to its installation
        /// </summary>
        /// <param name="fileId">The ID of the file you want to download</param>
        /// <param name="progress">An optional callback</param>
        /// <param name="ct">Allows you to send a message to cancel the download anywhere during the process</param>
        /// <param name="milisecondsUpdateDelay">How often to call the progress function</param>
        /// <returns>true if downloaded and installed correctly</returns>
        public static async Task <bool> DownloadAsync(PublishedFileId fileId, Action <float> progress = null, int milisecondsUpdateDelay = 60, CancellationToken ct = default)
        {
            var item = new Steamworks.Ugc.Item(fileId);

            if (ct == default)
            {
                ct = new CancellationTokenSource(TimeSpan.FromSeconds(60)).Token;
            }

            progress?.Invoke(0.0f);

            if (Download(fileId, true) == false)
            {
                return(item.IsInstalled);
            }

            // Steam docs about Download:
            // If the return value is true then register and wait
            // for the Callback DownloadItemResult_t before calling
            // GetItemInstallInfo or accessing the workshop item on disk.

            // Wait for DownloadItemResult_t
            {
                Action <Result> onDownloadStarted = null;

                try
                {
                    var downloadStarted = false;

                    onDownloadStarted     = r => downloadStarted = true;
                    OnDownloadItemResult += onDownloadStarted;

                    while (downloadStarted == false)
                    {
                        if (ct.IsCancellationRequested)
                        {
                            break;
                        }

                        await Task.Delay(milisecondsUpdateDelay);
                    }
                }
                finally
                {
                    OnDownloadItemResult -= onDownloadStarted;
                }
            }

            progress?.Invoke(0.2f);
            await Task.Delay(milisecondsUpdateDelay);

            //Wait for downloading completion
            {
                while (true)
                {
                    if (ct.IsCancellationRequested)
                    {
                        break;
                    }

                    progress?.Invoke(0.2f + item.DownloadAmount * 0.8f);

                    if (!item.IsDownloading && item.IsInstalled)
                    {
                        break;
                    }

                    await Task.Delay(milisecondsUpdateDelay);
                }
            }

            progress?.Invoke(1.0f);

            return(item.IsInstalled);
        }
Beispiel #3
0
 static async System.Threading.Tasks.Task LoadModInfoAsync()
 {
     workshopItem = (Steamworks.Ugc.Item) await Steamworks.Ugc.Item.GetAsync(workshopId);
 }