Beispiel #1
0
        static async Task UploadIcon(Stream iconStream)
        {
            var hash        = SHAHash(iconStream);
            var iconSuccess = await CloudStream.UploadStream("gmpublish_icon.jpg", APPID, hash, iconStream.Length, steamClient, iconStream);

            if (!iconSuccess)
            {
                Console.WriteLine("JPG Upload failed");
                Exit(32);
            }
        }
Beispiel #2
0
        static async Task UploadAddonGMA(Stream gmaStream)
        {
            var lzmaStream = LZMAEncodeStream.CompressStreamLZMA(gmaStream);
            var hashGma    = SHAHash(lzmaStream);
            var gmaSuccess = await CloudStream.UploadStream("gmpublish.gma", APPID, hashGma, lzmaStream.Length, steamClient, lzmaStream);

            if (!gmaSuccess)
            {
                Console.WriteLine("GMA Upload failed");
                Exit(32);
            }
        }
Beispiel #3
0
        static void FullyLoggedIn(SteamUser.LoggedOnCallback callback)
        {
            var task = Task.Run(async() =>
            {
                try
                {
                    await CloudStream.DeleteFile("gmpublish_icon.jpg", APPID, steamClient);
                    await CloudStream.DeleteFile("gmpublish.gma", APPID, steamClient);

                    var baseFolder = "./Addon";
                    var gmaPath    = "./addon.gma"; //Path.GetTempFileName();

                    var addonJsonPath = Path.Combine(baseFolder, "addon.json");
                    if (!File.Exists(addonJsonPath))
                    {
                        throw new Exception("No addon.json file found in specified folder");
                    }
                    AddonJSON addon;
                    using (FileStream addonStream = new FileStream(addonJsonPath, FileMode.Open))
                    {
                        addon = addonStream.CreateFromJsonStream <AddonJSON>();
                    }
                    if (addon.Icon == "")
                    {
                        throw new Exception("No icon file specified");
                    }
                    using (Stream gmaStream = new FileStream(gmaPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                    {
                        GMADCreator.Create(baseFolder, addon, gmaStream);
                        gmaStream.Seek(0, SeekOrigin.Begin);


                        using (var icon = new FileStream(Path.Combine(baseFolder, addon.Icon), FileMode.Open))
                        {
                            var hash        = SHAHash(icon);
                            var iconSuccess = await CloudStream.UploadStream("gmpublish_icon.jpg", APPID, hash, icon.Length, steamClient, icon);
                            if (!iconSuccess)
                            {
                                Console.WriteLine("JPG Upload failed"); return;
                            }
                        }

                        var lzmaStream = LZMAEncodeStream.CompressStreamLZMA(gmaStream);
                        var hashGma    = SHAHash(lzmaStream);
                        var gmaSuccess = await CloudStream.UploadStream("gmpublish.gma", APPID, hashGma, lzmaStream.Length, steamClient, lzmaStream);
                        if (!gmaSuccess)
                        {
                            Console.WriteLine("GMA Upload failed"); return;
                        }
                    }

                    var publishService = steamUnifiedMessages.CreateService <IPublishedFile>();
                    if (addon.WorkshopID == 0)
                    {
                        var request = new CPublishedFile_Publish_Request
                        {
                            appid                 = APPID,
                            consumer_appid        = APPID,
                            cloudfilename         = "gmpublish.gma",
                            preview_cloudfilename = "gmpublish_icon.jpg",
                            title                 = addon.Title,
                            file_description      = addon.Description,
                            file_type             = (uint)EWorkshopFileType.Community,
                            visibility            = (uint)EPublishedFileVisibility.Public,
                            collection_type       = addon.Type,
                        };
                        foreach (var tag in addon.Tags)
                        {
                            request.tags.Add(tag);
                        }

                        var publishCallback = await publishService.SendMessage(publish => publish.Publish(request));
                        var publishResponse = publishCallback.GetDeserializedResponse <CPublishedFile_Publish_Response>();
                        addon.WorkshopID    = publishResponse.publishedfileid;

                        using (FileStream addonStream = new FileStream(addonJsonPath, FileMode.Create))
                        {
                            addonStream.WriteObjectToStreamJson(addon);
                        }
                        Console.WriteLine("NEW PUBLISHED ID: " + publishResponse.publishedfileid + ". Wrote to addon.json");
                    }
                    else
                    {
                        var request = new CPublishedFile_Update_Request
                        {
                            image_height     = 512,
                            image_width      = 512,
                            publishedfileid  = addon.WorkshopID,
                            appid            = APPID,
                            filename         = "gmpublish.gma",
                            preview_filename = "gmpublish_icon.jpg",
                            title            = addon.Title,
                            file_description = addon.Description,
                            visibility       = (uint)EPublishedFileVisibility.Public,
                        };
                        foreach (var tag in addon.Tags)
                        {
                            request.tags.Add(tag);
                        }

                        var updateCallback = await publishService.SendMessage(publish => publish.Update(request));
                        var updateResponse = updateCallback.GetDeserializedResponse <CPublishedFile_Update_Response>();

                        Console.WriteLine("Addon has been updated");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.ReadKey();
                }
            });

            task.Wait();
            steamUser.LogOff();
            isRunning = false;
        }
Beispiel #4
0
        static void FullyLoggedIn(SteamUser.LoggedOnCallback callback)
        {
            var task = Task.Run(async() =>
            {
                try
                {
                    if (currentAction == Action.CREATE || currentAction == Action.UPDATE)
                    {
                        // Delete any previously uploaded temp files
                        await CloudStream.DeleteFile("gmpublish_icon.jpg", APPID, steamClient);
                        await CloudStream.DeleteFile("gmpublish.gma", APPID, steamClient);
                        AddonInfo addonInfo;

                        addonInfo = GetAddonInfoFromGMAFile(gmaFile.OpenRead());

                        using (Stream gmaStream = gmaFile.OpenRead())
                        {
                            // for updates the icon file is optional
                            if (iconFile != null && iconFile.Exists)
                            {
                                using (Stream iconStream = iconFile.OpenRead())
                                {
                                    await UploadIcon(iconStream);
                                }
                            }

                            await UploadAddonGMA(gmaStream);
                        }

                        var publishService = steamUnifiedMessages.CreateService <IPublishedFile>();

                        if (currentAction == Action.CREATE)
                        {
                            Console.WriteLine("Creating new addon - " + addonInfo.title);

                            var request = new CPublishedFile_Publish_Request
                            {
                                appid                 = APPID,
                                consumer_appid        = APPID,
                                cloudfilename         = "gmpublish.gma",
                                preview_cloudfilename = "gmpublish_icon.jpg",
                                title                 = addonInfo.title,
                                file_description      = addonInfo.description.Description,
                                file_type             = (uint)EWorkshopFileType.Community,
                                visibility            = (uint)EPublishedFileVisibility.Public,
                                collection_type       = addonInfo.description.Type,
                            };
                            foreach (var tag in addonInfo.description.Tags)
                            {
                                request.tags.Add(tag);
                            }

                            var publishCallback = await publishService.SendMessage(publish => publish.Publish(request));
                            var publishResponse = publishCallback.GetDeserializedResponse <CPublishedFile_Publish_Response>();
                            var newId           = publishResponse.publishedfileid;
                            Console.WriteLine(publishResponse.redirect_uri);
                            Console.WriteLine("Success! New Addon Published. Addon ID: " + newId.ToString());
                            Exit(1); // 1 signals success in the original gmpublish
                        }
                        else // currentAction == Action.UPDATE
                        {
                            Console.WriteLine("Updating existing addon " + workshopId + " - " + addonInfo.title);
                            var request = new CPublishedFile_Update_Request
                            {
                                publishedfileid  = (ulong)workshopId,
                                appid            = APPID,
                                filename         = "gmpublish.gma",
                                title            = addonInfo.title,
                                file_description = addonInfo.description.Description,
                                visibility       = (uint)EPublishedFileVisibility.Public,
                            };
                            foreach (var tag in addonInfo.description.Tags)
                            {
                                request.tags.Add(tag);
                            }

                            // only update the icon if one was supplied
                            if (iconFile != null && iconFile.Exists)
                            {
                                request.image_height     = 512;
                                request.image_width      = 512;
                                request.preview_filename = "gmpublish_icon.jpg";
                            }

                            var updateCallback = await publishService.SendMessage(publish => publish.Update(request));
                            var updateResponse = updateCallback.GetDeserializedResponse <CPublishedFile_Update_Response>();


                            Console.WriteLine("Success! Addon " + workshopId + " has been updated");
                            Exit(1); // 1 signals success in the original gmpublish
                        }
                    }
                    else if (currentAction == Action.LIST)
                    {
                        var publishService = steamUnifiedMessages.CreateService <IPublishedFile>();

                        var request = new CPublishedFile_GetUserFiles_Request
                        {
                            appid    = APPID,
                            ids_only = false,
                            steamid  = steamClient.SteamID.ConvertToUInt64()
                        };

                        Console.WriteLine("Getting published files...\n");

                        var listCallback = await publishService.SendMessage(publish => publish.GetUserFiles(request));
                        var listResponse = listCallback.GetDeserializedResponse <CPublishedFile_GetUserFiles_Response>();
                        Console.WriteLine("Found " + listResponse.total.ToString() + " results");
                        listResponse.publishedfiledetails.ForEach(publishedFile =>
                                                                  Console.WriteLine(String.Format("\t{0}\t{1,-5:F1} MB \"{2}\" ", publishedFile.publishedfileid, publishedFile.file_size / 1000000f, publishedFile.title))
                                                                  );
                        Exit(1); // 1 signals success in the original gmpublish
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Exit(2);
                }
            });

            task.Wait();
            steamUser.LogOff();
            isRunning = false;
        }