Esempio n. 1
0
        private void btnBurn_Click(object sender, EventArgs e)
        {
            if (ProjectBuilder.CheckForWinAVR())
            {
                owner.BurnerPanel.FormToProj();

                System.Diagnostics.Process p = new System.Diagnostics.Process();
                ProjectBuilder.SetEnviroVarsForProc(p.StartInfo);
                p.StartInfo.FileName  = "cmd";
                p.StartInfo.Arguments = "/k avrdude ";

                string overrides = "";

                BurnerPanel.GetPortOverride(ref overrides, owner.Project);

                p.StartInfo.Arguments += String.Format("-c {0} -p {1} {2} {3} {4}", owner.Project.BurnProgrammer, owner.Project.BurnPart, overrides, owner.Project.BurnOptions, GetArgString(fuseVal));

                try
                {
                    p.Start();
                }
                catch (Exception ex)
                {
                    ErrorReportWindow.Show(ex, "Error While Writing Fuse");
                }
            }
        }
Esempio n. 2
0
        public static ToolStripMenuItem GetMenuLinkRoot(string text)
        {
            ToolStripMenuItem item = new ToolStripMenuItem(text);

            item.Image = GraphicsResx.web;

            XmlDocument xDoc = new XmlDocument();

            if (File.Exists(SettingsManagement.AppDataPath + "helplinks.xml") == false)
            {
                try
                {
                    File.WriteAllText(SettingsManagement.AppDataPath + "helplinks.xml", Properties.Resources.helplinks);
                    xDoc.Load(SettingsManagement.AppDataPath + "helplinks.xml");
                }
                catch
                {
                    xDoc.LoadXml(Properties.Resources.helplinks);
                }
            }
            else
            {
                try
                {
                    xDoc.Load(SettingsManagement.AppDataPath + "helplinks.xml");
                }
                catch (XmlException ex)
                {
                    MessageBox.Show("Error while reading helplinks.xml: " + ex.Message);
                    return(item);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while reading helplinks.xml: " + ex.Message);
                    return(item);
                }
            }

            try
            {
                XmlElement xDocEle = xDoc.DocumentElement;

                foreach (XmlElement xEle in xDocEle.ChildNodes)
                {
                    MenuWebLink link = new MenuWebLink(xEle.GetAttribute("Text"), xEle.GetAttribute("URL"));
                    link.Add(xEle);

                    item.DropDownItems.Add(link.MenuItem);
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error while creating help links");
            }

            return(item);
        }
        public static ToolStripMenuItem GetExternalToolsRoot(IDEWindow wind)
        {
            ToolStripMenuItem root = new ToolStripMenuItem("External Tools");

            root.Image = GraphicsResx.tool_icon_png;

            XmlDocument xDoc = new XmlDocument();

            if (File.Exists(SettingsManagement.AppDataPath + "ext_tools.xml") == false)
            {
                try
                {
                    File.WriteAllText(SettingsManagement.AppDataPath + "ext_tools.xml", Properties.Resources.ext_tools);
                    xDoc.Load(SettingsManagement.AppDataPath + "ext_tools.xml");
                }
                catch
                {
                    xDoc.LoadXml(Properties.Resources.ext_tools);
                }
            }
            else
            {
                try
                {
                    xDoc.Load(SettingsManagement.AppDataPath + "ext_tools.xml");
                }
                catch (XmlException ex)
                {
                    MessageBox.Show("Error while reading ext_tools.xml: " + ex.Message);
                    return(root);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while reading ext_tools.xml: " + ex.Message);
                    return(root);
                }
            }

            try
            {
                XmlElement xDocEle = xDoc.DocumentElement;

                foreach (XmlElement xEle in xDocEle.GetElementsByTagName("Tool"))
                {
                    ExternalTool link = new ExternalTool(xEle.GetAttribute("text"), xEle.GetAttribute("cmd"), xEle.GetAttribute("args"), xEle.GetAttribute("dir"), wind);
                    link.mbtn.Image = GraphicsResx.tool_icon_png;
                    toolList.Add(link);
                    root.DropDownItems.Add(link.mbtn);
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error while creating external tool buttons");
            }

            return(root);
        }
Esempio n. 4
0
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Fuse Calculator");
     }
 }
Esempio n. 5
0
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Configuration Window");
     }
 }
Esempio n. 6
0
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Editor Panel for '" + this.FileName + "'");
     }
 }
