#pragma warning disable 612,618 void DeleteButton_Click(object sender, RoutedEventArgs e) { var selectedMission = (Mission)DataGrid.SelectedItem; var dialog = new PasswordRequest { Owner = MainWindow.Instance }; if (dialog.ShowDialog() == true) { var password = dialog.PasswordBox.Password; Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); client.DeleteMission(selectedMission.MissionID, selectedMission.AuthorName, password); RefreshList(); } catch (FaultException <ExceptionDetail> ex) { MessageBox.Show(ex.Message); } }); } }
void RefreshList() { if (Dispatcher.Thread != Thread.CurrentThread) { this.Invoke(RefreshList); return; } var loadingDialog = new LoadingDialog { Text = "Getting Mission List", Owner = MainWindow.Instance }; Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); var list = client.ListMissionInfos(); this.Invoke(delegate { DataGrid.ItemsSource = showHiddenMissionsBox.IsChecked == true ? list : list.Where(m => !m.IsDeleted); loadingDialog.Close(); }); } catch (Exception e) { MessageBox.Show("Could not get mission list: " + e.Message); } }); loadingDialog.ShowDialog(); }
#pragma warning restore 612,618 void OpenButton_Click(object sender, RoutedEventArgs e) { var loadingDialog = new LoadingDialog { Text = "Opening Mission", Owner = this }; var selectedMission = (Mission)DataGrid.SelectedItem; if (selectedMission == null) { return; } Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); var missionData = client.GetMission(selectedMission.Name); loadingDialog.Invoke(delegate { loadingDialog.Close(); var filter = "Spring Mod Archive (*.sdz)|*.sdz|All files (*.*)|*.*"; var saveFileDialog = new SaveFileDialog { DefaultExt = "sdz", Filter = filter, RestoreDirectory = true }; if (saveFileDialog.ShowDialog() == true) { File.WriteAllBytes(saveFileDialog.FileName, missionData.Mutator.ToArray()); } WelcomeDialog.LoadExistingMission(saveFileDialog.FileName); }); } catch (FaultException <ExceptionDetail> ex) { MessageBox.Show(ex.Message); } }); loadingDialog.ShowDialog(); }
public static bool SendMission(Mission mission, string password, int?missionId) { try { var info = new ZkData.Mission() { Description = mission.Description, DescriptionStory = mission.DescriptionStory != String.Empty ? mission.DescriptionStory : null, Map = mission.Map.Name, Mod = mission.Mod.Name, Name = mission.Name, ScoringMethod = mission.ScoringMethod, Script = mission.GetScript(), ModRapidTag = mission.RapidTag, }; var slots = mission.GetSlots(); var image = File.ReadAllBytes(mission.ImagePath).ToImage(96, 96); var pngEncoder = new PngBitmapEncoder(); pngEncoder.Frames.Add(BitmapFrame.Create(image)); var imageStream = new MemoryStream(); pngEncoder.Save(imageStream); imageStream.Position = 0; info.Image = new Binary(imageStream.ToArray()); if (ApplicationDeployment.IsNetworkDeployed) { info.MissionEditorVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); } using (var unitSync = new UnitSync(Settings.Default.SpringPath)) info.SpringVersion = unitSync.Version; if (missionId.HasValue) { info.MissionID = missionId.Value; } string tempPath = null; var missionFileName = "publish_mission_temp.sdz"; try { var paths = new SpringPaths(Settings.Default.SpringPath); using (var unitSync = new PlasmaShared.UnitSyncLib.UnitSync(paths)) { var modPath = Path.Combine(paths.WritableDirectory, "games"); tempPath = Path.Combine(modPath, missionFileName); } if (File.Exists(tempPath)) { File.Delete(tempPath); } mission.CreateArchive(tempPath); PlasmaShared.UnitSyncLib.Mod mod; using (var unitSync = new PlasmaShared.UnitSyncLib.UnitSync(paths)) { mod = unitSync.GetModFromArchive(mission.Mod.ArchiveName); if (mod == null) { throw new Exception("Mod metadata not extracted: mod not found"); } } info.Mutator = new Binary(File.ReadAllBytes(tempPath)); var client = MissionServiceClientFactory.MakeClient(); client.SendMission(info, slots, mission.Author, password, mod); MessageBox.Show("Mission successfully uploaded.\n\rIt is now accessible from the lobby.\r\nPlease make sure it works!"); return(true); } catch (Exception e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } finally { try { if (tempPath != null && File.Exists(tempPath)) { File.Delete(tempPath); } } catch {} } } catch (FaultException <ExceptionDetail> e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } catch (FaultException e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } }