Example #1
0
 private void BrowseFirmwareButton_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog {
         Filter = "WDS hex files (*.whf)|*.whf|Intel hex files (*.hex)|*.hex",
         RestoreDirectory = true
     };
     int index = -1;
     if (this.lstSelectFirmware.SelectedItems.Count > 0)
     {
         index = this.lstSelectFirmware.SelectedItems[0].Index;
     }
     try
     {
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             FirmwareItem firmwareItem = IO_FD_Main.GetFirmwareItem(dialog.FileName);
             if (firmwareItem.type == null)
             {
                 CompatibleDeviceDescriptor item = new CompatibleDeviceDescriptor();
                 item.addDeviceType(this._adtRec.DeviceInfo.DeviceType.TypeID);
                 firmwareItem.supportedDeviceList.Add(item);
                 if ((this.lstSelectMcu.SelectedItems.Count > 0) && (this._adtRec.DeviceInfo.DeviceType.TypeID.ToString() != this.lstSelectMcu.SelectedItems[0].Text))
                 {
                     firmwareItem.supportedDeviceList[firmwareItem.supportedDeviceList.Count - 1].DeviceList[0].CompatibleComponentDescriptor.addDeviceType(this.lstSelectMcu.SelectedItems[0].Text);
                 }
                 firmwareItem.name = Path.GetFileNameWithoutExtension(dialog.FileName);
                 firmwareItem.date = DateTime.Now;
                 firmwareItem.version = new FirmwareVersion("0.1r");
                 firmwareItem.type = new FirmwareType("Unknown");
             }
             DeviceDescriptor deviceInfo = this._adtRec.DeviceInfo;
             if (!firmwareItem.supportedDeviceList[firmwareItem.supportedDeviceList.Count - 1].IsCompatible(deviceInfo, HwVersion.Upper, FwVersion.Lower, true))
             {
                 throw new Exception("The selected firmware does not compatible with the board attached.");
             }
             ArrayList list = new ArrayList(this._firmwareItems);
             list.Add(firmwareItem);
             this._firmwareItems = (FirmwareItem[]) list.ToArray(typeof(FirmwareItem));
             this.lstSelectFirmware.Items.Add(firmwareItem.getFWDownloadListViewItem());
             this.lstSelectFirmware.Items[this.lstSelectFirmware.Items.Count - 1].Selected = true;
             this.DownloadButton.Enabled = true;
         }
     }
     catch (Exception exception)
     {
         if ((index < this.lstSelectFirmware.Items.Count) && (index >= 0))
         {
             this.lstSelectFirmware.Items[index].Selected = true;
         }
         this.firmwareUpdateCallback(0, true, "The file " + dialog.FileName + " is not a valid firmware. \n\r" + exception.Message, MessageBoxButtons.OK);
     }
 }
Example #2
0
 public void parseCompatibleDevices(List<CompatibleDeviceDescriptor> comaptibleDeviceList, XmlNode subNode)
 {
     foreach (XmlNode node in subNode.ChildNodes)
     {
         if ((node.NodeType != XmlNodeType.Comment) && (node.Attributes != null))
         {
             CompatibleDeviceDescriptor descriptor = new CompatibleDeviceDescriptor();
             descriptor.addDeviceType(node.Attributes[0].InnerText);
             foreach (XmlNode node2 in node.ChildNodes)
             {
                 string name = node2.Name;
                 if (name != null)
                 {
                     if (!(name == "DeviceVersion"))
                     {
                         if (name == "DeviceComponents")
                         {
                             goto Label_0221;
                         }
                         if (name == "Licenses")
                         {
                             goto Label_029E;
                         }
                     }
                     else if (node2.Attributes != null)
                     {
                         descriptor.addDeviceVersion(node.Attributes[0].InnerText, node2.Attributes[0].InnerText);
                         foreach (XmlNode node3 in node2.ChildNodes)
                         {
                             string str2;
                             if ((((str2 = node3.Name) != null) && (str2 == "FirmwareType")) && (node3.Attributes != null))
                             {
                                 descriptor.addFirmwareType(node.Attributes[0].InnerText, node2.Attributes[0].InnerText, node3.Attributes[0].InnerText);
                                 foreach (XmlNode node4 in node3.ChildNodes)
                                 {
                                     if (node4.Attributes != null)
                                     {
                                         descriptor.addFirmwareVersion(node.Attributes[0].InnerText, node2.Attributes[0].InnerText, node3.Attributes[0].InnerText, node4.Attributes[0].InnerText);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 continue;
             Label_0221:
                 foreach (XmlNode node5 in node2.ChildNodes)
                 {
                     if ((node5.NodeType != XmlNodeType.Comment) && (node5.Name == "DeviceType"))
                     {
                         this.parseCompatibleDevices(descriptor.getCompatibleComponentDescriptor(node.Attributes[0].InnerText), node2);
                         break;
                     }
                 }
                 continue;
             Label_029E:
                 foreach (XmlNode node6 in node2.ChildNodes)
                 {
                     if ((node6.NodeType != XmlNodeType.Comment) && (node6.Name == "Name"))
                     {
                         LicenseItem license = new LicenseItem {
                             Name = node6.InnerText
                         };
                         descriptor.addLicense(node.Attributes[0].InnerText, license);
                     }
                 }
             }
             comaptibleDeviceList.Add(descriptor);
         }
     }
 }