private void buttonExtLoad_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = System.IO.Path.Combine(Tools.GetAppDataDirectory(), "Actions"); if (!System.IO.Directory.Exists(dlg.InitialDirectory)) { System.IO.Directory.CreateDirectory(dlg.InitialDirectory); } dlg.DefaultExt = "atf"; dlg.AddExtension = true; dlg.Filter = "Action Text Files (*.atf)|*.atf|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { using (System.IO.StreamReader sr = new System.IO.StreamReader(dlg.FileName)) { string err; ActionProgram ap = ActionProgram.FromFile(dlg.FileName, out err); if (ap == null) { Forms.MessageBoxTheme.Show(this, "Failed to load text file" + Environment.NewLine + err); } else { LoadProgram(ap); } } } }
public bool EditInEditor(string file = null) // edit in editor, swap to this { try { if (file == null) // if not associated directly with a file, save to a temp one { string filename = Name.Length > 0 ? Name : "Default"; file = System.IO.Path.Combine(System.IO.Path.GetTempPath(), filename.SafeFileString() + ".atf"); if (!SaveText(file)) { return(false); } } while (true) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = Tools.AssocQueryString(Tools.AssocStr.Executable, ".txt"); p.StartInfo.Arguments = file.QuoteString(); p.Start(); p.WaitForExit(); string err; ActionProgram apin = ActionProgram.FromFile(file, out err); if (apin == null) { DialogResult dr = Forms.MessageBoxTheme.Show("Editing produced the following errors" + Environment.NewLine + Environment.NewLine + err + Environment.NewLine + "Click Retry to correct errors, Cancel to abort editing", "Warning", MessageBoxButtons.RetryCancel); if (dr == DialogResult.Cancel) { return(false); } } else { programsteps = apin.programsteps; Name = apin.Name; StoredInFile = apin.StoredInFile; return(true); } } } catch { } Forms.MessageBoxTheme.Show("Unable to run text editor - check association for .txt files"); return(false); }