예제 #1
0
        public static async Task <byte[]> UGCDownload(PublishedFileId fileId, uint priority = 1)
        {
            var ugc = new Data.Ugc();

            ugc.Handle.Value = fileId;
            var r = await Internal.UGCDownload(ugc.Handle, priority);

            if (!r.HasValue)
            {
                return(null);
            }

            var size = r.Value.SizeInBytes;

            if (size <= 0)
            {
                return(null);
            }
            var buffer = new byte[size];

            unsafe
            {
                fixed(byte *ptr = buffer)
                {
                    var uh2 = new Data.Ugc();

                    uh2.Handle.Value = r.Value.File;
                    var readsize = Internal.UGCRead(uh2.Handle, (IntPtr)ptr, size, 0, UGCReadAction.ontinueReadingUntilFinished);

                    return(buffer);
                }
            }
        }
예제 #2
0
        public static async Task <bool> DeleteFileAsync(PublishedFileId fileId)
        {
            bool flag;
            DeleteItemResult_t?nullable = await SteamUGC.Internal.DeleteItem(fileId);

            DeleteItemResult_t?nullable1 = nullable;

            nullable = null;
            ref Nullable nullablePointer = ref nullable1;
예제 #3
0
        /// <summary>
        /// <para> get info about currently installed content on disc for items that have EItemStateInstalled set</para>
        /// <para> if EItemStateLegacyItem is set, directoryPath contains the path to the legacy file itself (not a folder)</para>
        /// </summary>
        public static bool GetItemInstallInfo(PublishedFileId fileId, out ulong sizeOnDisk, out string directoryPath, uint directorySize, out uint timeStamp)
        {
            InteropHelp.TestIfAvailableClient();
            var folder2 = Marshal.AllocHGlobal((int)directorySize);
            var ret     = NativeMethods.ISteamUGC_GetItemInstallInfo(fileId, out sizeOnDisk, folder2, directorySize, out timeStamp);

            directoryPath = ret ? InteropHelp.PtrToStringUTF8(folder2) : null;
            Marshal.FreeHGlobal(folder2);
            return(ret);
        }
        /// <summary>
        /// <para> get info about currently installed content on disc for items that have EItemStateInstalled set</para>
        /// <para> if EItemStateLegacyItem is set, Folder contains the path to the legacy file itself (not a folder)</para>
        /// </summary>
        public static bool GetItemInstallInfo(PublishedFileId fileId, out ulong punSizeOnDisk, out string Folder, uint FolderSize, out uint punTimeStamp)
        {
            InteropHelp.TestIfAvailableGameServer();
            var Folder2 = Marshal.AllocHGlobal((int)FolderSize);
            var ret     = NativeMethods.ISteamGameServerUGC_GetItemInstallInfo(fileId, out punSizeOnDisk, Folder2, FolderSize, out punTimeStamp);

            Folder = ret ? InteropHelp.PtrToStringUTF8(Folder2) : null;
            Marshal.FreeHGlobal(Folder2);
            return(ret);
        }
예제 #5
0
        /// <summary>
        /// Get's all the available info about the PublishedFieldId and if it exists locally.
        /// </summary>
        /// <param name="item">Item to get details for</param>
        /// <returns>Details</returns>
        public static Task <SteamUGCRequestUGCDetailsResult> GetItemDetailsAsync(PublishedFileId item)
        {
            var tcs  = new TaskCompletionSource <SteamUGCRequestUGCDetailsResult>();
            var call = RequestUGCDetails(item, 0);
            var detailRequestResult = new CallResult <SteamUGCRequestUGCDetailsResult>();

            detailRequestResult.Set(call, (a, d) =>
            {
                tcs.SetResult(a);
            });
            return(tcs.Task);
        }
예제 #6
0
        public async Task CreateAndThenEditFile()
        {
            PublishedFileId fileid = default;

            //
            // Make a file
            //
            {
                var result = await Ugc.Editor.NewCommunityFile
                             .WithTitle("Unedited File")
                             .SubmitAsync();

                Assert.IsTrue(result.Success);
                Assert.AreNotEqual(result.FileId.Value, 0);

                fileid = result.FileId;
            }

            await Task.Delay(1000);

            //
            // Edit it
            //
            {
                var editor = new Ugc.Editor(fileid);
                editor = editor.WithTitle("An Edited File");
                var result = await editor.SubmitAsync();

                Assert.IsTrue(result.Success);
                Assert.AreEqual(result.FileId, fileid);
            }

            await Task.Delay(1000);

            //
            // Make sure the edited file matches
            //
            {
                var details = await SteamUGC.QueryFileAsync(fileid) ?? throw new Exception("Somethign went wrong");

                Assert.AreEqual(details.Id, fileid);
                Assert.AreEqual(details.Title, "An Edited File");
            }

            //
            // Clean up
            //
            var deleted = await SteamUGC.DeleteFileAsync(fileid);

            Assert.IsTrue(deleted);
        }
        /// <summary>
        /// Utility function to fetch a single item. Internally this uses Ugc.FileQuery -
        /// which you can use to query multiple items if you need to.
        /// </summary>
        public static async Task <Ugc.Item?> QueryFileAsync(PublishedFileId fileId)
        {
            var result = await new Ugc.Query(UgcType.All, fileId).GetPageAsync(1);

            if (!result.HasValue || result.Value.ResultCount != 1)
            {
                return(null);
            }

            var item = result.Value.Entries.First();

            result.Value.Dispose();

            return(item);
        }
예제 #8
0
		/// <summary>
		/// Utility function to fetch a single item. Internally this uses Ugc.FileQuery -
		/// which you can use to query multiple items if you need to.
		/// </summary>
		public static async Task<Ugc.Item?> QueryFileAsync(PublishedFileId fileId)
		{
			var result = await Ugc.Query.All
									.WithFileId(fileId)
									.GetPageAsync(1);

			if (!result.HasValue || result.Value.ResultCount != 1)
				return null;

			var item = result.Value.Entries.First();

			result.Value.Dispose();

			return item;
		}
예제 #9
0
 public static bool Download(PublishedFileId fileId, Action onInstalled = null, bool highPriority = false)
 {
     if (onInstalled != null)
     {
         onItemInstalled ??= new Dictionary <PublishedFileId, Action>();
         if (!onItemInstalled.ContainsKey(fileId))
         {
             onItemInstalled.Add(fileId, onInstalled);
         }
         else
         {
             onItemInstalled[fileId] += onInstalled;
         }
     }
     return(Internal.DownloadItem(fileId, highPriority));
 }
예제 #10
0
        public static Task DownloadAsync(PublishedFileId downloadItem)
        {
            return(Task.Run(() =>
            {
                if (!DownloadItem(downloadItem, true))
                {
                    return;
                }
                Console.WriteLine("Starting download...");
                ulong lastProgress = 0;
                while (true)
                {
                    ulong downloaded;
                    ulong total;

                    if (!GetItemDownloadInfo(downloadItem, out downloaded, out total))
                    {
                        break;
                    }

                    if (lastProgress < downloaded)
                    {
                        Console.WriteLine($"DL: {downloaded/1024}/{total/1024}kb");
                    }

                    if (downloaded > 0 && total > 0 && downloaded == total)
                    {
                        break;
                    }

                    lastProgress = downloaded;
                    Thread.Sleep(10);
                }
                Console.WriteLine("Stopping download...");
            }));
        }
 /// <summary>
 /// <para> get info about pending update for items that have EItemStateNeedsUpdate set. punBytesTotal will be valid after download started once</para>
 /// </summary>
 public static bool GetItemDownloadInfo(PublishedFileId fileId, out ulong punBytesDownloaded, out ulong punBytesTotal)
 {
     InteropHelp.TestIfAvailableGameServer();
     return(NativeMethods.ISteamGameServerUGC_GetItemDownloadInfo(fileId, out punBytesDownloaded, out punBytesTotal));
 }
 /// <summary>
 /// <para> unsubscribe from this item, will be uninstalled after game quits</para>
 /// </summary>
 public static SteamAPICall UnsubscribeItem(PublishedFileId fileId)
 {
     InteropHelp.TestIfAvailableGameServer();
     return((SteamAPICall)NativeMethods.ISteamGameServerUGC_UnsubscribeItem(fileId));
 }
 /// <summary>
 /// <para> get ItemState flags about item on this client</para>
 /// </summary>
 public static uint GetItemState(PublishedFileId fileId)
 {
     InteropHelp.TestIfAvailableGameServer();
     return(NativeMethods.ISteamGameServerUGC_GetItemState(fileId));
 }
예제 #14
0
 public static SteamAPICall GetUserPublishedItemVoteDetails(PublishedFileId unPublishedFileId)
 {
     InteropHelp.TestIfAvailableClient();
     return((SteamAPICall)NativeMethods.ISteamRemoteStorage_GetUserPublishedItemVoteDetails(unPublishedFileId));
 }
 public static SteamAPICall RemoveItemFromFavorites(AppId nAppId, PublishedFileId fileId)
 {
     InteropHelp.TestIfAvailableGameServer();
     return((SteamAPICall)NativeMethods.ISteamGameServerUGC_RemoveItemFromFavorites(nAppId, fileId));
 }
 /// <summary>
 /// <para> DEPRECATED - Use CreateQueryUGCDetailsRequest call above instead!</para>
 /// </summary>
 public static SteamAPICall RequestUGCDetails(PublishedFileId fileId, uint unMaxAgeSeconds)
 {
     InteropHelp.TestIfAvailableGameServer();
     return((SteamAPICall)NativeMethods.ISteamGameServerUGC_RequestUGCDetails(fileId, unMaxAgeSeconds));
 }
예제 #17
0
        internal bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId unPublishedFileID)
        {
            var returnValue = _TagPublishedFile(Self, hScreenshot, unPublishedFileID);

            return(returnValue);
        }
