/// <summary> /// Загрузить параметры с файла. /// </summary> public static void Load() { if (!File.Exists(Filename)) { MessageBox.Show("Can`t find logPolitics file.\n'" + Filename + "' not found\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); try { Reset(); Save(); } catch { MessageBox.Show("Something Went Wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } MessageBox.Show("Done", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var data = ExOperators.Load(Filename); SavePrintLog = bool.Parse(data["SavePrintLog"]); SaveSerialMonitorLog = bool.Parse(data["SaveSerialMonitorLog"]); SaveManualControlLog = bool.Parse(data["SaveManualControlLog"]); SaveGlobalPrintLog = bool.Parse(data["SaveGlobalPrintLog"]); SaveGlobalVectLog = bool.Parse(data["SaveGlobalVectLog"]); PrintLogNameFormat = data["PrintLogNameFormat"]; SerialMonitorLogNameFormat = data["SerialMonitorLogNameFormat"]; ManualControlLogNameFormat = data["ManualControlLogNameFormat"]; MacroLogNameFormat = data["MacroLogNameFormat"]; GlobalPrintLogNameFormat = data["GlobalPrintLogNameFormat"]; GlobalVectLogNameFormat = data["GlobalVectLogNameFormat"]; }
/// <summary> /// Сохраняет параметры в файл опций. /// </summary> public static void Save() { var a = new Dictionary <string, string> { { "StepHeightConst", StepHeightConst.ToString() }, { "MaxDisConst", MaxDisConst.ToString() }, { "UseAutoSpeed", UseAutoSpeed.ToString() }, { "XMM", XMM.ToString(CultureInfo.InvariantCulture) }, { "YMM", YMM.ToString(CultureInfo.InvariantCulture) }, { "Mainbd", Mainbd.ToString() }, { "Mainport", Mainport }, { "Def_SPO", DefSpo.ToString() }, { "Def_RBO", DefRbo.ToString() }, { "Def_print_back", ExOperators.ColorToHex(DefPrintBack) }, { "Def_print_draw", ExOperators.ColorToHex(DefPrintDraw) }, { "Def_view_back", ExOperators.ColorToHex(DefViewBack) }, { "Def_view_draw", ExOperators.ColorToHex(DefViewDraw) }, { "MaxWidthSteps", MaxWidthSteps.ToString() }, { "MaxHeightSteps", MaxHeightSteps.ToString() }, { "ignoreRegisterExtentions", IgnoreRegisterExtentions.ToString() }, { "PathToArduino", PathToArduino }, { "def_board", DefBoard.ToString() }, { "UpKoof", UpKoof.ToString() }, { "Language", Lang.ToString() }, { "PreloadPlugins", PreloadPlugins.ToString() } }; ExOperators.Save(Filename, a, "Don`t EDIT this FILE!"); }
/// <summary> /// Сохранить параметры в файл. /// </summary> public static void Save() { var a = new Dictionary <string, string> { { "SavePrintLog", SavePrintLog.ToString() }, { "SaveSerialMonitorLog", SaveSerialMonitorLog.ToString() }, { "SaveManualControlLog", SaveManualControlLog.ToString() }, { "SaveMacroLog", SaveMacroLog.ToString() }, { "SaveGlobalPrintLog", SaveGlobalPrintLog.ToString() }, { "SaveGlobalVectLog", SaveGlobalVectLog.ToString() }, { "PrintLogNameFormat", PrintLogNameFormat }, { "SerialMonitorLogNameFormat", SerialMonitorLogNameFormat }, { "ManualControlLogNameFormat", ManualControlLogNameFormat }, { "MacroLogNameFormat", MacroLogNameFormat }, { "GlobalPrintLogNameFormat", GlobalPrintLogNameFormat }, { "GlobalVectLogNameFormat", GlobalVectLogNameFormat } }; ExOperators.Save(Filename, a, "Don`t EDIT this FILE!"); }
/// <summary> /// Загружает параметры с файла опций. /// </summary> public static void Load() { Ver = Application.ProductVersion; try { Build = int.Parse(File.ReadAllLines(BuildFilename)[1]); File.WriteAllText(BuildFilename, "<!--Don`t EDIT this FILE!-->\n" + ++Build); } catch { MessageBox.Show("Can`t find build file.\n'" + BuildFilename + "' not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; if (!File.Exists(Filename)) { MessageBox.Show("Can`t find options file.\n'" + Filename + "' not found\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); try { Reset(); Save(); } catch { MessageBox.Show("Something Went Wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } MessageBox.Show("Done", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var data = ExOperators.Load(Filename); StepHeightConst = int.Parse(data["StepHeightConst"]); MaxDisConst = int.Parse(data["MaxDisConst"]); UseAutoSpeed = bool.Parse(data["UseAutoSpeed"]); XMM = float.Parse(data["XMM"], CultureInfo.InvariantCulture); YMM = float.Parse(data["YMM"], CultureInfo.InvariantCulture); Mainbd = int.Parse(data["Mainbd"]); Mainport = data["Mainport"]; DefSpo = ExOperators.GetEnum <StartPrintOption>(data["Def_SPO"]); DefRbo = ExOperators.GetEnum <ReturnBackOption>(data["Def_RBO"]); DefPrintBack = ExOperators.ColorFromHex(data["Def_print_back"]); DefPrintDraw = ExOperators.ColorFromHex(data["Def_print_draw"]); DefViewBack = ExOperators.ColorFromHex(data["Def_view_back"]); DefViewDraw = ExOperators.ColorFromHex(data["Def_view_draw"]); MaxHeightSteps = int.Parse(data["MaxHeightSteps"]); MaxWidthSteps = int.Parse(data["MaxWidthSteps"]); IgnoreRegisterExtentions = bool.Parse(data["ignoreRegisterExtentions"]); PathToArduino = data["PathToArduino"]; DefBoard = ArduinoBoard.Boards.ToList().Find(p => p.ProgramName == data["def_board"]); UpKoof = int.Parse(data["UpKoof"]); Lang = data["Language"]; PreloadPlugins = bool.Parse(data["PreloadPlugins"]); }
/// <summary> /// —оздает новый экземпл¤р класса <see cref="Macro"/>, загружа¤ его из файла. /// </summary> /// <param name="filename">»м¤ файла.</param> public Macro(string filename) { try { Elems = new List <MacroElem>(0); XmlDocument document = new XmlDocument(); document.Load(filename); Name = document.ChildNodes[1].ChildNodes[0].Attributes[0].Value; Discr = document.ChildNodes[1].ChildNodes[0].Attributes[1].Value; PicFileName = document.ChildNodes[1].ChildNodes[0].Attributes[2].Value; string[] PicSizeValues = document.ChildNodes[1].ChildNodes[0].Attributes[3].Value.Split('_'); PicSize = new SizeF(float.Parse(PicSizeValues[0], CultureInfo.InvariantCulture), float.Parse(PicSizeValues[1], CultureInfo.InvariantCulture)); CreatedVersion = new Version( int.Parse(document.ChildNodes[1].ChildNodes[1].Attributes[0].Value), int.Parse(document.ChildNodes[1].ChildNodes[1].Attributes[1].Value), int.Parse(document.ChildNodes[1].ChildNodes[1].Attributes[2].Value), int.Parse(document.ChildNodes[1].ChildNodes[1].Attributes[3].Value)); Elems = new List <MacroElem>(); for (int i = 2; i <= document.ChildNodes[1].ChildNodes.Count - 1; i++) { MacroElemType type = MacroElem.ShortedTypeToNormal(ExOperators.GetEnum <MacroElemTypeShorted>(document.ChildNodes[1].ChildNodes[i].Attributes[0].Value)); int toolmove = int.Parse(document.ChildNodes[1].ChildNodes[i].Attributes[1].Value); string[] MoveToPointS = document.ChildNodes[1].ChildNodes[i].Attributes[2].Value.Split('_'); PointF MoveToPoint = new PointF(float.Parse(MoveToPointS[0], CultureInfo.InvariantCulture), float.Parse(MoveToPointS[1], CultureInfo.InvariantCulture)); string[] MoveRelativeS = document.ChildNodes[1].ChildNodes[i].Attributes[3].Value.Split('_'); PointF MoveRelative = new PointF(float.Parse(MoveRelativeS[0], CultureInfo.InvariantCulture), float.Parse(MoveRelativeS[1], CultureInfo.InvariantCulture)); float Delay = float.Parse(document.ChildNodes[1].ChildNodes[i].Attributes[4].Value, CultureInfo.InvariantCulture); Elems.Add(new MacroElem() { Delay = Delay, MoveRelative = MoveRelative, MoveToPoint = MoveToPoint, ToolMove = toolmove, Type = type }); } } catch (Exception e) { throw new FileLoadException("Unknown error", e); } }
private void UpDateMacrosettings(int i) { var a = main.Elems[i]; if (a.GetMacro() == null) { int height = pictureBox1.Height; int width = pictureBox1.Width; Bitmap bmp = new Bitmap(width, height); using (Graphics gr = Graphics.FromImage(bmp)) { gr.FillRectangle(new SolidBrush(Color.FromArgb(224, 224, 224)), new RectangleF(0, 0, width, height)); var font = new Font("Cambria", 15f, FontStyle.Regular); var size = gr.MeasureString(TB.L.Phrase["Form_MacroPack.NothingToPreview"], font); gr.DrawString(TB.L.Phrase["Form_MacroPack.NothingToPreview"], font, Brushes.Red, new Point((int)(width / 2 - size.Width / 2), (int)(height / 2 - size.Height / 2))); } Image img = pictureBox1.Image; pictureBox1.Image = bmp; img?.Dispose(); return; } label_macro_name.Text = TB.L.Phrase["Form_MacroPack.Name"] + ExOperators.CutString(a.GetMacro().Name, 15); label_macro_path.Text = TB.L.Phrase["Form_MacroPack.Path"] + new FileInfo(a.Path).Directory.Name + "\\" + new FileInfo(a.Path).Name; label_macro_discr.Text = TB.L.Phrase["Form_MacroPack.Discr"] + ExOperators.CutString(a.GetMacro().Discr, 15); textBox_macro_caption.Text = a.Options.Caption; comboBox_macro_keybind.SelectedItem = a.Options.KeyBind.ToString(); comboBox_macro_charbind.Text = a.Options.CharBind.ToString(); label_macro_elemcount.Text = TB.L.Phrase["Form_MacroPack.Elements"] + a.GetMacro().Elems.Count; checkBox_isHidden.Checked = a.Options.Hidden; RenderGR(i); Render(); }
private void comboBox_macro_keybind_SelectedIndexChanged(object sender, EventArgs e) { if (listBox_macroses.SelectedIndex != -1) { var a = main.Elems[listBox_macroses.SelectedIndex]; main.Elems[listBox_macroses.SelectedIndex] = new MacroPackElem() { Options = new MacroPackElemOption { Caption = a.Options.Caption, CharBind = a.Options.CharBind, KeyBind = ExOperators.GetEnum <Key>(comboBox_macro_keybind.Text) }, Path = a.Path }; main.Elems[listBox_macroses.SelectedIndex].SetMacro(a.GetMacro()); } }