public UploadOptions(ModObject mod)
        {
            InitializeComponent();
            if (!DesignMode)
            {
                mod.Refresh();
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
                this.mod   = mod;
                this.store = ModStore.LoadForMod(mod);
                LoadGUITags((store.Tags != null && store.Tags.Count() > 0) ? store.Tags : null);
                textBox1.Text           = store.Changelog;
                comboBox3.SelectedIndex = store.Visibility;
                checkBox1.Checked       = store.UploadUnCookedContent;
                checkBox2.Checked       = store.UploadScripts;
                checkBox13.Checked      = store.ForceNoTags;

                checkBox13_CheckedChanged(null, null);

                var wsid = mod.GetUploadedId();
                if (wsid > 0)
                {
                    label6.Text      = "WorkshopId: " + wsid;
                    mButton4.Visible = false;
                }
                else
                {
                    mButton4.Visible = true;
                }
            }
        }
        private void mButton4_Click(object sender, EventArgs e)
        {
            var input = InputWindow.Ask(this, "Steam Workshop URL", "Insert the URL to the Steam Workshop item", new InputWindow.NonEmptyValidator());

            if (input == null)
            {
                return;
            }

            try
            {
                var parsed = HttpUtility.ParseQueryString(new Uri(input).Query).Get("id");
                var lg     = ulong.Parse(parsed);
                if (lg > 100000)
                {
                    mod.SetUploadedId(lg);
                    mod.Refresh();
                    var wsid = mod.GetUploadedId();
                    if (wsid > 0)
                    {
                        label6.Text      = "WorkshopId: " + wsid;
                        mButton4.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                GUI.MessageBox.Show("Invalid input: " + input + "\n" + ex.Message + "\n\n" + ex.ToString());
            }
        }
Beispiel #3
0
        public void UploadMod(ModObject mod, string changelog, string[] tags, bool keepUnCooked, bool keepScripts, int visibility, string description)
        {
            if (IsUploaderRunning)
            {
                MainWindow.Instance.Invoke(new MethodInvoker(() => {
                    GUI.MessageBox.Show(MainWindow.Instance, "Only one uploader instance can run at once!");
                }));
                return;
            }

            success           = true;
            IsUploaderRunning = true;
            try
            {
                ERemoteStoragePublishedFileVisibility fileVisibility
                    = (ERemoteStoragePublishedFileVisibility)Enum.ToObject(typeof(ERemoteStoragePublishedFileVisibility), visibility);;

                mod.Refresh();
                SetStatus("Preparing the uploader...");
                var tmpDir = Path.Combine(Program.GetAppRoot(), "uploader_tmp");
                if (Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }
                Directory.CreateDirectory(tmpDir);

                Utils.DirectoryCopy(mod.RootPath, tmpDir, true);
                if (!keepScripts)
                {
                    if (Directory.Exists(Path.Combine(tmpDir, "CompiledScripts")))
                    {
                        Directory.Delete(Path.Combine(tmpDir, "CompiledScripts"), true);
                    }
                    if (Directory.Exists(Path.Combine(tmpDir, "Classes")))
                    {
                        Directory.Delete(Path.Combine(tmpDir, "Classes"), true);
                    }
                }

                if (!keepUnCooked)
                {
                    if (Directory.Exists(Path.Combine(tmpDir, "Maps")))
                    {
                        Directory.Delete(Path.Combine(tmpDir, "Maps"), true);
                    }
                    if (Directory.Exists(Path.Combine(tmpDir, "Content")))
                    {
                        Directory.Delete(Path.Combine(tmpDir, "Content"), true);
                    }
                }

                //var description = mod.GetDescription();

                var modid = mod.GetUploadedId();

                SetStatus("Creating callback...");

                m_itemCreated = CallResult <CreateItemResult_t> .Create(OnItemCreated);

                var appId = new AppId_t(uint.Parse(GameFinder.AppID));

                if (modid == 0)
                {
                    SteamAPICall_t call = SteamUGC.CreateItem(appId, EWorkshopFileType.k_EWorkshopFileTypeCommunity);
                    m_itemCreated.Set(call);
                }
                else
                {
                    publishID = modid;
                }
                while (publishID == 0)
                {
                    SteamAPI.RunCallbacks();
                    Thread.Sleep(1000);
                }

                Thread.Sleep(1000);

                if (modid == 0)
                {
                    SetStatus("Uploading an new mod " + mod.Name + " with WorkshopID: " + publishID);
                    mod.SetUploadedId(publishID);
                }
                else
                {
                    SetStatus("Updating the mod " + mod.Name + " with WorkshopID: " + publishID);
                }
                var publishFileID_t = new PublishedFileId_t(publishID);

                ugcUpdateHandle = SteamUGC.StartItemUpdate(appId, publishFileID_t);

                SteamUGC.SetItemTitle(ugcUpdateHandle, mod.Name);
                SteamUGC.SetItemDescription(ugcUpdateHandle, description);
                SteamUGC.SetItemVisibility(ugcUpdateHandle, fileVisibility);
                if (tags != null)
                {
                    SteamUGC.SetItemTags(ugcUpdateHandle, tags);
                }
                SteamUGC.SetItemPreview(ugcUpdateHandle, Path.Combine(tmpDir, mod.Icon));
                SteamUGC.SetItemContent(ugcUpdateHandle, tmpDir);

                SteamAPICall_t t = SteamUGC.SubmitItemUpdate(ugcUpdateHandle, changelog);
                m_itemSubmitted = CallResult <SubmitItemUpdateResult_t> .Create(OnItemSubmitted);

                m_itemSubmitted.Set(t);

                while (true)
                {
                    Thread.Sleep(1000);
                    if (ugcUpdateHandle == UGCUpdateHandle_t.Invalid)
                    {
                        break;
                    }
                    SteamAPI.RunCallbacks();
                    ulong             bytesDone, bytesTotal;
                    EItemUpdateStatus status = SteamUGC.GetItemUpdateProgress(ugcUpdateHandle, out bytesDone, out bytesTotal);
                    if (status == EItemUpdateStatus.k_EItemUpdateStatusInvalid && !success)
                    {
                        break;
                    }
                    SetStatus(string.Format("[{3}%] Status: {0}\n{1}/{2}", TranslateStatus(status), BytesToString(bytesDone), BytesToString(bytesTotal), bytesTotal > 0 ? Math.Floor(((double)bytesDone / (double)bytesTotal) * (double)100) : 100));
                }

                DialogResult res = DialogResult.No;

                if (success)
                {
                    MainWindow.Instance.Invoke(new MethodInvoker(() => {
                        res = GUI.MessageBox.Show(MainWindow.Instance, "Done, mod url:" + "\nhttps://steamcommunity.com/sharedfiles/filedetails/?id=" + publishID + "\n\nOpen it in the browser?", "Uploader", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        if (res == DialogResult.Yes)
                        {
                            Process.Start("steam://openurl/https://steamcommunity.com/sharedfiles/filedetails/?id=" + publishID);
                        }
                    }));

                    SetStatus("Item uploaded successfully!");
                    Thread.Sleep(1000);
                }

                SetStatus("Cleanup");
                if (Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }

                SetStatus(null);

                IsUploaderRunning = false;
            }
            catch (Exception e)
            {
                MainWindow.Instance.Invoke(new MethodInvoker(() => {
                    GUI.MessageBox.Show(MainWindow.Instance, e.Message + "\n" + e.ToString());
                }));
                IsUploaderRunning = false;
                SetStatus(null);
            }
        }