예제 #18
0
 public static bool Download(PublishedFileId fileId, bool highPriority = false)
 {
     return(Internal.DownloadItem(fileId, highPriority));
 }
예제 #19
0
 /// <summary>
 /// <para> Gets published file details for the given publishedfileid.  If unMaxSecondsOld is greater than 0,</para>
 /// <para> cached data may be returned, depending on how long ago it was cached.  A value of 0 will force a refresh.</para>
 /// <para> A value of WorkshopForceLoadPublishedFileDetailsFromCache will use cached data if it exists, no matter how old it is.</para>
 /// </summary>
 public static SteamAPICall GetPublishedFileDetails(PublishedFileId unPublishedFileId, uint unMaxSecondsOld)
 {
     InteropHelp.TestIfAvailableClient();
     return((SteamAPICall)NativeMethods.ISteamRemoteStorage_GetPublishedFileDetails(unPublishedFileId, unMaxSecondsOld));
 }
예제 #20
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);
        }
예제 #21
0
 public static SteamAPICall UnsubscribePublishedFile(PublishedFileId unPublishedFileId)
 {
     InteropHelp.TestIfAvailableClient();
     return((SteamAPICall)NativeMethods.ISteamRemoteStorage_UnsubscribePublishedFile(unPublishedFileId));
 }
