private void copyTemplate(string source) { try { Directory.CreateDirectory(Path.GetDirectoryName(fileLocation)); File.Copy(source, fileLocation); } catch (Exception ex) { MsgBox.error("Failed to copy " + name + " template to AppData", ex); } }
private void copyTemplate(string source) { try { Directory.CreateDirectory(Path.GetDirectoryName(fileLocation)); File.Copy(source, fileLocation); } catch (Exception ex) { MsgBox.error("_XMLCOPYERROR", name, ex.Message); } }
private bool launch(string args, OutputTo outputTo) { Process tmp = new Process(); tmp.StartInfo.FileName = binary; tmp.StartInfo.Arguments = args; tmp.StartInfo.CreateNoWindow = true; tmp.StartInfo.UseShellExecute = false; tmp.StartInfo.RedirectStandardOutput = true; tmp.StartInfo.RedirectStandardError = true; tmp.EnableRaisingEvents = true; if (outputTo == OutputTo.Log) { tmp.OutputDataReceived += new DataReceivedEventHandler(outputLogHandler); tmp.ErrorDataReceived += new DataReceivedEventHandler(errorLogHandler); } tmp.Exited += new EventHandler(p_Exited); try { tmp.Start(); } catch (Exception ex) { MsgBox.error("Error starting process", ex); return(false); } if (OnProcessStart != null) { OnProcessStart(this, EventArgs.Empty); } enableConsoleUpdate = (outputTo == OutputTo.Console); p = tmp; if (outputTo == OutputTo.Log) { processOutputStreamOpen = true; processErrorStreamOpen = true; p.BeginOutputReadLine(); p.BeginErrorReadLine(); } else { processOutputStreamOpen = false; processErrorStreamOpen = false; } return(true); }
protected void load(string binaryName, string directory, bool enableConsoleWrite = true) { binary = searchForBinary(binaryName, directory); if (binary == null) { MsgBox.error(binaryName + " is missing!"); } else if (enableConsoleWrite) { Thread t = new Thread(new ThreadStart(tConsoleUpdate)); t.IsBackground = true; t.Start(); } }
public void load() { try { string location = AssemblyData.directory + "/Languages/"; findLanguages(location); // Load the selected language xml readThroughXML(location + Config.Prop.language + ".xml", getTranslation, null); } catch (Exception ex) { MsgBox.error("Error loading languages:{0}{1}", Environment.NewLine, ex.Message); } }
protected void read() { data = default(T); TextReader tr = null; try { tr = new StreamReader(fileLocation); data = (T) new XmlSerializer(typeof(T)).Deserialize(tr); } catch (Exception ex) { MsgBox.error("An error occurred trying to load " + name, ex); } if (tr != null) { tr.Close(); } }
protected void read() { data = default(T); TextReader tr = null; try { tr = new StreamReader(fileLocation); data = (T) new XmlSerializer(typeof(T)).Deserialize(tr); } catch (Exception ex) { // No translation here since we might have a read error while loading config.xml or the translation file itself MsgBox.error("An error occurred trying to load {0}:{1}{2}", name, Environment.NewLine, ex.Message); } if (tr != null) { tr.Close(); } }
protected void write() { TextWriter tw = null; // TODO: move these try-catches somewhere outside this class? try { // Make sure directory exists Directory.CreateDirectory(Path.GetDirectoryName(fileLocation)); tw = new StreamWriter(fileLocation, false); new XmlSerializer(data.GetType()).Serialize(tw, data); } catch (Exception ex) { MsgBox.error("_XMLWRITEERROR", name, ex.Message); } if (tw != null) { tw.Close(); } }
private void load() { string signature = null; string high = null; string low = null; string ext = null; string lb = null; TextReader tr = null; try { tr = new StreamReader(fileLocation); using (XmlReader reader = XmlReader.Create(tr)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; if (name == "mcu") { signature = reader.GetAttribute("signature"); } reader.Read(); switch (name) { case "high": high = reader.ReadContentAsString(); break; case "low": low = reader.ReadContentAsString(); break; case "ext": ext = reader.ReadContentAsString(); break; case "lock": lb = reader.ReadContentAsString(); break; default: break; } } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "mcu" && signature != null) { if (lb != null) { lockbits.Add(signature, lb); } if (low != null) { fusebitslo.Add(signature, low); } if (high != null) { fusebitshi.Add(signature, high); } if (ext != null) { fusebitsext.Add(signature, ext); } signature = null; high = null; low = null; ext = null; lb = null; } } } } } catch (Exception ex) { MsgBox.error("An error occurred trying to load fuses", ex); } if (tr != null) { tr.Close(); } }
// Basic parsing of avrdude.conf to get programmers & MCUs private void LoadConfig(string confLoc) { string conf_loc = null; if (!String.IsNullOrEmpty(confLoc)) { conf_loc = Path.Combine(confLoc, FILE_AVRDUDECONF); } else { // If on Unix check /etc/ and /usr/local/etc/ first if (Environment.OSVersion.Platform == PlatformID.Unix) { conf_loc = "/etc/" + FILE_AVRDUDECONF; if (!File.Exists(conf_loc)) { conf_loc = "/usr/local/etc/" + FILE_AVRDUDECONF; if (!File.Exists(conf_loc)) { conf_loc = null; } } } if (conf_loc == null) { conf_loc = Path.Combine(AssemblyData.directory, FILE_AVRDUDECONF); if (!File.Exists(conf_loc)) { conf_loc = Path.Combine(Directory.GetCurrentDirectory(), FILE_AVRDUDECONF); } } } // Config file not found if (String.IsNullOrEmpty(conf_loc) || !File.Exists(conf_loc)) { throw new System.IO.FileNotFoundException(FILE_AVRDUDECONF + " is not found in the application folder."); return; } // Load config string[] lines; try { lines = File.ReadAllLines(conf_loc); } catch (Exception ex) { MsgBox.error("Error reading " + FILE_AVRDUDECONF, ex); return; } char[] trimChars = new char[3] { ' ', '"', ';' }; for (int i = 0; i < lines.Length - 3; i++) { string s = lines[i].Trim(); bool isProgrammer = s.StartsWith("programmer"); bool isPart = s.StartsWith("part"); if (!isPart && !isProgrammer) { continue; } // Get parent ID string partentId = null; if (isPart && s.Contains("parent")) { string[] parts = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 2) { partentId = parts[2].Trim(trimChars); } } i++; // next line // Does line have id key? int pos = lines[i].IndexOf('='); if (pos < 0 || lines[i].Substring(1, pos - 1).Trim() != "id") { continue; } // Get ID value string id = lines[i].Substring(pos + 1).Trim(trimChars); i++; // next line // Does line have desc key? pos = lines[i].IndexOf('='); if (pos < 0 || lines[i].Substring(1, pos - 1).Trim() != "desc") { continue; } // Get description value string desc = lines[i].Substring(pos + 1).Trim(trimChars); // If its a programmer then add to programmers and go back to the top if (isProgrammer) { _programmers.Add(new Programmer(id, desc)); continue; } // Otherwise its an MCU // Part is a common value thing or deprecated if (id.StartsWith(".") || desc.StartsWith("deprecated")) { continue; } // Here we get the MCU signature, flash and EEPROM sizes string signature = ""; int flash = -1; int eeprom = -1; ParseMemType memType = ParseMemType.None; // Loop through lines looking for "signature" and "memory" // Abort if "part" or "programmer" is found for ( ; i < lines.Length; i++) { s = lines[i].Trim(); // Too far if (s.StartsWith("part") || s.StartsWith("programmer")) { i--; break; } // Found memory section if (s.StartsWith("memory")) { pos = lines[i].IndexOf('"'); if (pos > -1) { // What type of memory is this? string mem = lines[i].Substring(pos - 1).Trim(trimChars).ToLower(); if (mem == "flash") { memType = ParseMemType.Flash; } else if (mem == "eeprom") { memType = ParseMemType.Eeprom; } } } else if (memType != ParseMemType.None) { // See if this line defines the memory size pos = lines[i].IndexOf('='); if (pos > -1 && lines[i].Substring(1, pos - 1).Trim() == "size") { // Get size value string memStr = lines[i].Substring(pos + 1).Trim(trimChars); // Parse to int int memTmp = 0; if (!int.TryParse(memStr, out memTmp)) { // Probably hex if (memStr.StartsWith("0x")) { memStr = memStr.Substring(2); // Remove 0x } int.TryParse(memStr, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out memTmp); } if (memType == ParseMemType.Flash) { flash = memTmp; } else if (memType == ParseMemType.Eeprom) { eeprom = memTmp; } memType = ParseMemType.None; } } // Does line have signature key? pos = lines[i].IndexOf('='); if (pos > -1 && lines[i].Substring(1, pos - 1).Trim() == "signature") { // Get signature value signature = lines[i].Substring(pos + 1).Trim(trimChars); // Remove 0x and spaces from signature (0xAA 0xAA 0xAA -> AAAAAA) signature = signature.Replace("0x", "").Replace(" ", ""); } } // Some formatting desc = desc.ToUpper().Replace("XMEGA", "xmega").Replace("MEGA", "mega").Replace("TINY", "tiny"); // Find parent MCU parent = null; if (partentId != null) { parent = _mcus.Find(m => m.name == partentId); } // Add to MCUs _mcus.Add(new MCU(id, desc, signature, flash, eeprom, parent)); } }