예제 #1
0
        public async Task <Editor> UpdateItem(Item item, DirectoryInfo uploadDirectory, CancellationToken token)
        {
            Editor editor;

            if (item == null)
            {
                editor             = _client.Workshop.CreateItem(ItemType.Community);
                editor.Title       = "New Item";
                editor.Description = "Edit me";
            }
            else
            {
                editor = _client.Workshop.EditItem(item.Id);
            }

            var previewExtensions = new[] { ".png", ".jpeg", ".jpg" };

            var preview = uploadDirectory.EnumerateFiles()
                          .Where(x => previewExtensions.Contains(x.Extension.ToLower()))
                          .Where(x => x.Length < 1024 * 1024)
                          .FirstOrDefault();

            editor.WorkshopUploadAppId = _client.AppId;
            editor.Folder       = uploadDirectory.FullName;
            editor.PreviewImage = preview?.FullName;
            editor.Publish();

            ConsoleHelpers.WriteLine();
            ConsoleHelpers.WriteLine($"Publishing workshop item... this might take a little while.");

            while (editor.Publishing)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(20), token);
            }

            if (editor.NeedToAgreeToWorkshopLegal)
            {
                ConsoleHelpers.WriteLine();
                ConsoleHelpers.WriteLine("Please agree to the Steam Workshop legal agreement.", ConsoleColor.Yellow);
                _browserOpener.OpenBrowser("http://steamcommunity.com/sharedfiles/workshoplegalagreement");
            }

            return(editor);
        }
        internal async Task Upload(DirectoryInfo uploadDirectory, ulong?existingItemId, CancellationToken token)
        {
            if (!uploadDirectory.Exists)
            {
                ConsoleHelpers.FatalError($"Directory doesn't exist: {uploadDirectory.FullName}");
            }

            Item existingItem = null;

            if (existingItemId.HasValue)
            {
                existingItem = await _workshopRepository.GetItem(existingItemId.Value, token);

                if (existingItem == null)
                {
                    ConsoleHelpers.FatalError($"Item {existingItemId.Value} was not found.");
                }

                ConsoleHelpers.WriteLine();
                ConsoleHelpers.WriteLine($"Updating existing item '{existingItem.Title}'");
            }

            var item = await _workshopRepository.UpdateItem(existingItem, uploadDirectory, token);

            if (item.Error == null)
            {
                ConsoleHelpers.WriteLine();
                ConsoleHelpers.WriteLine("Item uploaded successfully!", ConsoleColor.Green);

                ConsoleHelpers.WriteLine();
                _browserOpener.OpenBrowser($"https://steamcommunity.com/sharedfiles/filedetails/?id={item.Id}");

                ConsoleHelpers.WriteLine();
                ConsoleHelpers.WriteLine("You can edit the title, description, preview images and more from the item page.", ConsoleColor.Green);
            }
            else
            {
                ConsoleHelpers.FatalError($"Item upload failed. The error from Steam was: {item.Error}");
            }
        }