// Board settings file: Text file, starting with 8 characters board name and \n\r, // then the setings in Json format static public bool Save(TinyG TinyGSettings, qQuintic qQuinticSettings, string FileName) { try { if (MainForm.Cnc.Controlboard == CNC.ControlBoardType.TinyG) { MainForm.DisplayText("Writing TinyG settings file: " + FileName); File.WriteAllText(FileName, "TinyG \n\r" + JsonConvert.SerializeObject(TinyGSettings, Formatting.Indented)); } else if (MainForm.Cnc.Controlboard == CNC.ControlBoardType.qQuintic) { MainForm.DisplayText("Writing qQuintic settings file: " + FileName); File.WriteAllText(FileName, "qQuintic\n\r" + JsonConvert.SerializeObject(qQuinticSettings, Formatting.Indented)); } else { MainForm.DisplayText("Skipping writing board settings file; board type unknown"); } return(true); } catch (System.Exception excep) { MainForm.DisplayText("Saving settings to " + FileName + " failed:\n" + excep.Message, KnownColor.DarkRed); return(false); } }
static public bool Load(ref TinyG TinyGSettings, ref qQuintic qQuinticSettings, string FileName) { string content = ""; try { string name = FileName; if (File.Exists(name)) { MainForm.DisplayText("Reading " + name); content = File.ReadAllText(name); } else { MainForm.DisplayText("Settings file " + name + " not found, using default values."); return(false); } if (content.Length < 10) { MainForm.ShowMessageBox( "Problem loading application settings: File is too short.\nUsing built in defaults.", "Settings not loaded", MessageBoxButtons.OK); return(false); } string boardType = content.Substring(0, 10); content = content.Remove(0, 10); if (boardType == "TinyG \n\r") { TinyGSettings = JsonConvert.DeserializeObject <TinyG>(content); } else if (boardType == "qQuintic\n\r") { qQuinticSettings = JsonConvert.DeserializeObject <qQuintic>(content ); } else { MainForm.ShowMessageBox( "Unknown baord type " + boardType + "\nUsing built in defaults.", "Settings not loaded", MessageBoxButtons.OK); return(false); } return(true); } catch (System.Exception excep) { MainForm.ShowMessageBox( "Problem loading application settings:\n" + excep.Message + "\nUsing built in defaults.", "Settings not loaded", MessageBoxButtons.OK); return(false); } }