Exemple #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);
        }
        public static SteamParamStringArray From(string[] array)
        {
            SteamParamStringArray hGlobalAnsi = new SteamParamStringArray()
            {
                NativeStrings = new IntPtr[(int)array.Length]
            };

            for (int i = 0; i < (int)hGlobalAnsi.NativeStrings.Length; i++)
            {
                hGlobalAnsi.NativeStrings[i] = Marshal.StringToHGlobalAnsi(array[i]);
            }
            int num = Marshal.SizeOf(typeof(IntPtr)) * (int)hGlobalAnsi.NativeStrings.Length;

            hGlobalAnsi.NativeArray = Marshal.AllocHGlobal(num);
            Marshal.Copy(hGlobalAnsi.NativeStrings, 0, hGlobalAnsi.NativeArray, (int)hGlobalAnsi.NativeStrings.Length);
            SteamParamStringArray_t steamParamStringArrayT = new SteamParamStringArray_t()
            {
                Strings    = hGlobalAnsi.NativeArray,
                NumStrings = (int)array.Length
            };

            hGlobalAnsi.Value = steamParamStringArrayT;
            return(hGlobalAnsi);
        }
Exemple #3
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);
                    }
                }

                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(8f);
                            break;
                        }

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

                    await Task.Delay(1000 / 60);
                }

                progress?.Report(1);

                var updated = updating.Result;

                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);
        }
        public async Task <PublishResult> SubmitAsync(IProgress <float> progress = null, Action <PublishResult> onItemCreated = null)
        {
            var result = default(PublishResult);

            progress?.Report(0);

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

            //
            // Checks
            //
            if (ContentFolder != null)
            {
                if (!System.IO.Directory.Exists(ContentFolder.FullName))
                {
                    throw new System.Exception($"UgcEditor - Content Folder doesn't exist ({ContentFolder.FullName})");
                }

                if (!ContentFolder.EnumerateFiles("*", System.IO.SearchOption.AllDirectories).Any())
                {
                    throw new System.Exception($"UgcEditor - Content Folder is empty");
                }
            }


            //
            // 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;

                if (onItemCreated != null)
                {
                    onItemCreated(result);
                }
            }


            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 (KeyValueTagsToRemove != null)
                {
                    foreach (var key in KeyValueTagsToRemove)
                    {
                        SteamUGC.Internal.RemoveItemKeyValueTags(handle, key);
                    }
                }

                if (KeyValueTags != null)
                {
                    foreach (var keyWithValues in KeyValueTags)
                    {
                        var key = keyWithValues.Key;
                        foreach (var value in keyWithValues.Value)
                        {
                            SteamUGC.Internal.AddItemKeyValueTag(handle, key, 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);
        }
Exemple #5
0
        public async Task <PublishResult> SubmitAsync(IProgress <float> progress = null)
        {
            PublishResult     publishResult;
            bool              flag;
            float             single;
            PublishResult     result    = new PublishResult();
            IProgress <float> progress1 = progress;

            if (progress1 != null)
            {
                progress1.Report(0f);
            }
            else
            {
            }
            if (this.consumerAppId == 0)
            {
                this.consumerAppId = SteamClient.AppId;
            }
            if (this.creatingNew)
            {
                result.Result = Result.Fail;
                CreateItemResult_t?nullable = await SteamUGC.Internal.CreateItem(this.consumerAppId, this.creatingType);

                CreateItemResult_t?nullable1 = nullable;
                nullable = null;
                if (nullable1.HasValue)
                {
                    result.Result = nullable1.Value.Result;
                    if (result.Result == Result.OK)
                    {
                        this.fileId = nullable1.Value.PublishedFileId;
                        result.NeedsWorkshopAgreement = nullable1.Value.UserNeedsToAcceptWorkshopLegalAgreement;
                        result.FileId = this.fileId;
                        nullable1     = null;
                    }
                    else
                    {
                        publishResult = result;
                        return(publishResult);
                    }
                }
                else
                {
                    publishResult = result;
                    return(publishResult);
                }
            }
            result.FileId = this.fileId;
            UGCUpdateHandle_t uGCUpdateHandleT = SteamUGC.Internal.StartItemUpdate(this.consumerAppId, this.fileId);

            if (uGCUpdateHandleT != (long)-1)
            {
                if ((object)this.Title != (object)null)
                {
                    SteamUGC.Internal.SetItemTitle(uGCUpdateHandleT, this.Title);
                }
                if ((object)this.Description != (object)null)
                {
                    SteamUGC.Internal.SetItemDescription(uGCUpdateHandleT, this.Description);
                }
                if ((object)this.MetaData != (object)null)
                {
                    SteamUGC.Internal.SetItemMetadata(uGCUpdateHandleT, this.MetaData);
                }
                if ((object)this.Language != (object)null)
                {
                    SteamUGC.Internal.SetItemUpdateLanguage(uGCUpdateHandleT, this.Language);
                }
                if (this.ContentFolder != null)
                {
                    SteamUGC.Internal.SetItemContent(uGCUpdateHandleT, this.ContentFolder.FullName);
                }
                if ((object)this.PreviewFile != (object)null)
                {
                    SteamUGC.Internal.SetItemPreview(uGCUpdateHandleT, this.PreviewFile);
                }
                if (this.Visibility.HasValue)
                {
                    SteamUGC.Internal.SetItemVisibility(uGCUpdateHandleT, this.Visibility.Value);
                }
                flag = (this.Tags == null ? false : this.Tags.Count > 0);
                if (flag)
                {
                    SteamParamStringArray steamParamStringArray = SteamParamStringArray.From(this.Tags.ToArray());
                    try
                    {
                        SteamParamStringArray_t value = steamParamStringArray.Value;
                        SteamUGC.Internal.SetItemTags(uGCUpdateHandleT, ref value);
                    }
                    finally
                    {
                        ((IDisposable)steamParamStringArray).Dispose();
                    }
                    steamParamStringArray = new SteamParamStringArray();
                }
                result.Result = Result.Fail;
                if (this.ChangeLog == null)
                {
                    this.ChangeLog = "";
                }
                Task <SubmitItemUpdateResult_t?> task = SteamUGC.Internal.SubmitItemUpdate(uGCUpdateHandleT, this.ChangeLog);
                while (!task.IsCompleted)
                {
                    if (progress != null)
                    {
                        ulong num  = (ulong)0;
                        ulong num1 = (ulong)0;
                        switch (SteamUGC.Internal.GetItemUpdateProgress(uGCUpdateHandleT, ref num1, ref num))
                        {
                        case ItemUpdateStatus.PreparingConfig:
                        {
                            IProgress <float> progress2 = progress;
                            if (progress2 != null)
                            {
                                progress2.Report(0.1f);
                            }
                            else
                            {
                            }
                            break;
                        }

                        case ItemUpdateStatus.PreparingContent:
                        {
                            IProgress <float> progress3 = progress;
                            if (progress3 != null)
                            {
                                progress3.Report(0.2f);
                            }
                            else
                            {
                            }
                            break;
                        }

                        case ItemUpdateStatus.UploadingContent:
                        {
                            single = (num > (long)0 ? (float)((float)num1) / (float)((float)num) : 0f);
                            float             single1   = single;
                            IProgress <float> progress4 = progress;
                            if (progress4 != null)
                            {
                                progress4.Report(0.2f + single1 * 0.7f);
                            }
                            else
                            {
                            }
                            break;
                        }

                        case ItemUpdateStatus.UploadingPreviewFile:
                        {
                            IProgress <float> progress5 = progress;
                            if (progress5 != null)
                            {
                                progress5.Report(8f);
                            }
                            else
                            {
                            }
                            break;
                        }

                        case ItemUpdateStatus.CommittingChanges:
                        {
                            IProgress <float> progress6 = progress;
                            if (progress6 != null)
                            {
                                progress6.Report(1f);
                            }
                            else
                            {
                            }
                            break;
                        }
                        }
                    }
                    await Task.Delay(16);
                }
                IProgress <float> progress7 = progress;
                if (progress7 != null)
                {
                    progress7.Report(1f);
                }
                else
                {
                }
                SubmitItemUpdateResult_t?result1 = task.Result;
                if (result1.HasValue)
                {
                    result.Result = result1.Value.Result;
                    if (result.Result == Result.OK)
                    {
                        result.NeedsWorkshopAgreement = result1.Value.UserNeedsToAcceptWorkshopLegalAgreement;
                        result.FileId = this.fileId;
                        task          = null;
                        result1       = null;
                        publishResult = result;
                    }
                    else
                    {
                        publishResult = result;
                    }
                }
                else
                {
                    publishResult = result;
                }
            }
            else
            {
                publishResult = result;
            }
            return(publishResult);
        }