コード例 #1
0
        public static SteamParamStringArray From(string[] array)
        {
            var a = new SteamParamStringArray();

            a.NativeStrings = new IntPtr[array.Length];
            for (int i = 0; i < a.NativeStrings.Length; i++)
            {
                a.NativeStrings[i] = Marshal.StringToHGlobalAnsi(array[i]);
            }

            var size = Marshal.SizeOf(typeof(IntPtr)) * a.NativeStrings.Length;

            a.NativeArray = Marshal.AllocHGlobal(size);
            Marshal.Copy(a.NativeStrings, 0, a.NativeArray, a.NativeStrings.Length);

            a.Value = new SteamParamStringArray_t
            {
                Strings    = a.NativeArray,
                NumStrings = array.Length
            };

            return(a);
        }
コード例 #2
0
        public async Task <PublishResult> SubmitAsync(IProgress <float> progress = null)
        {
            var result = default(PublishResult);

            progress?.Report(0);

            if (consumerAppId == 0)
            {
                consumerAppId = SteamClient.AppId;
            }

            //
            // Item Create
            //
            if (creatingNew)
            {
                result.Result = Steamworks.Result.Fail;

                var created = await SteamUGC.Internal.CreateItem(consumerAppId, creatingType);

                if (!created.HasValue)
                {
                    return(result);
                }

                result.Result = created.Value.Result;

                if (result.Result != Steamworks.Result.OK)
                {
                    return(result);
                }

                fileId = created.Value.PublishedFileId;
                result.NeedsWorkshopAgreement = created.Value.UserNeedsToAcceptWorkshopLegalAgreement;
                result.FileId = fileId;
            }


            result.FileId = fileId;

            //
            // Item Update
            //
            {
                var handle = SteamUGC.Internal.StartItemUpdate(consumerAppId, fileId);
                if (handle == 0xffffffffffffffff)
                {
                    return(result);
                }

                if (Title != null)
                {
                    SteamUGC.Internal.SetItemTitle(handle, Title);
                }
                if (Description != null)
                {
                    SteamUGC.Internal.SetItemDescription(handle, Description);
                }
                if (MetaData != null)
                {
                    SteamUGC.Internal.SetItemMetadata(handle, MetaData);
                }
                if (Language != null)
                {
                    SteamUGC.Internal.SetItemUpdateLanguage(handle, Language);
                }
                if (ContentFolder != null)
                {
                    SteamUGC.Internal.SetItemContent(handle, ContentFolder.FullName);
                }
                if (PreviewFile != null)
                {
                    SteamUGC.Internal.SetItemPreview(handle, PreviewFile);
                }
                if (Visibility.HasValue)
                {
                    SteamUGC.Internal.SetItemVisibility(handle, Visibility.Value);
                }
                if (Tags != null && Tags.Count > 0)
                {
                    using (var a = SteamParamStringArray.From(Tags.ToArray()))
                    {
                        var val = a.Value;
                        SteamUGC.Internal.SetItemTags(handle, ref val);
                    }
                }

                if (KeyValueTags != null && KeyValueTags.Count > 0)
                {
                    foreach (var keyValueTag in KeyValueTags)
                    {
                        SteamUGC.Internal.AddItemKeyValueTag(handle, keyValueTag.Key, keyValueTag.Value);
                    }
                }

                result.Result = Steamworks.Result.Fail;

                if (ChangeLog == null)
                {
                    ChangeLog = "";
                }

                var updating = SteamUGC.Internal.SubmitItemUpdate(handle, ChangeLog);

                while (!updating.IsCompleted)
                {
                    if (progress != null)
                    {
                        ulong total     = 0;
                        ulong processed = 0;

                        var r = SteamUGC.Internal.GetItemUpdateProgress(handle, ref processed, ref total);

                        switch (r)
                        {
                        case ItemUpdateStatus.PreparingConfig:
                        {
                            progress?.Report(0.1f);
                            break;
                        }

                        case ItemUpdateStatus.PreparingContent:
                        {
                            progress?.Report(0.2f);
                            break;
                        }

                        case ItemUpdateStatus.UploadingContent:
                        {
                            var uploaded = total > 0 ? ((float)processed / (float)total) : 0.0f;
                            progress?.Report(0.2f + uploaded * 0.7f);
                            break;
                        }

                        case ItemUpdateStatus.UploadingPreviewFile:
                        {
                            progress?.Report(0.8f);
                            break;
                        }

                        case ItemUpdateStatus.CommittingChanges:
                        {
                            progress?.Report(1);
                            break;
                        }
                        }
                    }

                    await Task.Delay(1000 / 60);
                }

                progress?.Report(1);

                var updated = updating.GetResult();

                if (!updated.HasValue)
                {
                    return(result);
                }

                result.Result = updated.Value.Result;

                if (result.Result != Steamworks.Result.OK)
                {
                    return(result);
                }

                result.NeedsWorkshopAgreement = updated.Value.UserNeedsToAcceptWorkshopLegalAgreement;
                result.FileId = fileId;
            }

            return(result);
        }