private void PanelType_SelectedIndexChanged(object sender, EventArgs e) { ActionProgram.ProgramConditionClass newcls = indextoclassifier[progmajortype.SelectedIndex]; if (newcls != classifier) { ActionProgram p = cd.action.HasChars() ? actionfile.actionprogramlist.Get(cd.action) : null; if (p != null) // if we have an existing program, may need to alter it { // to not full with prog class being full, need to clear, not in correct form if (newcls != ActionProgram.ProgramConditionClass.Full && p.progclass == ActionProgram.ProgramConditionClass.Full) { cd.action = cd.actiondata = ""; // only change these } else if (newcls == ActionProgram.ProgramConditionClass.Key) // key, make sure no say { p.SetKeySayProgram(p.keyuserdata, null); } else if (newcls == ActionProgram.ProgramConditionClass.Say) //say, make sure no key { p.SetKeySayProgram(null, p.sayuserdata); } } classifier = newcls; UpdateControls(); } }
private void buttonExtLoad_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = applicationfolder; 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)) { ActionProgram ap = new ActionProgram(); string err = ap.ReadFile(dlg.FileName); if (err.Length > 0) { ExtendedControls.MessageBoxTheme.Show(this, "Failed to load text file" + Environment.NewLine + err); } else { LoadProgram(ap); } } } }
public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile, System.Func <string, List <BaseUtils.TypeHelpers.PropertyNameInfo> > func, Icon ic, ToolTip toolTip) { cd = cond; // on creation, the cond with be set to onVoice with one condition, checked in ActionController.cs:SetPackEditor.. textBoxInput = new ExtendedControls.ExtTextBox(); textBoxInput.Location = new Point(panelxmargin, panelymargin); textBoxInput.Size = new Size(356, 24); // manually matched to size of eventprogramcondition bits textBoxInput.Text = cd.fields[0].matchstring; textBoxInput.TextChanged += TextBoxInput_TextChanged; textBoxInput.SetTipDynamically(toolTip, "Enter the voice input to recognise. Multiple phrases seperate with semicolons"); Controls.Add(textBoxInput); ActionProgram p = cond.action.HasChars() ? actionfile.actionprogramlist.Get(cond.action) : null; ActionProgram.ProgramConditionClass classifier = p != null ? p.progclass : ActionProgram.ProgramConditionClass.KeySay; ucprog = new ActionPackEditProgram(); ucprog.Location = new Point(textBoxInput.Right + 16, 0); ucprog.Size = new Size(400, this.Height); // init all the panels to 0/this height, select widths ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier); ucprog.onEditKeys = onEditKeys; ucprog.onEditSay = onEditSay; ucprog.onAdditionalNames += () => { return(func(cd.eventname)); }; ucprog.SuggestedName += () => { string textparse = (textBoxInput.Text.Length > 0 && !textBoxInput.Text.Equals("?")) ? ("_" + textBoxInput.Text.Split(';')[0].SafeVariableString()) : ""; return("VoiceInput" + textparse); }; ucprog.RefreshEvent += () => { RefreshIt(); }; Controls.Add(ucprog); }
public void WriteJSON(StreamWriter sr) // kept for reference and debugging.. files are now written in ASCII { JObject jo = new JObject(); jo["Conditions"] = actioneventlist.GetJSONObject(); JObject evt = new JObject(); JArray jf = new JArray(); ActionProgram ap = null; for (int i = 0; (ap = actionprogramlist.Get(i)) != null; i++) { JObject j1 = ap.WriteJSONObject(); jf.Add(j1); } evt["ProgramSet"] = jf; jo["Programs"] = evt; jo["Enabled"] = enabled; jo["Install"] = installationvariables.ToJSONObject(); string json = jo.ToString(Formatting.Indented); sr.Write(json); }
public ActionProgramRun(ActionFile af, // associated file ActionProgram r, // the program ConditionVariables iparas, // input variables to the program only.. not globals ActionRun runner, // who is running it.. ActionCoreController ed) : base(r.Name) // allow a pause { actionfile = af; actionrun = runner; actioncontroller = ed; execlevel = 0; execstate[execlevel] = ExecState.On; nextstepnumber = 0; //System.Diagnostics.Debug.WriteLine("Run " + actionfile.name + "::" + r.Name); //ActionData.DumpVars(gvars, " Func Var:"); inputvars = iparas; // current vars is set up by ActionRun at the point of invokation to have the latests globals List <ActionBase> psteps = new List <ActionBase>(); ActionBase ac; for (int i = 0; (ac = r.GetStep(i)) != null; i++) { psteps.Add(ActionBase.CreateCopy(ac)); } programsteps = psteps; }
void LoadProgram(ActionProgram prog) { foreach (Group g in groups) { g.panel.Controls.Clear(); panelVScroll.Controls.Remove(g.panel); } groups.Clear(); curprog = new ActionProgram(prog.Name); initialprogname = textBoxBorderName.Text = prog.Name; SuspendLayout(); panelVScroll.SuspendLayout(); ActionBase ac; int step = 0; while ((ac = prog.GetStep(step)) != null) { ActionBase ca = ActionBase.CreateCopy(ac);// COPY it.. so we can modify without altering current curprog.Add(ca); CreateStep(-1, ca); step++; } RepositionGroups(); panelVScroll.ResumeLayout(); ResumeLayout(); }
void UpdateProgram(ActionProgram np) { actionfile.actionprogramlist.AddOrChange(np); // replaces or adds (if its a new name) same as rename cd.action = np.Name; RefreshEvent(); UpdateControls(); }
private void UpdateControls() { proglist.Visible = progedit.Visible = paras.Visible = (classifier == ActionProgram.ProgramConditionClass.Full); buttonKeys.Visible = (classifier == ActionProgram.ProgramConditionClass.KeySay || classifier == ActionProgram.ProgramConditionClass.Key); buttonSay.Visible = (classifier == ActionProgram.ProgramConditionClass.KeySay || classifier == ActionProgram.ProgramConditionClass.Say); proglist.Enabled = false; if (cd.action.HasChars()) { proglist.SelectedItem = cd.action; } else { proglist.SelectedIndex = 0; } proglist.Enabled = true; paras.Text = cd.actiondata.Alt(""); buttonKeys.Text = "Enter Key"; buttonSay.Text = "Enter Speech"; ActionProgram p = cd.action.HasChars() ? actionfile.actionprogramlist.Get(cd.action) : null; if (p != null) { buttonKeys.Text = StringParser.FirstQuotedWord(p.keyuserdata, " ,", buttonKeys.Text, prefix: "Key:").Left(25); buttonSay.Text = StringParser.FirstQuotedWord(p.sayuserdata, " ,", buttonSay.Text, prefix: "Say:").Left(25); } }
public string Read(JObject jo, out bool readenable) // KEEP JSON reader for backwards compatibility. { string errlist = ""; readenable = false; try { JArray ivarja = (JArray)jo["Install"]; if (!ivarja.Empty()) { installationvariables.FromJSONObject(ivarja); } JObject jcond = (JObject)jo["Conditions"]; if (jcond != null) { actioneventlist.FromJSON(jcond); } JObject jprog = (JObject)jo["Programs"]; if (jprog != null) { JArray jf = (JArray)jprog["ProgramSet"]; foreach (JObject j in jf) { ActionProgram ap = new ActionProgram(); string lerr = ap.Read(j); if (lerr.Length == 0) // if can't load, we can't trust the pack, so indicate error so we can let the user manually sort it out { actionprogramlist.Add(ap); } else { errlist += lerr; } } } if (jo["Enabled"] != null) { enabled = (bool)jo["Enabled"]; readenable = true; } //System.Diagnostics.Debug.WriteLine("JSON read enable " + enabled); return(errlist); } catch { return(errlist + " Also Missing JSON fields"); } }
public Tuple <ActionFile, ActionProgram> FindProgram(string req, ActionFile preferred = null) // find a program { ActionProgram ap = null; string file = null, prog; int colon = req.IndexOf("::"); if (colon != -1) { file = req.Substring(0, colon); prog = req.Substring(colon + 2); } else { prog = req; } if (file != null) // if file given, only search that { ActionFile f = actionfiles.Find(x => x.name.Equals(file)); if (f != null) // found file.. { ap = f.actionprogramlist.Get(prog); return((ap != null) ? new Tuple <ActionFile, ActionProgram>(f, ap) : null); } } else { if (preferred != null) // if no file stated, and we have a preferred { ap = preferred.actionprogramlist.Get(prog); // get in local program list first if (ap != null) { return(new Tuple <ActionFile, ActionProgram>(preferred, ap)); } } foreach (ActionFile f in actionfiles) { ap = f.actionprogramlist.Get(prog); if (ap != null) // gotcha { return(new Tuple <ActionFile, ActionProgram>(f, ap)); } } } return(null); }
public void AddOrChange(ActionProgram ap) { int existing = programs.FindIndex(x => x.Name.Equals(ap.Name)); if (existing >= 0) { programs[existing] = ap; } else { programs.Add(ap); } }
public void Init(Icon ic, ActionCoreController cp, string appfolder, List <BaseUtils.TypeHelpers.PropertyNameInfo> vbs, // list any variables you want in condition statements - passed to config menu, passed back up to condition, not null string pfilesetname, // file set name ActionProgram prog = null, // give the program to display string[] defprogs = null, // list any default program names string suggestedname = null, bool edittext = false) // give a suggested name, if prog is null { this.Icon = ic; actioncorecontroller = cp; applicationfolder = appfolder; currentvarlist = new List <BaseUtils.TypeHelpers.PropertyNameInfo>(vbs); var enumlist = new Enum[] { AFIDs.ActionProgramEditForm, AFIDs.ActionProgramEditForm_labelName, AFIDs.ActionProgramEditForm_buttonExtDisk, AFIDs.ActionProgramEditForm_buttonExtLoad, AFIDs.ActionProgramEditForm_buttonExtSave, AFIDs.ActionProgramEditForm_buttonExtEdit, AFIDs.ActionProgramEditForm_extButtonHeader }; BaseUtils.Translator.Instance.TranslateControls(this, enumlist); bool winborder = ExtendedControls.Theme.Current.ApplyDialog(this); statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder; label_index.Text = this.Text; labelSet.Text = pfilesetname + "::"; textBoxBorderName.Location = new Point(labelSet.Location.X + labelSet.Width + 8, textBoxBorderName.Location.Y); if (defprogs != null) { definedprograms = defprogs; } if (suggestedname != null) { textBoxBorderName.Text = suggestedname; } if (prog != null) { LoadProgram(prog); } panelVScroll.ContextMenuStrip = contextMenuStrip1; panelVScroll.MouseDown += panelVScroll_MouseDown; editastextimmediately = edittext; #if !DEBUG buttonExtDisk.Visible = false; #endif }
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 (!WriteFile(file)) { return(false); } } while (true) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = BaseUtils.AssociateExe.AssocQueryString(BaseUtils.Win32.UnsafeNativeMethods.AssocStr.Executable, ".txt"); p.StartInfo.Arguments = file.QuoteString(); p.Start(); p.WaitForExit(); ActionProgram apin = new ActionProgram(); string err = apin.ReadFile(file); if (err.Length > 0) { DialogResult dr = ExtendedControls.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 { Name = apin.Name; programsteps = apin.programsteps; HeaderText = apin.HeaderText; return(true); } } } catch { } ExtendedControls.MessageBoxTheme.Show("Unable to run text editor - check association for .txt files"); return(false); }
public bool EditProgram(string s, string outername, ActionCoreController cp, string appfolder) { int colon = s.IndexOf(':'); if (colon >= 0) { s = s.Substring(0, colon); } int bracket = s.IndexOf('('); if (bracket >= 0) { s = s.Substring(0, bracket); } ActionProgram p = Get(s); if (p != null) { if (p.StoredInSubFile != null) { p.EditInEditor(p.StoredInSubFile); // Edit in the editor.. } else { ActionProgramEditForm apf = new ActionProgramEditForm(); apf.EditProgram += EditProgram; this.edoutername = outername; this.cp = cp; this.appfolder = appfolder; List <BaseUtils.TypeHelpers.PropertyNameInfo> additionalfieldnames = new List <BaseUtils.TypeHelpers.PropertyNameInfo>(); // We don't have any names to contribute going thru this path apf.Init("Action program ", cp.Icon, cp, appfolder, additionalfieldnames, outername, p, GetActionProgramList(), ""); System.Windows.Forms.DialogResult res = apf.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { ActionProgram np = apf.GetProgram(); AddOrChange(np); // replaces or adds (if its a new name) same as rename } return(true); } } return(false); }
public Tuple <ActionFile, ActionProgram> FindProgram(string packname, string progname) { ActionFile f = actionfiles.Find(x => x.name.Equals(packname)); if (f != null) { ActionProgram ap = f.actionprogramlist.Get(progname); // get in local program list first if (ap != null) { return(new Tuple <ActionFile, ActionProgram>(f, ap)); } } return(null); }
public ActionProgram GetProgram() // call only when OK returned { ActionProgram ap = new ActionProgram(curprog.Name, curprog.StoredInSubFile); ActionBase ac; int step = 0; while ((ac = curprog.GetStep(step++)) != null) { if (ac != null) { ap.Add(ac); } } return(ap); }
public void Init(string t, Icon ic, ActionCoreController cp, string appfolder, List <string> vbs, // list any variables you want in condition statements - passed to config menu, passed back up to condition, not null string pfilesetname, // file set name ActionProgram prog = null, // give the program to display string[] defprogs = null, // list any default program names string suggestedname = null, bool edittext = false) // give a suggested name, if prog is null { this.Icon = ic; actioncorecontroller = cp; applicationfolder = appfolder; startvarlist = vbs; currentvarlist = new List <string>(startvarlist); bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont); statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder; this.Text = label_index.Text = t; filesetname = pfilesetname; labelSet.Text = filesetname + "::"; textBoxBorderName.Location = new Point(labelSet.Location.X + labelSet.Width + 8, textBoxBorderName.Location.Y); if (defprogs != null) { definedprograms = defprogs; } if (suggestedname != null) { textBoxBorderName.Text = suggestedname; } if (prog != null) { LoadProgram(prog); } panelVScroll.ContextMenuStrip = contextMenuStrip1; panelVScroll.MouseDown += panelVScroll_MouseDown; editastextimmediately = edittext; #if !DEBUG buttonExtDisk.Visible = false; #endif }
private void Saypress_Click(object sender, EventArgs e) { ActionProgram p = cd.action.HasChars() ? actionfile.actionprogramlist.Get(cd.action) : null; string ud = onEditSay(this, p != null ? p.sayuserdata.Alt("") : "", actioncorecontroller); if (ud != null) { if (p == null) { p = new ActionProgram(GetSuggestedName()); } paras.Text = cd.actiondata = ""; p.SetKeySayProgram(p.keyuserdata, ud); UpdateProgram(p); } }
// now = true, run it immediately, else run at end of queue. Optionally pass in handles and dialogs in case its a sub prog public void Run(bool now, ActionFile fileset, ActionProgram r, Variables inputparas, FunctionPersistentData fh = null, Dictionary<string, ExtendedControls.ConfigurableForm> d = null, bool closeatend = true) { if (now) { if (progcurrent != null) // if running, push the current one back onto the queue to be picked up progqueue.Insert(0, progcurrent); progcurrent = new ActionProgramRun(fileset, r, inputparas, this, actioncontroller); // now we run this.. no need to push to stack progcurrent.PrepareToRun(new Variables(progcurrent.inputvariables, actioncontroller.Globals, fileset.filevariables), fh == null ? new FunctionPersistentData() : fh, d == null ? new Dictionary<string, ExtendedControls.ConfigurableForm>() : d, closeatend); // if no filehandles, make them and close at end } else { progqueue.Add(new ActionProgramRun(fileset, r, inputparas, this, actioncontroller)); } }
private void Keypress_Click(object sender, EventArgs e) { ActionProgram p = cd.action.HasChars() ? actionfile.actionprogramlist.Get(cd.action) : null; string ud = onEditKeys(this.FindForm(), this.Icon, p != null ? p.keyuserdata.Alt("") : ""); if (ud != null) { if (p == null) { p = new ActionProgram(GetSuggestedName()); } paras.Text = cd.actiondata = ""; p.SetKeySayProgram(ud, p.sayuserdata); UpdateProgram(p); } }
private void comboBoxCustomEditProg_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxCustomEditProg.Enabled) { string progname = comboBoxCustomEditProg.Text.Replace(" (Ext)", ""); // remove the EXT marker ActionProgram p = null; if (!progname.Equals("New")) { p = actionfile.ProgramList.Get(progname); } if (p != null && p.StoredInSubFile != null) { p.EditInEditor(p.StoredInSubFile); // Edit in the editor.. } else { ActionProgramEditForm apf = new ActionProgramEditForm(); apf.EditProgram += EditProgram; apf.Init(this.Icon, actioncorecontroller, applicationfolder, AdditionalNames(null), // no event associated, so just return the globals in effect actionfile.Name, p, actionfile.ProgramList.GetActionProgramList(), "", ModifierKeys.HasFlag(Keys.Shift)); DialogResult res = apf.ShowDialog(this); if (res == DialogResult.OK) { ActionProgram np = apf.GetProgram(); actionfile.ProgramList.AddOrChange(np); // replaces or adds (if its a new name) same as rename Usercontrol_RefreshEvent(); } else if (res == DialogResult.Abort) // delete { ActionProgram np2 = apf.GetProgram(); actionfile.ProgramList.Delete(np2.Name); Usercontrol_RefreshEvent(); } } } }
public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile, System.Func <string, List <BaseUtils.TypeHelpers.PropertyNameInfo> > func, Icon ic, ToolTip toolTip) { cd = cond; //this.BackColor = Color.Red; // for debug // layed out for 12 point. UC below require 28 point area eventtype = new ExtendedControls.ExtComboBox(); eventtype.Items.AddRange(events); eventtype.Location = new Point(panelxmargin, panelymargin); eventtype.Size = new Size(140, 24); if (cd.EventName != null) { eventtype.SelectedItem = cd.EventName; } eventtype.SelectedIndexChanged += Eventtype_SelectedIndexChanged; Controls.Add(eventtype); uccond = new ActionPackEditCondition(); uccond.Location = new Point(eventtype.Right + 16, 0); uccond.Size = new Size(200, 28); // init all the panels to 0/this height, select widths uccond.Init(cond, ic, toolTip); uccond.onAdditionalNames += () => { return(func(eventtype.Text)); }; Controls.Add(uccond); ActionProgram p = cond.Action.HasChars() ? actionfile.ProgramList.Get(cond.Action) : null; ActionProgram.ProgramConditionClass classifier = p != null ? p.ProgramClass : ActionProgram.ProgramConditionClass.Full; ucprog = new ActionPackEditProgram(); ucprog.Location = new Point(uccond.Right + 16, 0); ucprog.Size = new Size(400, 28); // init all the panels to 0/this height, select widths ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier); ucprog.onEditKeys = onEditKeys; ucprog.onEditSay = onEditSay; ucprog.onAdditionalNames += () => { return(func(eventtype.Text)); }; ucprog.SuggestedName += () => { return(eventtype.Text); }; ucprog.RefreshEvent += () => { RefreshIt(); }; Controls.Add(ucprog); }
private void Saypress_Click(object sender, EventArgs e) { ActionProgram p = cd.Action.HasChars() ? actionfile.ProgramList.Get(cd.Action) : null; string ud = onEditSay(this.FindForm(), p != null ? p.ProgramClassSayUserData.Alt("") : "", actioncorecontroller); if (ud != null) { if (p == null) { p = new ActionProgram(GetSuggestedName()); } paras.Text = ""; cd.ActionVars = new Variables(); p.SetKeySayProgram(p.ProgramClassKeyUserData, ud); UpdateProgram(p); } }
public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile, System.Func <string, List <string> > func, Icon ic, ToolTip toolTip) { cd = cond; anfunc = func; eventtype = new ExtendedControls.ComboBoxCustom(); eventtype.Items.AddRange(events); eventtype.Location = new Point(panelxmargin, panelymargin); eventtype.Size = new Size(140, 24); eventtype.DropDownHeight = 400; eventtype.DropDownWidth = eventtype.Width * 3 / 2; if (cd.eventname != null) { eventtype.SelectedItem = cd.eventname; } eventtype.SelectedIndexChanged += Eventtype_SelectedIndexChanged; Controls.Add(eventtype); uccond = new ActionPackEditCondition(); uccond.Location = new Point(eventtype.Right + 16, 0); uccond.Size = new Size(200, this.Height); // init all the panels to 0/this height, select widths uccond.Init(cond, ic, toolTip); uccond.onAdditionalNames += () => { return(anfunc(eventtype.Text)); }; Controls.Add(uccond); ActionProgram p = cond.action.HasChars() ? actionfile.actionprogramlist.Get(cond.action) : null; ActionProgram.ProgramConditionClass classifier = p != null ? p.progclass : ActionProgram.ProgramConditionClass.Full; ucprog = new ActionPackEditProgram(); ucprog.Location = new Point(uccond.Right + 16, 0); ucprog.Size = new Size(400, this.Height); // init all the panels to 0/this height, select widths ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier); ucprog.onEditKeys = onEditKeys; ucprog.onEditSay = onEditSay; ucprog.onAdditionalNames += () => { return(anfunc(eventtype.Text)); }; ucprog.SuggestedName += () => { return(eventtype.Text); }; ucprog.RefreshEvent += () => { RefreshIt(); }; Controls.Add(ucprog); }
public string ReadFile(string filename, out bool readenable) // string, empty if no errors { readenable = false; Clear(filename, Path.GetFileNameWithoutExtension(filename)); try { var utc8nobom = new UTF8Encoding(false); // give it the default UTF8 no BOM encoding, it will detect BOM or UCS-2 automatically using (StreamReader sr = new StreamReader(filename, utc8nobom)) // read directly from file.. presume UTF8 no bom { string firstline = sr.ReadLine(); fileencoding = sr.CurrentEncoding; System.Diagnostics.Debug.WriteLine("File " + filename + " is in " + fileencoding.BodyName + " is utc8nobom? " + Equals(utc8nobom, fileencoding)); if (firstline == "{") { string json = firstline + Environment.NewLine + sr.ReadToEnd(); sr.Close(); try { JObject jo = JObject.Parse(json); return(Read(jo, out readenable)); } catch { return("Invalid JSON" + Environment.NewLine); } } else if (firstline == "ACTIONFILE V4") { string line; int lineno = 1; // on actionFILE V4 while ((line = sr.ReadLine()) != null) { lineno++; // on line of read.. line.Trim(); if (line.StartsWith("ENABLED", StringComparison.InvariantCultureIgnoreCase)) { line = line.Substring(7).Trim().ToLower(); if (line == "true") { enabled = true; } else if (line == "false") { enabled = false; } else { return(name + " " + lineno + " ENABLED is neither true or false" + Environment.NewLine); } readenable = true; } else if (line.StartsWith("PROGRAM", StringComparison.InvariantCultureIgnoreCase)) { ActionProgram ap = new ActionProgram(); string err = ap.Read(sr, ref lineno); if (err.Length > 0) { return(name + " " + err); } ap.Rename(line.Substring(7).Trim()); //MUST rename now, after read, as read clears the name expecting PROGRAM actionprogramlist.Add(ap); } else if (line.StartsWith("INCLUDE", StringComparison.InvariantCultureIgnoreCase)) { string incfilename = line.Substring(7).Trim(); if (!incfilename.Contains("/") && !incfilename.Contains("\\")) { incfilename = Path.Combine(Path.GetDirectoryName(filename), incfilename); } ActionProgram ap = new ActionProgram("", incfilename); // NAME will be filled in by PROGRAM statement in file string err = ap.ReadFile(incfilename); if (err.Length > 0) { return(name + " " + err); } actionprogramlist.Add(ap); } else if (line.StartsWith("EVENT", StringComparison.InvariantCultureIgnoreCase)) { Condition c = new Condition(); string err = c.Read(line.Substring(5).Trim(), true); if (err.Length > 0) { return(name + " " + lineno + " " + err + Environment.NewLine); } else if (c.action.Length == 0 || c.eventname.Length == 0) { return(name + " " + lineno + " EVENT Missing event name or action" + Environment.NewLine); } actioneventlist.Add(c); } else if (line.StartsWith("INSTALL", StringComparison.InvariantCultureIgnoreCase)) { ConditionVariables c = new ConditionVariables(); if (c.FromString(line.Substring(7).Trim(), ConditionVariables.FromMode.OnePerLine) && c.Count == 1) { installationvariables.Add(c); } else { return(name + " " + lineno + " Incorrectly formatted INSTALL variable" + Environment.NewLine); } } else if (line.StartsWith("//") || line.StartsWith("REM", StringComparison.InvariantCultureIgnoreCase) || line.Length == 0) { } else { return(name + " " + lineno + " Invalid command" + Environment.NewLine); } } return(""); } else { return(name + " Header file type not recognised" + Environment.NewLine); } } } catch (Exception e) { return(filename + " Not readable" + Environment.NewLine + " " + e.Message); } }
public bool WriteFile() { try { var utc8nobom = new UTF8Encoding(false); System.Diagnostics.Trace.WriteLine("File " + FilePath + " written in " + FileEncoding.BodyName + " is utf8 no bom " + Equals(utc8nobom, FileEncoding)); using (StreamWriter sr = new StreamWriter(FilePath, false, FileEncoding)) { string rootpath = Path.GetDirectoryName(FilePath) + "\\"; sr.WriteLine("ACTIONFILE V4"); sr.WriteLine(); sr.WriteLine("ENABLED " + Enabled); sr.WriteLine(); if (InstallationVariables.Count > 0) { sr.WriteLine(InstallationVariables.ToString(prefix: "INSTALL ", separ: Environment.NewLine)); sr.WriteLine(); } if (FileEventList.Count > 0) { string currenteventgroup = null; for (int i = 0; i < FileEventList.Count; i++) { string evgroup = FileEventList[i].GroupName; if (evgroup != currenteventgroup) { if (currenteventgroup != null) { if (FileEventList[i].Tag != null) { sr.WriteLine(Environment.NewLine + (string)FileEventList[i].Tag); } else { sr.WriteLine(""); } } else { if (FileEventList[i].Tag != null) { sr.WriteLine((string)FileEventList[i].Tag); } else { sr.WriteLine(""); } } currenteventgroup = evgroup; sr.WriteLine("GROUP " + currenteventgroup + Environment.NewLine); } else { if (FileEventList[i].Tag != null) { sr.Write((string)FileEventList[i].Tag); } } sr.WriteLine("EVENT " + FileEventList[i].ToString(includeaction: true)); } sr.WriteLine(); } if (ProgramList.Count > 0) { for (int i = 0; i < ProgramList.Count; i++) { ActionProgram f = ProgramList.Get(i); List <string> elv = new List <string>() { "// Events: " }; int totonline = 0; for (int ic = 0; ic < FileEventList.Count; ic++) { Condition c = FileEventList[ic]; if (c.Action.Equals(f.Name)) { string e = c.EventName; if (!c.IsAlwaysTrue()) { e += "?(" + c.ToString() + ")"; } if (c.ActionVars.Count > 0) { e += "(" + c.ActionVars.ToString() + ")"; } if (elv.Last().Length > 120) { elv.Add("// Events: "); totonline = 0; } elv[elv.Count - 1] += (totonline > 0 ? ", " : "") + e; totonline++; } } if (elv[0] == "// Events: ") { elv[0] += "None"; } if (f.HeaderText.HasChars()) { string[] lines = f.HeaderText.Split(Environment.NewLine); bool doneevents = false; foreach (var l in lines) { if (l.StartsWith("// Events:")) { if (!doneevents) { sr.WriteLine(string.Join(Environment.NewLine, elv)); doneevents = true; } } else { sr.WriteLine(l); } } } else { sr.WriteLine(automarker); sr.WriteLine("// " + f.Name); sr.WriteLine(string.Join(Environment.NewLine, elv)); sr.WriteLine(automarker); } if (f.StoredInSubFile != null) { string full = f.StoredInSubFile; // try and simplify the path here.. if (full.StartsWith(rootpath)) { full = full.Substring(rootpath.Length); } sr.WriteLine("INCLUDE " + full); f.WriteFile(f.StoredInSubFile); } else { f.Write(sr); } sr.WriteLine(); } } sr.Close(); } return(true); } catch { } return(false); }
public void Set(ActionProgram other) { Name = other.Name; programsteps = other.programsteps; }
public bool WriteFile() { try { var utc8nobom = new UTF8Encoding(false); System.Diagnostics.Debug.WriteLine("File " + filepath + " written in " + fileencoding.BodyName + " is utf8 no bom " + Equals(utc8nobom, fileencoding)); using (StreamWriter sr = new StreamWriter(filepath, false, fileencoding)) { string rootpath = Path.GetDirectoryName(filepath) + "\\"; sr.WriteLine("ACTIONFILE V4"); sr.WriteLine(); sr.WriteLine("ENABLED " + enabled); sr.WriteLine(); if (installationvariables.Count > 0) { sr.WriteLine(installationvariables.ToString(prefix: "INSTALL ", separ: Environment.NewLine)); sr.WriteLine(); } if (actioneventlist.Count > 0) { for (int i = 0; i < actioneventlist.Count; i++) { sr.WriteLine("EVENT " + actioneventlist.Get(i).ToString(includeaction: true)); } sr.WriteLine(); } if (actionprogramlist.Count > 0) { for (int i = 0; i < actionprogramlist.Count; i++) { ActionProgram f = actionprogramlist.Get(i); sr.WriteLine("//*************************************************************"); sr.WriteLine("// " + f.Name); string evl = ""; for (int ic = 0; ic < actioneventlist.Count; ic++) { Condition c = actioneventlist.Get(ic); if (c.action.Equals(f.Name)) { string e = c.eventname; if (!c.IsAlwaysTrue()) { e += "?(" + c.ToString() + ")"; } if (c.actiondata.Length > 0) { e += "(" + c.actiondata + ")"; } e += ", "; if (evl.Length + e.Length > 100) { sr.WriteLine("// Events: " + evl); evl = ""; } evl += e; } } if (evl.Length > 0) { evl = evl.Substring(0, evl.Length - 2); sr.WriteLine("// Events: " + evl); } sr.WriteLine("//*************************************************************"); if (f.StoredInSubFile != null) { string full = f.StoredInSubFile; // try and simplify the path here.. if (full.StartsWith(rootpath)) { full = full.Substring(rootpath.Length); } sr.WriteLine("INCLUDE " + full); f.WriteFile(f.StoredInSubFile); } else { f.Write(sr); } sr.WriteLine(); } } sr.Close(); } return(true); } catch { } return(false); }
public void Add(ActionProgram p) { programs.Add(p); }
private void Progedit_Click(object sender, EventArgs e) //FULL { bool shift = ModifierKeys.HasFlag(Keys.Shift); ActionProgram p = null; if (proglist.SelectedIndex > 0) // exclude NEW from checking for program { p = actionfile.actionprogramlist.Get(proglist.Text); } if (p != null && p.StoredInSubFile != null && shift) // if we have a stored in sub file, but we shift hit, cancel it { if (ExtendedControls.MessageBoxTheme.Show(this, "Do you want to bring the file back into the main file", "WARNING", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { p.CancelSubFileStorage(); shift = false; } else { return; // cancel, abort. } } if (p != null && p.StoredInSubFile != null) { p.EditInEditor(p.StoredInSubFile); // Edit in the editor.. this also updated the program steps held internally } else { string suggestedname = null; if (p == null) // if no program, create a new suggested name and clear any action data { suggestedname = GetSuggestedName(); paras.Text = ""; } ActionProgramEditForm apf = new ActionProgramEditForm(); apf.EditProgram += (s) => { if (!actionfile.actionprogramlist.EditProgram(s, actionfile.name, actioncorecontroller, applicationfolder)) { ExtendedControls.MessageBoxTheme.Show(this, "Unknown program or not in this file " + s); } }; // we init with a variable list based on the field names of the group (normally the event field names got by SetFieldNames) // pass in the program if found, and its action data. apf.Init("Action program ", this.Icon, actioncorecontroller, applicationfolder, onAdditionalNames(), actionfile.name, p, actionfile.actionprogramlist.GetActionProgramList(), suggestedname, ModifierKeys.HasFlag(Keys.Shift)); DialogResult res = apf.ShowDialog(); if (res == DialogResult.OK) { ActionProgram np = apf.GetProgram(); UpdateProgram(np); } else if (res == DialogResult.Abort) // delete { ActionProgram np2 = apf.GetProgram(); actionfile.actionprogramlist.Delete(np2.Name); cd.action = ""; RefreshEvent(); } } }