Esempio n. 7
0
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Hardware Explorer");
     }
 }
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Debugger Memory View");
     }
 }
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Disassembly Viewer");
     }
 }
Esempio n. 10
0
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error from CopyCatWizard");
     }
 }
Esempio n. 11
0
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override void WndProc(ref Message m)
 {
     try
     {
         base.WndProc(ref m);
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error In Search Panel");
     }
 }
Esempio n. 12
0
        private static void NotifyOfUserAction()
        {
            bool   showMsg = false;
            string msg     = "It appears that you have recently updated AVR Project IDE. There may be some files that may have been updated but you already have a different version." + Environment.NewLine;

            msg += "You may have customized these files yourself, in this case you can choose not to update these files." + Environment.NewLine;
            msg += "If you wish to update these files, you can delete them and they will be updated when you start AVR Project IDE again." + Environment.NewLine;
            msg += "You can also save a backup of your own version, and then delete the originals to receive the updated version, and then merge the changes manually." + Environment.NewLine;
            msg += "These are the files:" + Environment.NewLine;

            try
            {
                if (File.ReadAllText(SettingsManagement.AppDataPath + "templates.xml") != Properties.Resources.templates)
                {
                    msg    += "Project configuration templates file at '" + SettingsManagement.AppDataPath + "templates.xml" + "'" + Environment.NewLine;
                    showMsg = true;
                }

                if (File.Exists(SettingsManagement.AppDataPath + "chip_xml" + Path.DirectorySeparatorChar + "interruptvectors.xml"))
                {
                    if (File.ReadAllText(SettingsManagement.AppDataPath + "chip_xml" + Path.DirectorySeparatorChar + "interruptvectors.xml") != Properties.Resources.interruptvectors)
                    {
                        msg    += "Interrupt vector list file at '" + SettingsManagement.AppDataPath + "chip_xml" + Path.DirectorySeparatorChar + "interruptvectors.xml" + "'" + Environment.NewLine;
                        showMsg = true;
                    }
                }

                if (File.ReadAllText(SettingsManagement.AppDataPath + "helplinks.xml") != Properties.Resources.helplinks)
                {
                    msg    += "Help links collection file at '" + SettingsManagement.AppDataPath + "helplinks.xml" + "'" + Environment.NewLine;
                    showMsg = true;
                }

                if (SettingsManagement.AutocompleteEnable)
                {
                    if (File.ReadAllText(SettingsManagement.AppDataPath + "autocomplete.xml") != Properties.Resources.autocomplete)
                    {
                        msg    += "Autocomplete keyword collection file at '" + SettingsManagement.AppDataPath + "autocomplete.xml" + "'" + Environment.NewLine;
                        showMsg = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error while scanning for updated files");
            }

            msg += "Also various other files may have changed, such as the files under '" + SettingsManagement.AppDataPath + "chip_xml" + Path.DirectorySeparatorChar + "' and '" + SettingsManagement.AppDataPath + "file_templates" + Path.DirectorySeparatorChar + "'" + Environment.NewLine;

            if (showMsg)
            {
                MessageBox.Show(msg);
            }
        }
Esempio n. 13
0
 private void TryRun()
 {
     try
     {
         avrdude.Start();
     }
     catch (Exception ex)
     {
         ErrorReportWindow.Show(ex, "Error using AVRDUDE GUI");
     }
 }
Esempio n. 14
0
        static public bool Load()
        {
            string templatePath = SettingsManagement.AppDataPath + "templates.xml";

            if (File.Exists(templatePath) == false)
            {
                try
                {
                    File.WriteAllText(templatePath, Properties.Resources.templates);
                }
                catch (Exception ex)
                {
                    ErrorReportWindow.Show(ex, "Error while creating templates");
                    return(false);
                }
            }

            try
            {
                tempDoc = new XmlDocument();
                tempDoc.Load(templatePath);

                XmlElement docEle = tempDoc.DocumentElement;

                templates.Clear();
                XmlNodeList tempList = docEle.GetElementsByTagName("template");
                foreach (XmlElement temp in tempList)
                {
                    string name = temp.GetAttribute("name");
                    if (string.IsNullOrEmpty(name) == false)
                    {
                        templates.Add(name, temp);
                    }
                }
            }
            catch (XmlException ex)
            {
                MessageBox.Show("XML Error in Template File: " + ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error while loading templates");

                return(false);
            }

            return(true);
        }
Esempio n. 15
0
        public UsbPanel()
        {
            InitializeComponent();

            this.Icon = Icon.FromHandle(GraphicsResx.usbpanelicon.GetHicon());

            try
            {
                UsbDevice.UsbErrorEvent += OnUsbError;

                devNotifier = DeviceNotifier.OpenDeviceNotifier();
                devNotifier.OnDeviceNotify += onDevNotify;

                FillDeviceInfo();
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Initializing USB Panel");
            }
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            splash = new SplashScreen();
            splash.Show();

            try
            {
                SettingsManagement.Load();
                FileTemplate.Unpack();
                ProjTemplate.Load();

                if (SettingsManagement.AutocompleteEnable)
                {
                    KeywordImageGen.GenerateKeywordImages();
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Initialization Error");
            }

            try
            {
                UpdateMech.CheckForUpdates();
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Checking Updates");
            }

            try
            {
                AVRProject newProject = new AVRProject();

                if (args.Length > 0)
                {
                    string fname = args[0];

                    if (newProject.Open(fname) == true)
                    {
                        SettingsManagement.AddFileAsMostRecent(fname);
                    }
                    else
                    {
                        MessageBox.Show("Error, failed to open file");
                    }
                }
                else if (SettingsManagement.OpenLastProject)
                {
                    if (string.IsNullOrEmpty(SettingsManagement.LastProjectPath) == false)
                    {
                        if (newProject.Open(SettingsManagement.LastProjectPath) == true)
                        {
                            SettingsManagement.AddFileAsMostRecent(SettingsManagement.LastProjectPath);
                        }
                        else
                        {
                            MessageBox.Show("Error, failed to open file");
                        }
                    }
                }

                KeywordScanner.Initialize();

                Application.Run(new IDEWindow(newProject));

                if (newProject.IsReady)
                {
                    if (SettingsManagement.SaveRecentList() == false)
                    {
                        MessageBox.Show("Error, Could Not Save Recent File List");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Main IDE Error");
            }

            try
            {
                if (UpdateMech.HasFinishedChecking)
                {
                    if (UpdateMech.UpdateAvailable)
                    {
                        try
                        {
                            if (MessageBox.Show("An Updated Version of AVR Project IDE is Available (" + SettingsManagement.Version + " to " + UpdateMech.NewBuildID + "). Would you like to download it?", "Update Available", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                System.Diagnostics.Process.Start(Properties.Resources.WebsiteURL);
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorReportWindow.Show(ex, "Updater Error");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Checking Updates");
            }

            try
            {
                if (SettingsManagement.LastRunVersion != SettingsManagement.Version)
                {
                    NotifyOfUserAction();
                }

                SettingsManagement.LastRunVersion = SettingsManagement.Version;
            }
            catch { }
        }
Esempio n. 17
0
        public SaveResult AddFile(out ProjectFile file, string filePath)
        {
            string fn  = Path.GetFileName(filePath);
            string ext = Path.GetExtension(fn).ToLowerInvariant();

            if (project.FileList.TryGetValue(fn.ToLowerInvariant(), out file))
            {
                if (file.FileAbsPath != filePath && file.Exists)
                {
                    // name conflict, do not allow
                    MessageBox.Show("Error, Cannot Add File " + file.FileName + " Due To Name Conflict");
                    return(SaveResult.Failed);
                }
                else
                {
                    // added file already in list, maybe it was missing, so refresh the list to update icons
                    PopulateList();
                    return(SaveResult.Cancelled);
                }
            }
            else
            {
                if (ext == ".c" || ext == ".cpp" || ext == ".cxx" || ext == ".s" || ext == ".h" || ext == ".hpp")
                {
                    // check for space if it's a source or header file, we don't care about the other files
                    if (fn.Contains(" "))
                    {
                        MessageBox.Show("Error, File Name May Not Contain Spaces");
                        return(SaveResult.Failed);
                    }
                }

                file = new ProjectFile(filePath, this.project);

                if (file.Exists == false)
                {
                    try
                    {
                        StreamWriter newFile = new StreamWriter(file.FileAbsPath);

                        if (file.FileExt == "h" || file.FileExt == "hpp")
                        {
                            newFile.WriteLine(FileTemplate.CreateFile(file.FileName, project.FileNameNoExt, "defaultheader.txt"));
                        }
                        else if (file.FileExt == "c" || file.FileExt == "cpp")
                        {
                            newFile.WriteLine(FileTemplate.CreateFile(file.FileName, project.FileNameNoExt, "defaultcode.txt"));
                        }
                        else
                        {
                            newFile.WriteLine(FileTemplate.CreateFile(file.FileName, project.FileNameNoExt, "default_" + file.FileExt + ".txt"));
                        }

                        newFile.Close();
                    }
                    catch (Exception ex)
                    {
                        ErrorReportWindow.Show(ex, "Error Creating New File " + file.FileName);
                    }
                }

                project.FileList.Add(fn.ToLowerInvariant(), file);

                if (project.Save() == SaveResult.Failed)
                {
                    MessageBox.Show("Error saving project");
                }

                PopulateList();
                return(SaveResult.Successful);
            }
        }
Esempio n. 18
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string iniFilename = txtInitialFilename.Text.Trim();
            bool   hasIniFile  = !string.IsNullOrEmpty(iniFilename);

            hasIniFile = false;
            string projFilename = txtProjName.Text.Trim();

            if (string.IsNullOrEmpty(projFilename))
            {
                MessageBox.Show("The project name can't be blank");
                return;
            }

            char[] forbidChars = Path.GetInvalidFileNameChars();
            foreach (char c in forbidChars)
            {
                if (hasIniFile && iniFilename.Contains(c))
                {
                    MessageBox.Show("Illegal Character in Initial File Name");
                    return;
                }

                if (projFilename.Contains(c))
                {
                    MessageBox.Show("Illegal Character in Project File Name");
                    return;
                }
            }

            if (hasIniFile)
            {
                if (iniFilename.Contains('/') || iniFilename.Contains('\\') || iniFilename.Contains(Path.DirectorySeparatorChar) || iniFilename.Contains(Path.AltDirectorySeparatorChar))
                {
                    MessageBox.Show("Illegal Character in Initial File Name");
                    return;
                }

                if (iniFilename.Contains('.') || iniFilename.Contains(' ') || iniFilename.Contains('\t'))
                {
                    MessageBox.Show("No Spaces or Dots are Allowed in Initial File Name");
                    return;
                }
            }

            if (projFilename.Contains('/') || projFilename.Contains('\\') || projFilename.Contains(Path.DirectorySeparatorChar) || projFilename.Contains(Path.AltDirectorySeparatorChar))
            {
                MessageBox.Show("Illegal Character in Project File Name");
                return;
            }

            if (projFilename.Contains('.'))
            {
                MessageBox.Show("No Dots are Allowed in Project File Name");
                return;
            }

            string folderPath = Program.CleanFilePath(txtFolderPath.Text);

            if (Program.MakeSurePathExists(folderPath) == false)
            //if (Directory.Exists(folderPath))
            {
                MessageBox.Show("Error Creating Folder");
                //MessageBox.Show("Error: Folder Invalid");
                return;
            }

            string projFilePath = folderPath + Path.DirectorySeparatorChar + projFilename + ".avrproj";

            project.FilePath = projFilePath;

            string ext = "c";

            if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("C++"))
            {
                ext = "cpp";
            }
            else if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("C"))
            {
                ext = "c";
            }
            else if (((string)dropFileType.Items[dropFileType.SelectedIndex]).Contains("Arduino"))
            {
                ext = "pde";
            }

            string iniFilePath = folderPath + Path.DirectorySeparatorChar + iniFilename + "." + ext;

            if (File.Exists(projFilePath))
            {
                if (MessageBox.Show("Project File Already Exists at the Location, Overwrite it?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            bool merge = false;

            if (hasIniFile && File.Exists(iniFilePath))
            {
                if (MessageBox.Show("Initial File Already Exists at the Location, Merge it with your project?", "Merge File?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    merge = true;
                }
                else if (MessageBox.Show("Maybe you'd rather overwrite it with a blank file?", "Overwrite File?", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            if (hasIniFile)
            {
                if (merge == false)
                {
                    try
                    {
                        StreamWriter writer = new StreamWriter(iniFilePath);
                        if (ext == "pde")
                        {
                            writer.Write(FileTemplate.CreateFile(iniFilename + "." + ext, projFilename, "initialpde.txt"));
                        }
                        else
                        {
                            writer.Write(FileTemplate.CreateFile(iniFilename + "." + ext, projFilename, "initialmain.txt"));
                        }
                        writer.WriteLine();
                        writer.Close();
                    }
                    catch (Exception ex)
                    {
                        ErrorReportWindow.Show(ex, "Error while creating initial file");
                    }
                }

                ProjectFile newFile = new ProjectFile(iniFilePath, project);
                newFile.IsOpen = true;
                project.FileList.Add(newFile.FileName.ToLowerInvariant(), newFile);
            }

            ProjTemplate.ApplyTemplate((string)dropTemplates.Items[dropTemplates.SelectedIndex], project);

            project.FilePath = projFilePath;

            FileAddWizard faw = new FileAddWizard(project);

            faw.ShowDialog();

            if (project.Save(projFilePath) == false)
            {
                MessageBox.Show("Error While Saving Project");
            }
            else
            {
                if (project.Open(projFilePath) == false)
                {
                    MessageBox.Show("Error While Opening Project");
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 19
0
        private bool WriteToFile(string path, bool backup)
        {
            // obviously the filesystem watcher will know if you rewrite the file, so disable it
            bool wasWatching = WatchingForChange;

            WatchingForChange = false;

            path = Program.CleanFilePath(path);

            bool success = true;

            if (Program.MakeSurePathExists(path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar))) == false)
            {
                return(false);
            }

            string content = scint.Text.TrimEnd();

            try
            {
                KeywordScanner.FeedFileContent(file, content);
                KeywordScanner.DoMoreWork();
            }
            catch { }

            if (backup)
            {
                for (int i = 0; i <= SAVERETRY; i++)
                {
                    try
                    {
                        System.IO.File.WriteAllText(path + ".bk", content);
                        break;
                    }
                    catch (Exception ex)
                    {
                        if (i == SAVERETRY)
                        {
                            success = false;
                            //ErrorReportWindow.Show(ex, "Save Error");
                            //
                            break;
                        }
                        System.Threading.Thread.Sleep(SAVERETRYDELAY);
                    }
                }
            }

            for (int i = 0; i <= SAVERETRY; i++)
            {
                try
                {
                    System.IO.File.WriteAllText(path, content);
                    break;
                }
                catch (Exception ex)
                {
                    if (i == SAVERETRY)
                    {
                        success = false;
                        ErrorReportWindow.Show(ex, "Save Error");

                        break;
                    }
                    System.Threading.Thread.Sleep(SAVERETRYDELAY);
                }
            }

            if (backup && success)
            {
                try
                {
                    System.IO.File.Delete(path + ".bk");
                }
                catch { }
            }

            WatchingForChange = wasWatching;

            return(success);
        }
Esempio n. 20
0
        private void FuseCalculator_Load(object sender, EventArgs e)
        {
            // avoid having two fuse calculators open since this tool can be
            // opened from two places
            if (isOpen)
            {
                this.Close();
                return;
            }

            isOpen = true;

            burnerPanel.ProjToForm();

            XmlDocument xDoc = new XmlDocument();

            try
            {
                string chipName = Program.ProperChipName(project.Device);
                string xmlFilePathA;
                string xmlFilePathB;
                int    cnt = chipName.Length;
                do
                {
                    xmlFilePathA = SettingsManagement.AppInstallPath + "chip_xml" + Path.DirectorySeparatorChar + chipName.Substring(0, cnt) + ".xml";
                    xmlFilePathB = SettingsManagement.AppDataPath + "chip_xml" + Path.DirectorySeparatorChar + chipName.Substring(0, cnt) + ".xml";

                    if (cnt == 0)
                    {
                        throw new Exception("chip data xml (" + chipName + ".xml) was not found in " + SettingsManagement.AppInstallPath + "chip_xml or " + SettingsManagement.AppDataPath + "chip_xml");
                    }

                    if (File.Exists(xmlFilePathB) == false)
                    {
                        if (File.Exists(xmlFilePathA))
                        {
                            File.Copy(xmlFilePathA, xmlFilePathB, true);
                            break;
                        }
                        else
                        {
                            cnt--;
                        }
                    }
                    else
                    {
                        break;
                    }
                }while (true);

                xDoc.Load(xmlFilePathB);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Could not find matching XML file for your device");
                this.Close();
                return;
            }
            catch (XmlException ex)
            {
                MessageBox.Show("Error in Chip Description XML File: " + ex.Message);
                this.Close();
                return;
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Fuse Calculator Error");
                this.Close();
                return;
            }

            XmlElement docEle = xDoc.DocumentElement;

            foreach (XmlElement xFuseContainer in docEle.GetElementsByTagName("FUSE"))
            {
                foreach (XmlElement xList in xFuseContainer.GetElementsByTagName("LIST"))
                {
                    string   t        = xList.InnerText.Trim().Trim(new char[] { '[', ']', }).Trim();
                    string[] fuseList = t.Split(':');
                    foreach (string fuse in fuseList)
                    {
                        if (string.IsNullOrEmpty(fuse) == false)
                        {
                            foreach (XmlElement xFuse in xFuseContainer.GetElementsByTagName(fuse))
                            {
                                FusePanel fp = new FusePanel(xFuse, project.BurnFuseBox, this);
                                TabPage   tp = new TabPage(fuse);
                                tp.Controls.Add(fp);
                                fp.Dock = DockStyle.Fill;
                                tabControl1.TabPages.Add(tp);
                            }
                        }
                    }

                    break;
                }

                break;
            }

            foreach (XmlElement xLockBitContainer in docEle.GetElementsByTagName("LOCKBIT"))
            {
                FusePanel fp = new FusePanel(xLockBitContainer, project.BurnFuseBox, this);
                TabPage   tp = new TabPage("Lock Bits");
                tp.Controls.Add(fp);
                fp.Dock = DockStyle.Fill;
                tabControl1.TabPages.Add(tp);

                break;
            }
        }
Esempio n. 21
0
        private int ReadFuse()
        {
            if (ProjectBuilder.CheckForWinAVR())
            {
                owner.BurnerPanel.FormToProj();

                System.Diagnostics.Process p = new System.Diagnostics.Process();
                ProjectBuilder.SetEnviroVarsForProc(p.StartInfo);
                p.StartInfo.FileName  = "avrdude";
                p.StartInfo.Arguments = "";
                //p.StartInfo.FileName = "cmd";
                //p.StartInfo.Arguments = "/k avrdude";

                string overrides = "";

                BurnerPanel.GetPortOverride(ref overrides, owner.Project);

                string avrdudeFuseStr = GetAVRDUDEFuseStringFromType(typeOfFuse);

                string action = String.Format("-U {0}:r:\"{1}\":h", avrdudeFuseStr, TempFuseFilePath);

                p.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.WorkingDirectory       = SettingsManagement.AppDataPath;
                p.StartInfo.Arguments += String.Format(" -c {0} -p {1} -n {2} {3} {4}", owner.Project.BurnProgrammer, owner.Project.BurnPart, overrides, owner.Project.BurnOptions, action);

                try
                {
                    File.Delete(TempFuseFilePath);
                }
                catch { }

                try
                {
                    p.Start();
                    p.WaitForExit(5000);

                    System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

                    while (true)
                    {
                        if (File.Exists(TempFuseFilePath))
                        {
                            break;
                        }

                        if (sw.ElapsedMilliseconds > 5000)
                        {
                            break;
                        }
                    }

                    if (File.Exists(TempFuseFilePath) == false)
                    {
                        MessageBox.Show("Failed to Read Fuse, temporary file not found at '" + TempFuseFilePath + "'. Here is the AVRDUDE output:" + Environment.NewLine + Environment.NewLine + p.StandardError.ReadToEnd() + Environment.NewLine + p.StandardOutput.ReadToEnd());
                        return(-1);
                    }
                    else
                    {
                        string fuseStr = File.ReadAllText(TempFuseFilePath);
                        try
                        {
                            File.Delete(TempFuseFilePath);
                        }
                        catch { }

                        if (string.IsNullOrEmpty(fuseStr))
                        {
                            MessageBox.Show("Temporary Fuse File is Empty at " + TempFuseFilePath);
                            return(-1);
                        }

                        fuseStr = fuseStr.Trim();
                        if (string.IsNullOrEmpty(fuseStr))
                        {
                            MessageBox.Show("Temporary Fuse File is Empty at " + TempFuseFilePath);
                            return(-1);
                        }

                        return(Convert.ToInt32(fuseStr, 16));
                    }
                }
                catch (Exception ex)
                {
                    ErrorReportWindow.Show(ex, "Error While Reading Fuse");
                }
            }

            return(-1);
        }