public ExportForm(ScoreBook book) { InitializeComponent(); Icon = Properties.Resources.MainIcon; ShowInTaskbar = false; if (!book.ExporterArgs.ContainsKey(ArgsKey) || !(book.ExporterArgs[ArgsKey] is SusArgs)) { book.ExporterArgs[ArgsKey] = new SusArgs(); } var args = book.ExporterArgs[ArgsKey] as SusArgs; browseButton.Click += (s, e) => { var dialog = new SaveFileDialog() { Filter = Filter }; if (dialog.ShowDialog(this) == DialogResult.OK) { outputBox.Text = dialog.FileName; } }; exportButton.Click += (s, e) => { if (string.IsNullOrEmpty(OutputPath)) { browseButton.PerformClick(); } if (string.IsNullOrEmpty(OutputPath)) { MessageBox.Show(this, ErrorStrings.OutputPathRequired, Program.ApplicationName); return; } try { exporter.CustomArgs = args; exporter.Export(OutputPath, book); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(this, ErrorStrings.ExportFailed, Program.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error); Program.DumpException(ex); } }; }
public void Export(IScoreBookExportPluginArgs args) { var book = args.GetScoreBook(); SusArgs susArgs = JsonConvert.DeserializeObject <SusArgs>(args.GetCustomData() ?? "") ?? new SusArgs(); if (!args.IsQuick) { var vm = new SusExportWindowViewModel(book, susArgs); var window = new SusExportWindow() { DataContext = vm }; var result = window.ShowDialog(); if (!result.HasValue || !result.Value) { throw new UserCancelledException(); } args.SetCustomData(JsonConvert.SerializeObject(susArgs)); } var exporter = new SusExporter(book, susArgs); exporter.Export(args.Stream); }
public ExportForm(ScoreBook book) { InitializeComponent(); Icon = Properties.Resources.MainIcon; ShowInTaskbar = false; levelDropDown.Items.AddRange(Enumerable.Range(1, 14).SelectMany(p => new string[] { p.ToString(), p + "+" }).ToArray()); difficultyDropDown.Items.AddRange(new string[] { "BASIC", "ADVANCED", "EXPERT", "MASTER", "WORLD'S END" }); if (!book.ExporterArgs.ContainsKey(ArgsKey) || !(book.ExporterArgs[ArgsKey] is SusArgs)) { book.ExporterArgs[ArgsKey] = new SusArgs(); } var args = book.ExporterArgs[ArgsKey] as SusArgs; titleBox.Text = book.Title; artistBox.Text = book.ArtistName; notesDesignerBox.Text = book.NotesDesignerName; difficultyDropDown.SelectedIndex = (int)args.PlayDifficulty; levelDropDown.Text = args.PlayLevel; songIdBox.Text = args.SongId; soundFileBox.Text = args.SoundFileName; soundOffsetBox.Value = args.SoundOffset; jacketFileBox.Text = args.JacketFilePath; hasPaddingBarBox.Checked = args.HasPaddingBar; browseButton.Click += (s, e) => { var dialog = new SaveFileDialog() { Filter = Filter }; if (dialog.ShowDialog(this) == DialogResult.OK) { outputBox.Text = dialog.FileName; } }; exportButton.Click += (s, e) => { if (string.IsNullOrEmpty(OutputPath)) { browseButton.PerformClick(); } if (string.IsNullOrEmpty(OutputPath)) { MessageBox.Show(this, "出力先を指定してください。", Program.ApplicationName); return; } book.Title = titleBox.Text; book.ArtistName = artistBox.Text; book.NotesDesignerName = notesDesignerBox.Text; args.PlayDifficulty = (SusArgs.Difficulty)difficultyDropDown.SelectedIndex; args.PlayLevel = levelDropDown.Text; args.SongId = songIdBox.Text; args.SoundFileName = soundFileBox.Text; args.SoundOffset = soundOffsetBox.Value; args.JacketFilePath = jacketFileBox.Text; args.HasPaddingBar = hasPaddingBarBox.Checked; try { exporter.CustomArgs = args; exporter.Export(OutputPath, book); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(this, "エクスポートに失敗しました。", Program.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error); Program.DumpException(ex); } }; }