예제 #22
0
 public static SteamAPICall UpdateUserPublishedItemVote(PublishedFileId unPublishedFileId, bool bVoteUp)
 {
     InteropHelp.TestIfAvailableClient();
     return((SteamAPICall)NativeMethods.ISteamRemoteStorage_UpdateUserPublishedItemVote(unPublishedFileId, bVoteUp));
 }
 /// <summary>
 /// <para> download new or update already installed item. If function returns true, wait for DownloadItemResult. If the item is already installed,</para>
 /// <para> then files on disk should not be used until callback received. If item is not subscribed to, it will be cached for some time.</para>
 /// <para> If bHighPriority is set, any other item download will be suspended and this item downloaded ASAP.</para>
 /// </summary>
 public static bool DownloadItem(PublishedFileId fileId, bool bHighPriority)
 {
     InteropHelp.TestIfAvailableGameServer();
     return(NativeMethods.ISteamGameServerUGC_DownloadItem(fileId, bHighPriority));
 }
 /// <summary>
 /// <para> start an UGC item update. Set changed properties before commiting update with CommitItemUpdate()</para>
 /// </summary>
 public static UGCUpdateHandle StartItemUpdate(AppId nConsumerAppId, PublishedFileId fileId)
 {
     InteropHelp.TestIfAvailableGameServer();
     return((UGCUpdateHandle)NativeMethods.ISteamGameServerUGC_StartItemUpdate(nConsumerAppId, fileId));
 }
예제 #25
0
 private static extern bool _TagPublishedFile(IntPtr self, ScreenshotHandle hScreenshot, PublishedFileId unPublishedFileID);
 public static SteamAPICall GetUserItemVote(PublishedFileId fileId)
 {
     InteropHelp.TestIfAvailableGameServer();
     return((SteamAPICall)NativeMethods.ISteamGameServerUGC_GetUserItemVote(fileId));
 }
예제 #27
0
        public static async Task <bool> DeleteFileAsync(PublishedFileId fileId)
        {
            var r = await Internal.DeleteItem(fileId);

            return(r?.Result == Result.OK);
        }
예제 #28
0
 public static SteamAPICall SetUserPublishedFileAction(PublishedFileId unPublishedFileId, EWorkshopFileAction eAction)
 {
     InteropHelp.TestIfAvailableClient();
     return((SteamAPICall)NativeMethods.ISteamRemoteStorage_SetUserPublishedFileAction(unPublishedFileId, eAction));
 }
예제 #29
0
        public static async Task <bool> StopPlaytimeTracking(PublishedFileId fileId)
        {
            var result = await Internal.StopPlaytimeTracking(new[] { fileId }, 1);

            return(result.Value.Result == Result.OK);
        }
 internal bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId unPublishedFileID)
 {
     return(_TagPublishedFile(Self, hScreenshot, unPublishedFileID));
 }