Ejemplo n.º 1
0
        private void submission_PackageAndUpload(object sender, DoWorkEventArgs e)
        {
            bool workDone = false;

            UpdateStatus(LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_SynchronisingMaps));

            //Run this on main thread to avoid threading issues (the editor is still being displayed in the background).
            GameBase.Scheduler.Add(delegate
            {
                using (HitObjectManager hitObjectManager = new HitObjectManagerEditor())
                {
                    Beatmap current = BeatmapManager.Current;

                    bool requiresReload = false;

                    try
                    {
                        //overwrite beatmap id's from the webservice and save them to disk.
                        for (int i = 0; i < beatmaps.Count; i++)
                        {
                            Beatmap b = beatmaps[i];
                            if (b.BeatmapSetId != newBeatmapSetID || b.BeatmapId != newBeatmapIDs[i])
                            {
                                AudioEngine.LoadedBeatmap = BeatmapManager.Current = b;
                                hitObjectManager.SetBeatmap(b, Mods.None);
                                hitObjectManager.LoadWithEvents();
                                b.BeatmapSetId = newBeatmapSetID;
                                b.BeatmapId    = newBeatmapIDs[i];
                                hitObjectManager.Save(false, false, false);

                                requiresReload = true;
                            }

                            b.ComputeAndSetDifficultiesTomStars(b.PlayMode);
                        }
                    }
                    catch { }

                    if (requiresReload)
                    {
                        AudioEngine.LoadedBeatmap = BeatmapManager.Current = current;
                        editor.LoadFile(current, false, false);
                    }

                    workDone = true;
                }
            });

            if (checkCancel(e))
            {
                return;
            }

            //get beatmap topic contents
            string url = String.Format(Urls.FORUM_GET_BEATMAP_TOPIC_INFO, ConfigManager.sUsername, ConfigManager.sPassword, newBeatmapSetID);

            activeWebRequest = new pWebRequest(url);
            string result = string.Empty;

            try
            {
                activeWebRequest.BlockingPerform();
                result = activeWebRequest.ResponseString;
                if (!string.IsNullOrEmpty(result) && result[0] == '0')
                {
                    string[] results = result.Split((char)3);
                    threadId = int.Parse(results[1]);

                    Invoke(() => oldMessage = results[3]);
                }
            }
            catch
            {
            }

            while (!workDone)
            {
                Thread.Sleep(100);
            }

            if (checkCancel(e))
            {
                return;
            }

            UpdateStatus(LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_CreatingPackage));

            //create a new Osz2 file
            string osz2Temp = GeneralHelper.GetTempPath(newBeatmapSetID + @".osz2");

            //todo: add to progress bar
            packageCurrentUpload = BeatmapManager.Current.ConvertToOsz2(osz2Temp, false);

            if (packageCurrentUpload == null)
            {
                error = LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_CouldntCreatePackage) +
                        LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_ExtraDiskSpace);
                submission_PackageAndUpload_Complete(null, null);
                return;
            }

            string osz2NewHash = (BitConverter.ToString(packageCurrentUpload.hash_body) +
                                  BitConverter.ToString(packageCurrentUpload.hash_meta)).Replace("-", "");

            beatmapFilesize = new System.IO.FileInfo(packageCurrentUpload.Filename).Length;

            if (checkCancel(e))
            {
                return;
            }

            Invoke(delegate
            {
                panelMain.Enabled = true;

                if (beatmaps.Count > 1)
                {
                    radioButtonWorkInProgress.Checked = approved != 0;
                    radioButtonPending.Checked        = approved == 0;
                }
                else
                {
                    radioButtonWorkInProgress.Checked = true;
                    radioButtonPending.Checked        = false;
                }

                newMessage = "[size=85]This beatmap was submitted using in-game submission on " +
                             DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString() + "[/size]\n";
                newMessage += "\n[b]Artist:[/b] " + beatmaps[0].Artist;
                newMessage += "\n[b]Title:[/b] " + beatmaps[0].Title;
                if (beatmaps[0].Source.Length > 0)
                {
                    newMessage += "\n[b]Source:[/b] " + beatmaps[0].Source;
                }
                if (beatmaps[0].Tags.Length > 0)
                {
                    newMessage += "\n[b]Tags:[/b] " + beatmaps[0].Tags;
                }
                newMessage += "\n[b]BPM:[/b] " + Math.Round(1000 / beatmaps[0].ControlPoints[0].BeatLength * 60, 2);
                newMessage += "\n[b]Filesize:[/b] " + (beatmapFilesize / 1024).ToString(GameBase.nfi) + "kb";
                newMessage +=
                    String.Format("\n[b]Play Time:[/b] {0:00}:{1:00}", beatmaps[0].TotalLength / 60000,
                                  (beatmaps[0].TotalLength % 60000) / 1000);
                newMessage += "\n[b]Difficulties Available:[/b]\n[list]";
                foreach (Beatmap b in beatmaps)
                {
                    newMessage += string.Format("[*][url={0}]{1}{2}[/url] ({3} stars, {4} notes)\n", Urls.PATH_MAPS + GeneralHelper.UrlEncode(Path.GetFileName(b.Filename)),
                                                (b.Version.Length > 0 ? b.Version : "Normal"), (b.PlayMode == PlayModes.OsuMania ? " - " + (int)Math.Round(b.DifficultyCircleSize) + "Key" : ""), Math.Round(b.DifficultyTomStars(b.PlayMode), 2), b.ObjectCount);
                }
                newMessage += "[/list]\n";
                newMessage += string.Format("\n[size=150][b]Download: [url={0}]{1}[/url][/b][/size]",
                                            string.Format(Urls.BEATMAP_SET_DOWNLOAD, newBeatmapSetID),
                                            beatmaps[0].SortTitle);

                if (hasVideo)
                {
                    newMessage += string.Format("\n[size=120][b]Download: [url={0}]{1}[/url][/b][/size]",
                                                string.Format(Urls.BEATMAP_SET_DOWNLOAD_NO_VIDEO, newBeatmapSetID),
                                                beatmaps[0].SortTitle + " (no video)");
                }

                newMessage += string.Format("\n[b]Information:[/b] [url={0}]Scores/Beatmap Listing[/url]",
                                            string.Format(Urls.BEATMAP_SET_LISTING, newBeatmapSetID));
                newMessage += "\n---------------\n";

                textMessage.Text =
                    LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_CreatorsWords);

                if (!string.IsNullOrEmpty(oldMessage))
                {
                    if (oldMessage.IndexOf("---------------\n") > 0)
                    {
                        textMessage.Text = oldMessage.Remove(0, oldMessage.IndexOf("---------------") + 16).Trim('\n', '\r').Replace("\n", "\r\n");
                    }
                    else
                    {
                        textMessage.Text = oldMessage.Replace("\n", "\r\n");
                    }
                }

                textMessage.Focus();
                textMessage.SelectAll();
            });

            bool marathonException = beatmaps[0].Version.Contains("Marathon");

            if (beatmapFilesize > 32 * 1024 * 1024 && !marathonException) //special marathon exception
            {
                error = LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_UploadFailed) +
                        LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_BeatmapTooLarge);
                submission_PackageAndUpload_Complete(null, null);
                return;
            }

            if (beatmaps.Count < 2 && !marathonException)
            {
                Invoke(delegate
                {
                    //don't allow submission to pending
                    radioButtonPending.Enabled = false;
                    radioButtonPending.Text    = LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_PendingBeatmaps);
                });
            }

            byte[] uploadBytes;

            if (!fullSubmit)
            {
                UpdateStatus(LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_PreparingChanges));
                progressStartTime = DateTime.Now;

                BSDiffer patchCreator = new BSDiffer();
                patchCreator.OnProgress += (object s, long current, long total) => { UpdateProgress(current, total); };

                using (MemoryStream ms = new MemoryStream())
                {
                    patchCreator.Diff(packagePreviousUpload.Filename, osz2Temp, ms, Compression.GZip);
                    uploadBytes = ms.ToArray();
                }
            }
            else
            {
                uploadBytes = File.ReadAllBytes(osz2Temp);
            }

            if (checkCancel(e))
            {
                return;
            }

            UpdateStatus(!isNewSubmission ? LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_SendingChanges) : LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_Uploading));

            //Start the main upload process...
            activeWebRequest            = new pWebRequest(Urls.OSZ2_SUBMIT_UPLOAD);
            activeWebRequest.Timeout    = 3 * 60 * 1000;
            activeWebRequest.RetryCount = 0;
            activeWebRequest.AddParameter("u", ConfigManager.sUsername);
            activeWebRequest.AddParameter("h", ConfigManager.sPassword);
            activeWebRequest.AddParameter("t", fullSubmit ? "1" : "2");
            activeWebRequest.AddParameter("z", string.Empty);
            activeWebRequest.AddParameter("s", newBeatmapSetID.ToString());
            activeWebRequest.AddFile("osz2", uploadBytes);
            activeWebRequest.UploadProgress += delegate(pWebRequest r, long current, long total)
            {
                if (total == 0)
                {
                    return;
                }

                if (current == total)
                {
                    UpdateStatus(LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_Distributing));
                }
                else
                {
                    UpdateProgress(current, total);
                }
            };
            activeWebRequest.Finished += submission_PackageAndUpload_Complete;

            activeWebRequest.Perform();
            progressStartTime = DateTime.Now;
        }
        /// <summary>
        /// Initialises Test Mode.
        /// </summary>
        internal void TestMode()
        {
            lastMode = CurrentMode;

            if (hitObjectManager.hitObjects.Count == 0)
            {
                return;
            }
            if (AudioEngine.AudioState == AudioStates.Playing)
            {
                Pause();
            }

            if (Compose != null)
            {
                Compose.FinishPlacement();
                Compose.RemovePlacementObject();
            }

            FinishBreakDrag();
            changeManager.FinishAction();

            if (AudioEngine.BeatLength <= 0)
            {
                MessageBox.Show(LocalisationManager.GetString(OsuString.EditorControl_OneSectionRequiredWarning), @"osu!", MessageBoxButtons.OK);
                return;
            }

            changeManager.IgnorePush = true;
            while (!AudioEngine.ControlPoints[0].TimingChange)
            {
                AudioEngine.ControlPoints.RemoveAt(0);
                AudioEngine.UpdateActiveTimingPoint(false);
            }
            changeManager.IgnorePush = false;

            AiModClose();

            CloseImportDialog();

            GameBase.TestMode = true;
            GameBase.TestTime = AudioEngine.Time;

            Beatmap b = hitObjectManager.Beatmap;

            Player.Mode = b.PlayMode;

            if (hitObjectManager.hitObjects.FindAll(h => h.EndTime > AudioEngine.Time).Count == 0)
            {
                GameBase.TestTime = 0; //There are no hitcircles after the current point.
            }
            if (!changeManager.Dirty || hitObjectManager.Save(true, false, false))
            {
                if (b.DifficultyTomStars(b.PlayMode) < 0)
                {
                    b.ComputeAndSetDifficultiesTomStars(b.PlayMode);
                }

                HideDifficultySwitch();
                GameBase.ChangeModeInstant(OsuModes.Play);
            }
            else
            {
                GameBase.TestMode = false;
            }
        }