public override void execute() { SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "Lilypond|*.ly|PDF|*.pdf" }; if (saveFileDialog.ShowDialog() == true) { string extension = System.IO.Path.GetExtension(saveFileDialog.FileName); if (extension.EndsWith(".ly")) { SaveToLilypondCommand saveToLilypondCommand = new SaveToLilypondCommand(_lilypondEditor, saveFileDialog.FileName); saveToLilypondCommand.execute(); } else if (extension.EndsWith(".pdf")) { SaveToPDFCommand saveToLilypondCommand = new SaveToPDFCommand(_lilypondEditor, saveFileDialog.FileName); saveToLilypondCommand.execute(); } else { MessageBox.Show($"Extension {extension} is not supported."); } } }
public override void execute() { if (_fileName == "") { SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "PDF|*.pdf" }; if (saveFileDialog.ShowDialog() == true) { _fileName = saveFileDialog.FileName; } else { return; } } string withoutExtension = Path.GetFileNameWithoutExtension(_fileName); string tmpFileName = $"{_fileName}-tmp.ly"; SaveToLilypondCommand saveToLilypond = new SaveToLilypondCommand(_lilypondEditor, tmpFileName); saveToLilypond.execute(); string lilypondLocation = @"C:\Program Files (x86)\LilyPond\usr\bin\lilypond.exe"; string sourceFolder = Path.GetDirectoryName(tmpFileName); string sourceFileName = Path.GetFileNameWithoutExtension(tmpFileName); string targetFolder = Path.GetDirectoryName(_fileName); string targetFileName = Path.GetFileNameWithoutExtension(_fileName); var process = new Process { StartInfo = { WorkingDirectory = sourceFolder, WindowStyle = ProcessWindowStyle.Hidden, Arguments = String.Format("--pdf \"{0}\\{1}.ly\"", sourceFolder, sourceFileName), FileName = lilypondLocation } }; process.Start(); while (!process.HasExited) { /* Wait for exit */ } try { if (sourceFolder != targetFolder || sourceFileName != targetFileName) { File.Move(sourceFolder + "\\" + sourceFileName + ".pdf", targetFolder + "\\" + targetFileName + ".pdf"); File.Delete(tmpFileName); } MessageBox.Show("Successful saved to PDF"); } catch { MessageBox.Show("Could not convert to PDF"); } _fileName = string.Empty; }