internal void PackageOsz2() { if (hitObjectManager.Beatmap.InOszContainer) { return; } SaveFile(); GameBase.MenuActive = true; SaveFileDialog s = new SaveFileDialog(); s.RestoreDirectory = true; s.AddExtension = true; s.Filter = @"Packaged Beatmaps|*.osz2"; s.DefaultExt = @".osz2"; s.FileName = GeneralHelper.WindowsFilenameStrip(hitObjectManager.Beatmap.SortTitle); DialogResult r = s.ShowDialog(GameBase.Form); if (r == DialogResult.OK) { MapPackage pkg = hitObjectManager.Beatmap.ConvertToOsz2(s.FileName, false); pkg.Close(); } GameBase.MenuActive = false; }
/// <summary> /// Calls a MapPackageAction in a safe environment by catching all the exceptions /// and translating them to appropiate responsecodes. /// </summary> /// <param name="Action">A MapPackageAction which updates the osz2 file in the save environment</param> /// <param name="MappackageFile">Path to the osz2 fileparam> /// <param name="Key">The key used to decrypt or encrypt the mappackage</param> /// <param name="SaveData">Whether to save the data after using the custom defined action on the beatmap</param> /// <returns>the UpdateResponseCode of the custom defined action when no exception has occured /// while loading the beatmap(osz2) file, or a failed UpdateResponseCode when there has.</returns> private UpdateResponseCode DoMapPackageActionSafe(MapPackageAction Action, string MappackageFile, byte[] Key, bool SaveData, bool MetadataOnly) { string originalPath = MappackageFile; if (!File.Exists(MappackageFile)) { MappackageFile = s3getToTemp("osz2/" + MappackageFile); } else { originalPath = Path.GetFileName(originalPath); } UpdateResponseCode CustomResponseCode; if (!File.Exists(MappackageFile)) { return(UpdateResponseCode.FileDoesNotExist); } try { using (MapPackage Osz2Beatmap = new MapPackage(MappackageFile, Key, false, MetadataOnly)) { CustomResponseCode = Action(Osz2Beatmap); if (CustomResponseCode == UpdateResponseCode.UpdateSuccessful && SaveData) { Osz2Beatmap.Save(); } Osz2Beatmap.Close(); } if (CustomResponseCode == UpdateResponseCode.UpdateSuccessful && SaveData) { s3putFile("osz2/" + originalPath, MappackageFile); } } catch (IOException e) { log(e); return(UpdateResponseCode.Osz2Corrupted); } catch (Exception e) { log(e); return(UpdateResponseCode.UnknownError); } finally { } return(CustomResponseCode); }
public static void CloseMapPackage(MapPackage package) { lock (locker) { int index = openPackages.IndexOf(package); package.Close(); openPackages.Remove(package); if (index == -1) { return; } } }
private void submission_PackageAndUpload_Complete(pWebRequest r, Exception e) { backgroundWorker.DoWork -= submission_PackageAndUpload; string result = r == null ? "-1" : r.ResponseString; Debug.Print(result); if (uploadError || e != null || result != "0") { Invoke(delegate { if (!string.IsNullOrEmpty(result)) { handleErrorCode(result.Split('\n'), 1); } else { result = null; } if (!formClosing) { string errorDetails = error ?? result ?? (e != null ? Logger.ApplyFilters(e.Message) : "No response from the server"); string errorMessage = string.Format(LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_ErrorDuringUpload), errorDetails).Trim('\n', ' '); MessageBox.Show(this, errorMessage, "osu!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } Close(); }); if (packageCurrentUpload != null) { packageCurrentUpload.Dispose(); File.Delete(packageCurrentUpload.Filename); packageCurrentUpload = null; } return; } //Replace/create submissionCache for this map... try { packageCurrentUpload.Close(); string lastUpload = lastUploadFilename; if (!Directory.Exists(Path.GetDirectoryName(lastUpload))) { Directory.CreateDirectory(Path.GetDirectoryName(lastUpload)); } if (packagePreviousUpload != null) { packagePreviousUpload.Close(); } File.Delete(lastUpload); File.Move(packageCurrentUpload.Filename, lastUpload); } catch { } //Finished uploading. Alert the user! UpdateStatus(isNewSubmission ? LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_Uploaded) : LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_Updated)); Invoke(delegate { if (!formClosing) { progressBar1.Value = 100; } buttonSubmit.Enabled = true; buttonCancel.Enabled = false; AudioEngine.PlaySample(@"notify1"); GameBase.FlashWindow(Handle, false); }); }